diff options
| author | DJ O'Leary <dijitol@proton.me> | 2026-06-27 04:28:48 +0200 |
|---|---|---|
| committer | DJ O'Leary <dijitol@proton.me> | 2026-06-27 04:28:48 +0200 |
| commit | bc8b9edc0860f4804dfd0ea868ee7beaa564e62a (patch) | |
| tree | e1123d11627b4829586da3b097015b1dbb3d0285 /ocaml/test/year2024/day03 | |
| parent | 976048a85403fbb0751c34fa42703a3c47f6e918 (diff) | |
Diffstat (limited to 'ocaml/test/year2024/day03')
| -rw-r--r-- | ocaml/test/year2024/day03/dune | 10 | ||||
| -rw-r--r-- | ocaml/test/year2024/day03/test_part01.ml | 29 |
2 files changed, 39 insertions, 0 deletions
diff --git a/ocaml/test/year2024/day03/dune b/ocaml/test/year2024/day03/dune new file mode 100644 index 0000000..c4a75c4 --- /dev/null +++ b/ocaml/test/year2024/day03/dune @@ -0,0 +1,10 @@ +(tests + (names + test_part01) + (libraries + year2024 + alcotest + qcheck-core + qcheck-alcotest) + (action (run %{test} -e)) + (modes byte exe)) diff --git a/ocaml/test/year2024/day03/test_part01.ml b/ocaml/test/year2024/day03/test_part01.ml new file mode 100644 index 0000000..78d04e2 --- /dev/null +++ b/ocaml/test/year2024/day03/test_part01.ml @@ -0,0 +1,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 ] ) ] |
