summaryrefslogtreecommitdiff
path: root/ocaml/test/year2024/day01/test_part01.ml
blob: 706284da41407c4dff4632f67a6fddf237cf1921 (plain)
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
open Year2024.Day01.Part01

let test_solve haveLeft haveRight want () =
  Alcotest.(check int) "incorrect solution" want @@ solve haveLeft haveRight

let test_distance_calculation haveX haveY want () =
  Alcotest.(check int) "incorrect solution" want
  @@ calculate_distance haveX haveY

let () =
  let open Alcotest in
  run "test suite for day 01 part 01"
    [ ( "test solutions"
      , [ test_case "empty list is 0" `Quick @@ (test_solve [] []) 0
        ; test_case "distance between 0 and 1 is 1" `Quick
          @@ (test_solve [0] [1]) 1
        ; test_case "distance between 1 and 0 is 1" `Quick
          @@ (test_solve [1] [0]) 1
        ; test_case "smallest are paired, then next smallest, ..." `Quick
          @@ (test_solve [1; 2; 3] [3; 2; 1]) 0
        ; test_case "solves example correctly" `Quick
          @@ (test_solve [3; 4; 2; 1; 3; 3] [4; 3; 5; 3; 9; 3]) 11
        ; test_case "same number is 0 distance apart" `Quick
          @@ (test_distance_calculation 0 0) 0
        ; test_case "same number is 0 distance apart" `Quick
          @@ (test_distance_calculation 1 1) 0
        ; test_case "distance is equal to abs(x - y)" `Quick
          @@ (test_distance_calculation 0 1) 1
        ; test_case "order of inputs doesn't matter" `Quick
          @@ (test_distance_calculation 1 0) 1 ] ) ]