From bc8b9edc0860f4804dfd0ea868ee7beaa564e62a Mon Sep 17 00:00:00 2001 From: DJ O'Leary Date: Sat, 27 Jun 2026 04:28:48 +0200 Subject: test: fix ocaml tests 2024 {WIP} --- ocaml/test/year2024/day03/test_part01.ml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 ocaml/test/year2024/day03/test_part01.ml (limited to 'ocaml/test/year2024/day03/test_part01.ml') 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 ] ) ] -- cgit v1.2.3