diff --git a/src/grader/introspection.ml b/src/grader/introspection.ml index 9d6011065..2bd4c0eaf 100644 --- a/src/grader/introspection.ml +++ b/src/grader/introspection.ml @@ -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 | _ -> () diff --git a/tests/README.md b/tests/README.md index e1456ba4a..23bb0301b 100644 --- a/tests/README.md +++ b/tests/README.md @@ -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`. diff --git a/tests/test1/demo/bad_plus.ml.json b/tests/test1/demo/bad_plus.ml.json index 0a65f36c1..b74ba58e0 100644 --- a/tests/test1/demo/bad_plus.ml.json +++ b/tests/test1/demo/bad_plus.ml.json @@ -79,7 +79,7 @@ "text": "Computing" }, { - "text": "plus 10 -10", + "text": "plus 10 (-10)", "display": "code" } ], @@ -91,7 +91,7 @@ "text": "Wrong value" }, { - "text": "-100", + "text": "(-100)", "display": "code" } ], diff --git a/tests/test1/demo/demo.ml.json b/tests/test1/demo/demo.ml.json index cddcee7d9..4a9a7943b 100644 --- a/tests/test1/demo/demo.ml.json +++ b/tests/test1/demo/demo.ml.json @@ -79,7 +79,7 @@ "text": "Computing" }, { - "text": "plus 10 -10", + "text": "plus 10 (-10)", "display": "code" } ], diff --git a/tests/test1/demo/demo2.ml.json b/tests/test1/demo/demo2.ml.json index 9cb63cac8..09ee73aa9 100644 --- a/tests/test1/demo/demo2.ml.json +++ b/tests/test1/demo/demo2.ml.json @@ -79,7 +79,7 @@ "text": "Computing" }, { - "text": "plus 10 -10", + "text": "plus 10 (-10)", "display": "code" } ], @@ -155,7 +155,7 @@ "text": "Computing" }, { - "text": "minus 4 -2", + "text": "minus 4 (-2)", "display": "code" } ], @@ -191,7 +191,7 @@ "text": "Correct value" }, { - "text": "-10", + "text": "(-10)", "display": "code" } ], diff --git a/tests/test_negative_int/int_exo/correct.ml b/tests/test_negative_int/int_exo/correct.ml new file mode 100644 index 000000000..d1b742e95 --- /dev/null +++ b/tests/test_negative_int/int_exo/correct.ml @@ -0,0 +1 @@ +let aff = fun a b x -> a * x + b diff --git a/tests/test_negative_int/int_exo/correct.ml.json b/tests/test_negative_int/int_exo/correct.ml.json new file mode 100644 index 000000000..50f6565d5 --- /dev/null +++ b/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 + } + ] + } +] \ No newline at end of file diff --git a/tests/test_negative_int/repo/exercises/index.json b/tests/test_negative_int/repo/exercises/index.json new file mode 100644 index 000000000..cb91e8ba2 --- /dev/null +++ b/tests/test_negative_int/repo/exercises/index.json @@ -0,0 +1,5 @@ +{ "learnocaml_version": "1", + "groups": + { "demo": + { "title": "Test negative_int", + "exercises": [ "int_exo" ] } } } diff --git a/tests/test_negative_int/repo/exercises/int_exo/descr.md b/tests/test_negative_int/repo/exercises/int_exo/descr.md new file mode 100644 index 000000000..cdcdb3e1f --- /dev/null +++ b/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. diff --git a/tests/test_negative_int/repo/exercises/int_exo/meta.json b/tests/test_negative_int/repo/exercises/int_exo/meta.json new file mode 100644 index 000000000..3ed130575 --- /dev/null +++ b/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"} diff --git a/tests/test_negative_int/repo/exercises/int_exo/prelude.ml b/tests/test_negative_int/repo/exercises/int_exo/prelude.ml new file mode 100644 index 000000000..e69de29bb diff --git a/tests/test_negative_int/repo/exercises/int_exo/prepare.ml b/tests/test_negative_int/repo/exercises/int_exo/prepare.ml new file mode 100644 index 000000000..e69de29bb diff --git a/tests/test_negative_int/repo/exercises/int_exo/solution.ml b/tests/test_negative_int/repo/exercises/int_exo/solution.ml new file mode 100644 index 000000000..ce9649c8b --- /dev/null +++ b/tests/test_negative_int/repo/exercises/int_exo/solution.ml @@ -0,0 +1 @@ +let aff a b x = a * x + b diff --git a/tests/test_negative_int/repo/exercises/int_exo/template.ml b/tests/test_negative_int/repo/exercises/int_exo/template.ml new file mode 100644 index 000000000..e69de29bb diff --git a/tests/test_negative_int/repo/exercises/int_exo/test.ml b/tests/test_negative_int/repo/exercises/int_exo/test.ml new file mode 100644 index 000000000..131a71309 --- /dev/null +++ b/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]) + ]