diff options
Diffstat (limited to 'ocaml/test/year2024/day02/test_part01.ml')
| -rw-r--r-- | ocaml/test/year2024/day02/test_part01.ml | 41 |
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 ] ) ] |
