1
exercism fetch ocaml rectangles

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
64
65
66
67
68
69
70
71
72
(* Test/exercise version: "1.0.0" *)

open Core
open OUnit2
open Rectangles

let ae exp got _test_ctxt = assert_equal exp got ~printer:Int.to_string

let tests = [
   "no rows" >::
      ae 0 (count_rectangles [||]);
   "no columns" >::
      ae 0 (count_rectangles [|""|]);
   "no rectangles" >::
      ae 0 (count_rectangles [|" "|]);
   "one rectangle" >::
      ae 1 (count_rectangles [|"+-+"; 
                               "| |"; 
                               "+-+"|]);
   "two rectangles without shared parts" >::
      ae 2 (count_rectangles [|"  +-+"; 
                               "  | |"; 
                               "+-+-+"; 
                               "| |  "; 
                               "+-+  "|]);
   "five rectangles with shared parts" >::
      ae 5 (count_rectangles [|"  +-+"; 
                               "  | |"; 
                               "+-+-+"; 
                               "| | |"; 
                               "+-+-+"|]);
   "rectangle of height 1 is counted" >::
      ae 1 (count_rectangles [|"+--+"; 
                               "+--+"|]);
   "rectangle of width 1 is counted" >::
      ae 1 (count_rectangles [|"++"; 
                               "||"; 
                               "++"|]);
   "1x1 square is counted" >::
      ae 1 (count_rectangles [|"++";
                               "++"|]);
   "only complete rectangles are counted" >::
      ae 1 (count_rectangles [|"  +-+"; 
                               "    |"; 
                               "+-+-+"; 
                               "| | -"; 
                               "+-+-+"|]);
   "rectangles can be of different sizes" >::
      ae 3 (count_rectangles [|"+------+----+"; 
                               "|      |    |"; 
                               "+---+--+    |"; 
                               "|   |       |"; 
                               "+---+-------+"|]);
   "corner is required for a rectangle to be complete" >::
      ae 2 (count_rectangles [|"+------+----+"; 
                               "|      |    |"; 
                               "+------+    |"; 
                               "|   |       |"; 
                               "+---+-------+"|]);
   "large input with many rectangles" >::
      ae 60 (count_rectangles [|"+---+--+----+"; 
                                "|   +--+----+"; 
                                "+---+--+    |"; 
                                "|   +--+----+"; 
                                "+---+--+--+-+"; 
                                "+---+--+--+-+"; 
                                "+------+  | |"; 
                                "          +-+"|]);
]

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