Skip to content

Instantly share code, notes, and snippets.

@mcmillhj mcmillhj/tests.sml
Last active Feb 21, 2017

Embed
What would you like to do?
fun run_tests _ [] = []
| run_tests f (x :: xs) =
let
fun aux { description, is_correct } =
let
val expl = description ^ ": " ^
(if is_correct then "PASSED" else "FAILED") ^ "\n"
in
(print (expl); is_correct)
end
in
(aux x) :: run_tests f xs
end
fun evaluateList f { description, input, expected } =
{ description = description, is_correct = (f input) = expected }
fun evaluateAllergicTo f { description, input, allergen, expected } =
{ description = description, is_correct = (f input allergen) = expected }
val testResults = run_tests list (List.map (evaluateList list) (#list test_cases))
@ run_tests list (List.map (evaluateAllergicTo allergic_to) (#allergic_to test_cases));
val passedTests = List.filter (fn x => x) testResults;
val failedTests = List.filter (fn x => not x) testResults;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.