Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(grader): Display negative numbers with mandatory parens #448

Merged
merged 3 commits into from Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/grader/introspection.ml
Expand Up @@ -183,7 +183,7 @@ let print_value ppf v ty =
state := `Undecided ;
for i = ofs to ofs + len - 1 do
match String.get s i with
| ' ' | '\n' | '\r' | '\t' ->
| '-' | ' ' | '\n' | '\r' | '\t' ->
state := `Decided true ;
raise Exit
| _ -> ()
Expand Down
2 changes: 2 additions & 0 deletions tests/README.md
Expand Up @@ -8,3 +8,5 @@ To run the test suite, please execute `runtests.sh`. It uses docker.

Each directory must contain a `repo` sub-directory, which will be built and launched with learn-ocaml.
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.

To update (or generate for the first time) the test.ml.json files, you can execute `runtests.sh set`.
4 changes: 2 additions & 2 deletions tests/test1/demo/bad_plus.ml.json
Expand Up @@ -79,7 +79,7 @@
"text": "Computing"
},
{
"text": "plus 10 -10",
"text": "plus 10 (-10)",
"display": "code"
}
],
Expand All @@ -91,7 +91,7 @@
"text": "Wrong value"
},
{
"text": "-100",
"text": "(-100)",
"display": "code"
}
],
Expand Down
2 changes: 1 addition & 1 deletion tests/test1/demo/demo.ml.json
Expand Up @@ -79,7 +79,7 @@
"text": "Computing"
},
{
"text": "plus 10 -10",
"text": "plus 10 (-10)",
"display": "code"
}
],
Expand Down
6 changes: 3 additions & 3 deletions tests/test1/demo/demo2.ml.json
Expand Up @@ -79,7 +79,7 @@
"text": "Computing"
},
{
"text": "plus 10 -10",
"text": "plus 10 (-10)",
"display": "code"
}
],
Expand Down Expand Up @@ -155,7 +155,7 @@
"text": "Computing"
},
{
"text": "minus 4 -2",
"text": "minus 4 (-2)",
"display": "code"
}
],
Expand Down Expand Up @@ -191,7 +191,7 @@
"text": "Correct value"
},
{
"text": "-10",
"text": "(-10)",
"display": "code"
}
],
Expand Down
1 change: 1 addition & 0 deletions tests/test_negative_int/int_exo/correct.ml
@@ -0,0 +1 @@
let aff = fun a b x -> a * x + b
78 changes: 78 additions & 0 deletions tests/test_negative_int/int_exo/correct.ml.json
@@ -0,0 +1,78 @@
[
{
"section": [
{
"text": "Function:"
},
{
"text": "aff",
"display": "code"
}
],
"contents": [
{
"message": [
{
"text": "Found"
},
{
"text": "aff",
"display": "code"
},
{
"text": "with compatible type."
}
],
"result": "informative"
},
{
"message": [
{
"text": "Computing"
},
{
"text": "aff 2 (-1) 5",
"display": "code"
}
],
"result": "informative"
},
{
"message": [
{
"text": "Correct value"
},
{
"text": "9",
"display": "code"
}
],
"result": 1
},
{
"message": [
{
"text": "Computing"
},
{
"text": "aff (-2) 1 5",
"display": "code"
}
],
"result": "informative"
},
{
"message": [
{
"text": "Correct value"
},
{
"text": "(-9)",
"display": "code"
}
],
"result": 1
}
]
}
]
5 changes: 5 additions & 0 deletions tests/test_negative_int/repo/exercises/index.json
@@ -0,0 +1,5 @@
{ "learnocaml_version": "1",
"groups":
{ "demo":
{ "title": "Test negative_int",
"exercises": [ "int_exo" ] } } }
3 changes: 3 additions & 0 deletions tests/test_negative_int/repo/exercises/int_exo/descr.md
@@ -0,0 +1,3 @@
# Test negative_int

This exercise is just a regression test with pretty-printing negative `int`s.
2 changes: 2 additions & 0 deletions tests/test_negative_int/repo/exercises/int_exo/meta.json
@@ -0,0 +1,2 @@
{"learnocaml_version":"1","kind":"exercise","stars":0,
"title":"Test negative_int"}
Empty file.
Empty file.
1 change: 1 addition & 0 deletions tests/test_negative_int/repo/exercises/int_exo/solution.ml
@@ -0,0 +1 @@
let aff a b x = a * x + b
Empty file.
13 changes: 13 additions & 0 deletions tests/test_negative_int/repo/exercises/int_exo/test.ml
@@ -0,0 +1,13 @@
open Test_lib
open Report

let () =
set_result @@
ast_sanity_check code_ast @@ fun () ->
[ Section
([ Text "Function:" ; Code "aff" ],
let prot = [%funty: int -> int -> int -> int] in
test_function_against_solution ~gen:(0) prot "aff"
[2 @: (-1) @:!! 5;
(-2) @: 1 @:!! 5])
]