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/day02 | |
| parent | 976048a85403fbb0751c34fa42703a3c47f6e918 (diff) | |
Diffstat (limited to 'ocaml/test/year2024/day02')
| -rw-r--r-- | ocaml/test/year2024/day02/dune | 10 | ||||
| -rw-r--r-- | ocaml/test/year2024/day02/test_part01.ml | 41 |
2 files changed, 51 insertions, 0 deletions
diff --git a/ocaml/test/year2024/day02/dune b/ocaml/test/year2024/day02/dune new file mode 100644 index 0000000..c4a75c4 --- /dev/null +++ b/ocaml/test/year2024/day02/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/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 ] ) ] |
