From 35941b5ebe8cb2b947cd6010118050a79c6e36f8 Mon Sep 17 00:00:00 2001 From: Erik Martin-Dorel Date: Wed, 13 Oct 2021 18:17:00 +0200 Subject: [PATCH] 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