summaryrefslogtreecommitdiff
path: root/ocaml/test/year2024/day02/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/day02/test_part01.ml
parent976048a85403fbb0751c34fa42703a3c47f6e918 (diff)
test: fix ocaml tests 2024 {WIP}HEADmain
Diffstat (limited to 'ocaml/test/year2024/day02/test_part01.ml')
-rw-r--r--ocaml/test/year2024/day02/test_part01.ml41
1 files changed, 41 insertions, 0 deletions
diff --git a/ocaml/test/year2024/day02/test_part01.ml b/ocaml/test/year2024/day02/test_part01.ml
new file mode 100644
index 0000000..4feea41
--- /dev/null
+++ b/ocaml/test/year2024/day02/test_part01.ml
@@ -0,0 +1,41 @@
+open Year2024.Day02.Part01
+
+let test_solve have want () =
+ Alcotest.(check int) "incorrect solution" want @@ solve have
+
+let test_report_safety_check have want () =
+ Alcotest.(check bool) "incorrect report safety" want
+ @@ check_report_safety have
+
+let () =
+ let open Alcotest in
+ run "test suite for day 2 part 1"
+ [ ( "test solutions"
+ , [ test_case "empty list should have no valid reports" `Quick
+ @@ test_solve [] 0
+ ; test_case "valid report should count as one" `Quick
+ @@ test_solve [[7; 6; 4; 2; 1]] 1
+ ; test_case "provided example" `Quick
+ @@ test_solve
+ [ [7; 6; 4; 2; 1]
+ ; [1; 2; 7; 8; 9]
+ ; [9; 7; 6; 2; 1]
+ ; [1; 3; 2; 4; 5]
+ ; [8; 6; 4; 4; 1]
+ ; [1; 3; 6; 7; 9] ]
+ 2 ] )
+ ; ( "test report safety check"
+ , [ test_case "all increasing" `Quick
+ @@ test_report_safety_check [1; 2; 3] true
+ ; test_case "all decreasing" `Quick
+ @@ test_report_safety_check [3; 2; 1] true
+ ; test_case "increasing and decreasing" `Quick
+ @@ test_report_safety_check [1; 3; 2] false
+ ; test_case "change of at least one" `Quick
+ @@ test_report_safety_check [1; 2; 3] true
+ ; test_case "no change" `Quick
+ @@ test_report_safety_check [1; 1; 2] false
+ ; test_case "change of at most three" `Quick
+ @@ test_report_safety_check [1; 2; 4; 7] true
+ ; test_case "change of at more than three" `Quick
+ @@ test_report_safety_check [1; 5] false ] ) ]