Skip to content

Commit

Permalink
Fix to issue #1313: update docs re ATString and whitespace.
Browse files Browse the repository at this point in the history
  • Loading branch information
sangwinc committed Nov 15, 2024
1 parent 1036623 commit 382fcab
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 69 deletions.
100 changes: 44 additions & 56 deletions doc/en/Authoring/Answer_Tests/Results/String.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,112 +9,100 @@ This page exposes the results of running answer tests on STACK test cases. This
<tr class="pass">
<td class="cell c0">String</td>
<td class="cell c1"><span style="color:green;"><i class="fa fa-check"></i></span></td>
<td class="cell c2"><pre>&quot;With spaces&quot;</pre></td>
<td class="cell c3"><pre>&quot;With spaces&quot;</pre></td>
<td class="cell c2"><pre>&quot;Hello&quot;</pre></td>
<td class="cell c3"><pre>&quot;hello&quot;</pre></td>
<td class="cell c4"></td>
<td class="cell c5">1</td>
<td class="cell c5">0</td>
<td class="cell c6"></td>
</tr>
<tr class="pass">
<td class="cell c0">String</td>
<td class="cell c1"><span style="color:green;"><i class="fa fa-check"></i></span></td>
<td class="cell c2"><pre>&quot;Without spaces&quot;</pre></td>
<td class="cell c3"><pre>&quot;Withoutspaces&quot;</pre></td>
<td class="cell c2"><pre>&quot;hello&quot;</pre></td>
<td class="cell c3"><pre>&quot;hello&quot;</pre></td>
<td class="cell c4"></td>
<td class="cell c5">0</td>
<td class="cell c5">1</td>
<td class="cell c6"></td>
</tr>
<tr class="pass">
<td class="cell c0">String</td>
<td class="cell c1"><span style="color:green;"><i class="fa fa-check"></i></span></td>
<td class="cell c2"><pre>Hello</pre></td>
<td class="cell c3"><pre>hello</pre></td>
<td class="cell c2"><pre>&quot;hello&quot;</pre></td>
<td class="cell c3"><pre>&quot;heloo&quot;</pre></td>
<td class="cell c4"></td>
<td class="cell c5">0</td>
<td class="cell c6"></td>
</tr>
<tr class="pass">
<td class="cell c0">String</td>
<td class="cell c1"><span style="color:green;"><i class="fa fa-check"></i></span></td>
<td class="cell c2"><pre>hello</pre></td>
<td class="cell c3"><pre>hello</pre></td>
<td class="cell c2"><pre>&quot;With spaces&quot;</pre></td>
<td class="cell c3"><pre>&quot;With spaces&quot;</pre></td>
<td class="cell c4"></td>
<td class="cell c5">1</td>
<td class="cell c6"></td>
</tr>
<tr class="pass">
<td class="cell c0">String</td>
<td class="cell c1"><span style="color:green;"><i class="fa fa-check"></i></span></td>
<td class="cell c2"><pre>hello</pre></td>
<td class="cell c3"><pre>heloo</pre></td>
<td class="cell c2"><pre>&quot;Without spaces&quot;</pre></td>
<td class="cell c3"><pre>&quot;Withoutspaces&quot;</pre></td>
<td class="cell c4"></td>
<td class="cell c5">0</td>
<td class="cell c6"></td>
</tr>
<tr class="notes">
<td class="cell c0"><td colspan="6">This test works on expressions as well as strings</td></td>
<td class="cell c0"><td colspan="6">Whitespace not trimmed off inside strings</td></td>
</tr>
<tr class="pass">
<td class="cell c0">String</td>
<td class="cell c1"><span style="color:green;"><i class="fa fa-check"></i></span></td>
<td class="cell c2"><pre>sin(x^2)</pre></td>
<td class="cell c3"><pre>&quot;sin(x^2)&quot;</pre></td>
<td class="cell c2"><pre>&quot; Hello &quot;</pre></td>
<td class="cell c3"><pre>&quot;Hello&quot;</pre></td>
<td class="cell c4"></td>
<td class="cell c5">1</td>
<td class="cell c5">0</td>
<td class="cell c6"></td>
</tr>
<tr class="emptyrow">
<td class="cell c0"></td>
<td class="cell c1"></td>
<td class="cell c2"></td>
<td class="cell c3"></td>
<td class="cell c4"></td>
<td class="cell c5"></td>
<td class="cell c6"></td>
<tr class="notes">
<td class="cell c0"><td colspan="6">Whitespace is trimmed off around atoms</td></td>
</tr>
<tr class="emptyrow">
<td class="cell c0"></td>
<td class="cell c1"></td>
<td class="cell c2"></td>
<td class="cell c3"></td>
<tr class="pass">
<td class="cell c0">String</td>
<td class="cell c1"><span style="color:green;"><i class="fa fa-check"></i></span></td>
<td class="cell c2"><pre> Hello </pre></td>
<td class="cell c3"><pre>Hello</pre></td>
<td class="cell c4"></td>
<td class="cell c5"></td>
<td class="cell c5">1</td>
<td class="cell c6"></td>
</tr>
<tr class="emptyrow">
<td class="cell c0"></td>
<td class="cell c1"></td>
<td class="cell c2"></td>
<td class="cell c3"></td>
<td class="cell c4"></td>
<td class="cell c5"></td>
<td class="cell c6"></td>
<tr class="notes">
<td class="cell c0"><td colspan="6">This test works on expressions as well as strings</td></td>
</tr>
<tr class="emptyrow">
<td class="cell c0"></td>
<td class="cell c1"></td>
<td class="cell c2"></td>
<td class="cell c3"></td>
<tr class="pass">
<td class="cell c0">String</td>
<td class="cell c1"><span style="color:green;"><i class="fa fa-check"></i></span></td>
<td class="cell c2"><pre>sin(x^2)</pre></td>
<td class="cell c3"><pre>&quot;sin(x^2)&quot;</pre></td>
<td class="cell c4"></td>
<td class="cell c5"></td>
<td class="cell c5">1</td>
<td class="cell c6"></td>
</tr>
<tr class="emptyrow">
<td class="cell c0"></td>
<td class="cell c1"></td>
<td class="cell c2"></td>
<td class="cell c3"></td>
<tr class="pass">
<td class="cell c0">String</td>
<td class="cell c1"><span style="color:green;"><i class="fa fa-check"></i></span></td>
<td class="cell c2"><pre>pi^2/6</pre></td>
<td class="cell c3"><pre>&quot;pi^2/6&quot;</pre></td>
<td class="cell c4"></td>
<td class="cell c5"></td>
<td class="cell c5">1</td>
<td class="cell c6"></td>
</tr>
<tr class="emptyrow">
<td class="cell c0"></td>
<td class="cell c1"></td>
<td class="cell c2"></td>
<td class="cell c3"></td>
<tr class="pass">
<td class="cell c0">String</td>
<td class="cell c1"><span style="color:green;"><i class="fa fa-check"></i></span></td>
<td class="cell c2"><pre>pi^2/6</pre></td>
<td class="cell c3"><pre>&quot;%pi^2/6&quot;</pre></td>
<td class="cell c4"></td>
<td class="cell c5"></td>
<td class="cell c5">0</td>
<td class="cell c6"></td>
</tr>
<tr class="emptyrow">
Expand Down
12 changes: 6 additions & 6 deletions doc/en/Authoring/Answer_Tests/Results/StringSloppy.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ This page exposes the results of running answer tests on STACK test cases. This
<td class="cell c5">0</td>
<td class="cell c6"></td>
</tr>
<tr class="emptyrow">
<td class="cell c0"></td>
<td class="cell c1"></td>
<td class="cell c2"></td>
<td class="cell c3"></td>
<tr class="pass">
<td class="cell c0">StringSloppy</td>
<td class="cell c1"><span style="color:green;"><i class="fa fa-check"></i></span></td>
<td class="cell c2"><pre>&quot; hel lo &quot;</pre></td>
<td class="cell c3"><pre>&quot;hello&quot;</pre></td>
<td class="cell c4"></td>
<td class="cell c5"></td>
<td class="cell c5">1</td>
<td class="cell c6"></td>
</tr>
<tr class="emptyrow">
Expand Down
10 changes: 6 additions & 4 deletions doc/en/Authoring/Answer_Tests/String.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

On rare occasions string matching is useful.

A much more useful feature is the [Damerau-Levenshtein distance](../../Topics/Levenshtein_distance.md).
Note that rather than using a string match a useful feature is the [Damerau-Levenshtein distance](../../Topics/Levenshtein_distance.md).

Since student's expressions are, by default, not permitted to contain spaces you will probably need to make use of the string input type.
If the argument to these tests is _not_ a Maxima string then (1) whitespace is stripped off and (2) the expression is turned into a string. The conversion to a Maxima string happens inside PHP: if you use `ATString` in the sandbox without a string argument, the Maxima function will throw an error.

### ATString ###

This test performs a string match ignoring leading and trailing white space which are stripped from all answers, using PHP's trim() function.
This test performs a string match. Whitespace anywhere within a string is unchanged.

If you use a string input, and want to trim whitespace from each end before using this answer test, you can process the string in Maxima, e.g. using `strim(" ", ans1)`. This can be used as an argument to `ATString` in the PRT.

### ATStringSloppy ###

This test removes spaces, newlines and tabs and then performs a string match.
This test removes all spaces, newlines and tabs within the string and then performs a string match.

### ATSRegExp ###

Expand Down
11 changes: 8 additions & 3 deletions tests/fixtures/answertestfixtures.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2580,17 +2580,22 @@ class stack_answertest_test_data {
['UnitsStrictAbsolute', '10.0', '2.321*m', '2300.0*mm', 0, 'ATUnits_compatible_units m.', ''],
['UnitsStrictAbsolute', '10.0', '2.301*kg', '2300.0*mm', 0, 'ATUnits_incompatible_units.', ''],

['String', '', '"Hello"', '"hello"', 0, '', ''],
['String', '', '"hello"', '"hello"', 1, '', ''],
['String', '', '"hello"', '"heloo"', 0, '', ''],
['String', '', '"With spaces"', '"With spaces"', 1, '', ''],
['String', '', '"Without spaces"', '"Withoutspaces"', 0, '', ''],
['String', '', 'Hello', 'hello', 0, '', ''],
['String', '', 'hello', 'hello', 1, '', ''],
['String', '', 'hello', 'heloo', 0, '', ''],
['String', '', '" Hello "', '"Hello"', 0, '', 'Whitespace not trimmed off inside strings'],
['String', '', ' Hello ', 'Hello', 1, '', 'Whitespace is trimmed off around atoms'],
['String', '', 'sin(x^2)', '"sin(x^2)"', 1, '', 'This test works on expressions as well as strings'],
['String', '', 'pi^2/6', '"pi^2/6"', 1, '', ''],
['String', '', 'pi^2/6', '"%pi^2/6"', 0, '', ''],

['StringSloppy', '', '"hello"', '"hello"', 1, '', ''],
['StringSloppy', '', '"hello"', '"heloo"', 0, '', ''],
['StringSloppy', '', '"hel lo"', '"hello"', 1, '', ''],
['StringSloppy', '', '"hel lo"', '"Hel*lo"', 0, '', ''],
['StringSloppy', '', '" hel lo "', '"hello"', 1, '', ''],

['Levenshtein', '', '"Hello"', '"Hello"', 0, 'STACKERROR_OPTION.', ''],
['Levenshtein', '0.9', '1/0', '"Hello"', -1, 'ATLevenshtein_STACKERROR_SAns.', ''],
Expand Down

0 comments on commit 382fcab

Please sign in to comment.