Skip to content

Commit 2b7f304

Browse files
authored
Merge pull request #448 from pfitaxel/fix/440-neg-int
fix(grader): Display negative numbers with mandatory parens
2 parents b6d44db + 35941b5 commit 2b7f304

File tree

15 files changed

+112
-7
lines changed

15 files changed

+112
-7
lines changed

src/grader/introspection.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ let print_value ppf v ty =
183183
state := `Undecided ;
184184
for i = ofs to ofs + len - 1 do
185185
match String.get s i with
186-
| ' ' | '\n' | '\r' | '\t' ->
186+
| '-' | ' ' | '\n' | '\r' | '\t' ->
187187
state := `Decided true ;
188188
raise Exit
189189
| _ -> ()

tests/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ To run the test suite, please execute `runtests.sh`. It uses docker.
88

99
Each directory must contain a `repo` sub-directory, which will be built and launched with learn-ocaml.
1010
Other sub-directories are named after exercices, and contain different solutions for it. Each solution (for example test.ml) must be provided with the desired output (test.ml.json), which will be compared with the server response.
11+
12+
To update (or generate for the first time) the test.ml.json files, you can execute `runtests.sh set`.

tests/test1/demo/bad_plus.ml.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"text": "Computing"
8080
},
8181
{
82-
"text": "plus 10 -10",
82+
"text": "plus 10 (-10)",
8383
"display": "code"
8484
}
8585
],
@@ -91,7 +91,7 @@
9191
"text": "Wrong value"
9292
},
9393
{
94-
"text": "-100",
94+
"text": "(-100)",
9595
"display": "code"
9696
}
9797
],

tests/test1/demo/demo.ml.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"text": "Computing"
8080
},
8181
{
82-
"text": "plus 10 -10",
82+
"text": "plus 10 (-10)",
8383
"display": "code"
8484
}
8585
],

tests/test1/demo/demo2.ml.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"text": "Computing"
8080
},
8181
{
82-
"text": "plus 10 -10",
82+
"text": "plus 10 (-10)",
8383
"display": "code"
8484
}
8585
],
@@ -155,7 +155,7 @@
155155
"text": "Computing"
156156
},
157157
{
158-
"text": "minus 4 -2",
158+
"text": "minus 4 (-2)",
159159
"display": "code"
160160
}
161161
],
@@ -191,7 +191,7 @@
191191
"text": "Correct value"
192192
},
193193
{
194-
"text": "-10",
194+
"text": "(-10)",
195195
"display": "code"
196196
}
197197
],
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let aff = fun a b x -> a * x + b
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
[
2+
{
3+
"section": [
4+
{
5+
"text": "Function:"
6+
},
7+
{
8+
"text": "aff",
9+
"display": "code"
10+
}
11+
],
12+
"contents": [
13+
{
14+
"message": [
15+
{
16+
"text": "Found"
17+
},
18+
{
19+
"text": "aff",
20+
"display": "code"
21+
},
22+
{
23+
"text": "with compatible type."
24+
}
25+
],
26+
"result": "informative"
27+
},
28+
{
29+
"message": [
30+
{
31+
"text": "Computing"
32+
},
33+
{
34+
"text": "aff 2 (-1) 5",
35+
"display": "code"
36+
}
37+
],
38+
"result": "informative"
39+
},
40+
{
41+
"message": [
42+
{
43+
"text": "Correct value"
44+
},
45+
{
46+
"text": "9",
47+
"display": "code"
48+
}
49+
],
50+
"result": 1
51+
},
52+
{
53+
"message": [
54+
{
55+
"text": "Computing"
56+
},
57+
{
58+
"text": "aff (-2) 1 5",
59+
"display": "code"
60+
}
61+
],
62+
"result": "informative"
63+
},
64+
{
65+
"message": [
66+
{
67+
"text": "Correct value"
68+
},
69+
{
70+
"text": "(-9)",
71+
"display": "code"
72+
}
73+
],
74+
"result": 1
75+
}
76+
]
77+
}
78+
]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{ "learnocaml_version": "1",
2+
"groups":
3+
{ "demo":
4+
{ "title": "Test negative_int",
5+
"exercises": [ "int_exo" ] } } }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Test negative_int
2+
3+
This exercise is just a regression test with pretty-printing negative `int`s.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{"learnocaml_version":"1","kind":"exercise","stars":0,
2+
"title":"Test negative_int"}

tests/test_negative_int/repo/exercises/int_exo/prelude.ml

Whitespace-only changes.

tests/test_negative_int/repo/exercises/int_exo/prepare.ml

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let aff a b x = a * x + b

tests/test_negative_int/repo/exercises/int_exo/template.ml

Whitespace-only changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
open Test_lib
2+
open Report
3+
4+
let () =
5+
set_result @@
6+
ast_sanity_check code_ast @@ fun () ->
7+
[ Section
8+
([ Text "Function:" ; Code "aff" ],
9+
let prot = [%funty: int -> int -> int -> int] in
10+
test_function_against_solution ~gen:(0) prot "aff"
11+
[2 @: (-1) @:!! 5;
12+
(-2) @: 1 @:!! 5])
13+
]

0 commit comments

Comments
 (0)