summaryrefslogtreecommitdiff
path: root/ocaml/test/year2024/day03/test_part01.ml
diff options
context:
space:
mode:
authorDJ O'Leary <dijitol@proton.me>2026-06-27 04:28:48 +0200
committerDJ O'Leary <dijitol@proton.me>2026-06-27 04:28:48 +0200
commitbc8b9edc0860f4804dfd0ea868ee7beaa564e62a (patch)
treee1123d11627b4829586da3b097015b1dbb3d0285 /ocaml/test/year2024/day03/test_part01.ml
parent976048a85403fbb0751c34fa42703a3c47f6e918 (diff)
test: fix ocaml tests 2024 {WIP}HEADmain
Diffstat (limited to 'ocaml/test/year2024/day03/test_part01.ml')
-rw-r--r--ocaml/test/year2024/day03/test_part01.ml29
1 files changed, 29 insertions, 0 deletions
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 ] ) ]