summaryrefslogtreecommitdiff
path: root/ocaml/test/year2024/day03/test_part01.ml
blob: 78d04e2e814cf7c3bc46cbe85f60500d365e1ec6 (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
open Year2024.Day03.Part01

let example_input =
  "xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))"

let test_find_mul () =
  Alcotest.(check (list string))
    "incorrect mul list found"
    ["mul(2,4)"; "mul(5,5)"; "mul(11,8)"; "mul(8,5)"]
    (let result = find_mul example_input in
     List.map (fun x -> Re2.Match.get_exn x ~sub:(`Index 0)) result )

let test_extract_pairs () =
  Alcotest.(check (list (pair int int)))
    "incorrect pairs"
    [(2, 4); (5, 5); (11, 8); (8, 5)]
    (let matches = find_mul example_input in
     extract_pairs matches )

let test_solve () = Alcotest.(check int) "" 161 @@ solve example_input

let () =
  let open Alcotest in
  run "test suite for day 3 part 1"
    [ ( "test implementation"
      , [ test_case "muls extracted from example correctly" `Quick
          @@ test_find_mul
        ; test_case "pairs extracted from matches" `Quick @@ test_extract_pairs
        ; test_case "example correctly solved" `Quick @@ test_solve ] ) ]