1
exercism fetch ocaml say

test.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
(* Test/exercise version: "1.0.0" *)

open Core
open OUnit2
open Say

let ae exp got _ctx = assert_equal ~printer:(Option.value ~default:"None") exp got

let tests = [
   "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));
]

let () =
  run_test_tt_main ("say tests" >::: tests)