From 19477a51327ed749bc0f7cf0ad9195e1b401c5f8 Mon Sep 17 00:00:00 2001 From: Erik Martin-Dorel Date: Wed, 13 Oct 2021 17:53:30 +0200 Subject: [PATCH 1/3] docs(tests/README.md): Add hint for test case generation --- tests/README.md | 2 ++ 1 file changed, 2 insertions(+) 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`. From 07033c98b3e73630a4472125673dc386687bc2b1 Mon Sep 17 00:00:00 2001 From: Erik Martin-Dorel Date: Wed, 13 Oct 2021 17:53:49 +0200 Subject: [PATCH 2/3] test: Add test to repro issue #440 --- tests/test_negative_int/int_exo/correct.ml | 1 + .../test_negative_int/int_exo/correct.ml.json | 78 +++++++++++++++++++ .../repo/exercises/index.json | 5 ++ .../repo/exercises/int_exo/descr.md | 3 + .../repo/exercises/int_exo/meta.json | 2 + .../repo/exercises/int_exo/prelude.ml | 0 .../repo/exercises/int_exo/prepare.ml | 0 .../repo/exercises/int_exo/solution.ml | 1 + .../repo/exercises/int_exo/template.ml | 0 .../repo/exercises/int_exo/test.ml | 13 ++++ 10 files changed, 103 insertions(+) create mode 100644 tests/test_negative_int/int_exo/correct.ml create mode 100644 tests/test_negative_int/int_exo/correct.ml.json create mode 100644 tests/test_negative_int/repo/exercises/index.json create mode 100644 tests/test_negative_int/repo/exercises/int_exo/descr.md create mode 100644 tests/test_negative_int/repo/exercises/int_exo/meta.json create mode 100644 tests/test_negative_int/repo/exercises/int_exo/prelude.ml create mode 100644 tests/test_negative_int/repo/exercises/int_exo/prepare.ml create mode 100644 tests/test_negative_int/repo/exercises/int_exo/solution.ml create mode 100644 tests/test_negative_int/repo/exercises/int_exo/template.ml create mode 100644 tests/test_negative_int/repo/exercises/int_exo/test.ml 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..24f6d418a --- /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 + } + ] + } +] 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]) + ] From 35941b5ebe8cb2b947cd6010118050a79c6e36f8 Mon Sep 17 00:00:00 2001 From: Erik Martin-Dorel Date: Wed, 13 Oct 2021 18:17:00 +0200 Subject: [PATCH 3/3] fix(grader): Display negative numbers with mandatory parens; Fix #440 * Thanks @letouzey for reporting this issue and suggesting a fix * Update some learn-ocaml-client tests accordingly --- src/grader/introspection.ml | 2 +- tests/test1/demo/bad_plus.ml.json | 4 ++-- tests/test1/demo/demo.ml.json | 2 +- tests/test1/demo/demo2.ml.json | 6 +++--- tests/test_negative_int/int_exo/correct.ml.json | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) 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/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.json b/tests/test_negative_int/int_exo/correct.ml.json index 24f6d418a..50f6565d5 100644 --- a/tests/test_negative_int/int_exo/correct.ml.json +++ b/tests/test_negative_int/int_exo/correct.ml.json @@ -75,4 +75,4 @@ } ] } -] +] \ No newline at end of file