tracks/ocaml/exercises/say/test.ml in trackler-2.0.1.1 vs tracks/ocaml/exercises/say/test.ml in trackler-2.0.1.2
- old
+ new
@@ -1,65 +1,61 @@
open Core.Std
open OUnit2
open Say
-(* A wrapper around the assert_equal function from oUnit to reduce the test
- boilerplate. *)
-let say_test exp n =
- exp>::(fun _ctx ->
- assert_equal ~printer:(Option.value ~default:"None")
- (Some exp) (in_english n))
+let ae exp got _ctx = assert_equal ~printer:(Option.value ~default:"None") exp got
let tests = [
- "cannot say numbers below 0">::(fun _ ->
- assert_bool "-1" (in_english (-1L) |> Option.is_none));
- "cannot say numbers above 1 trillion">::(fun _ ->
- assert_bool "1 trillion"
- (in_english 1_000_000_000_000L |> Option.is_none));
- say_test "zero" 0L;
- say_test "one" 1L;
- say_test "two" 2L;
- say_test "three" 3L;
- say_test "seven" 7L;
- say_test "ten" 10L;
- say_test "eleven" 11L;
- say_test "twelve" 12L;
- say_test "thirteen" 13L;
- say_test "fourteen" 14L;
- say_test "fifteen" 15L;
- say_test "sixteen" 16L;
- say_test "seventeen" 17L;
- say_test "eighteen" 18L;
- say_test "nineteen" 19L;
- say_test "twenty" 20L;
- say_test "twenty-four" 24L;
- say_test "thirty" 30L;
- say_test "thirty-five" 35L;
- say_test "forty-eight" 48L;
- say_test "fifty-seven" 57L;
- say_test "sixty" 60L;
- say_test "seventy-one" 71L;
- say_test "eighty-three" 83L;
- say_test "ninety-nine" 99L;
- say_test "one hundred" 100L;
- say_test "one hundred five" 105L;
- say_test "four hundred eighty-five" 485L;
- say_test "nine hundred ninety-nine" 999L;
- say_test "one thousand" 1000L;
- say_test "one thousand two" 1002L;
- say_test "one thousand three hundred twenty-three" 1323L;
- say_test "eight thousand seven hundred eleven" 8711L;
- say_test "nine hundred fifty-eight thousand one hundred forty-five" 958145L;
- say_test "one million" 1_000_000L;
- say_test "one billion" 1_000_000_000L;
- say_test ("nine hundred eighty-seven billion six hundred fifty-four " ^
- "million three hundred twenty-one thousand one hundred " ^
- "twenty-three") 987_654_321_123L;
+ "zero" >:: (
+ ae (Some "zero")
+ (in_english 0L));
+ "one" >:: (
+ ae (Some "one")
+ (in_english 1L));
+ "fourteen" >:: (
+ ae (Some "fourteen")
+ (in_english 14L));
+ "twenty" >:: (
+ ae (Some "twenty")
+ (in_english 20L));
+ "twenty-two" >:: (
+ ae (Some "twenty-two")
+ (in_english 22L));
+ "one hundred" >:: (
+ ae (Some "one hundred")
+ (in_english 100L));
+ "one hundred twenty-three" >:: (
+ ae (Some "one hundred twenty-three")
+ (in_english 123L));
+ "one thousand" >:: (
+ ae (Some "one thousand")
+ (in_english 1000L));
+ "one thousand two hundred thirty-four" >:: (
+ ae (Some "one thousand two hundred thirty-four")
+ (in_english 1234L));
+ "one million" >:: (
+ ae (Some "one million")
+ (in_english 1000000L));
+ "one million two thousand three hundred forty-five" >:: (
+ ae (Some "one million two thousand three hundred forty-five")
+ (in_english 1002345L));
+ "one billion" >:: (
+ ae (Some "one billion")
+ (in_english 1000000000L));
+ "a big number" >:: (
+ ae (Some "nine hundred eighty-seven billion six hundred fifty-four million three hundred twenty-one thousand one hundred twenty-three")
+ (in_english 987654321123L));
+ "numbers below zero are out of range" >:: (
+ ae None
+ (in_english (-1L)));
+ "numbers above 999,999,999,999 are out of range" >:: (
+ ae None
+ (in_english 1000000000000L));
"all numbers from 1 to 10_000 can be spelt">::(fun _ ->
- assert_bool "range test" (Sequence.range 0 10_000
- |> Sequence.map ~f:(fun n -> Int64.of_int n |> in_english)
- |> Sequence.filter ~f:(Option.is_none)
- |> Sequence.is_empty));
- ]
+ assert_bool "range test" (Sequence.range 0 10_000
+ |> Sequence.map ~f:(fun n -> Int64.of_int n |> in_english)
+ |> Sequence.filter ~f:(Option.is_none)
+ |> Sequence.is_empty));
+]
let () =
- run_test_tt_main ("say tests" >::: tests)
+ run_test_tt_main ("say tests" >::: tests)
\ No newline at end of file