diff options
Diffstat (limited to 'ocaml/test/year2025/day01/part02')
| -rw-r--r-- | ocaml/test/year2025/day01/part02/dune | 11 | ||||
| -rw-r--r-- | ocaml/test/year2025/day01/part02/test_dial.ml | 42 | ||||
| -rw-r--r-- | ocaml/test/year2025/day01/part02/test_solver.ml | 23 |
3 files changed, 76 insertions, 0 deletions
diff --git a/ocaml/test/year2025/day01/part02/dune b/ocaml/test/year2025/day01/part02/dune new file mode 100644 index 0000000..52cff9d --- /dev/null +++ b/ocaml/test/year2025/day01/part02/dune @@ -0,0 +1,11 @@ +(tests + (names + test_dial + test_solver) + (libraries + year2025 + alcotest + qcheck-core + qcheck-alcotest) + (action (run %{test} -e)) + (modes byte exe)) diff --git a/ocaml/test/year2025/day01/part02/test_dial.ml b/ocaml/test/year2025/day01/part02/test_dial.ml new file mode 100644 index 0000000..2d09635 --- /dev/null +++ b/ocaml/test/year2025/day01/part02/test_dial.ml @@ -0,0 +1,42 @@ +open Year2025.Day01.Part02.Dial +open Year2025.Day01.Part02.Turner + +let test_start () = + Alcotest.(check int) "incorrect starting state" 50 (Dial.to_int Dial.start) + +let test_turn errmsg exp dir = + Alcotest.(check int) + errmsg exp + (Dial.to_int (fst (Turner.turn Dial.start 0 dir))) + +let test_turn_left_one () = + test_turn "incorrect result when turning left one step" 49 (Dial.Left 1) + +let test_turn_left_100 () = + test_turn "incorrect result when turning left 100 steps" 50 (Dial.Left 100) + +let test_turn_right_one () = + test_turn "incorrect result when turning right one step" 51 (Dial.Right 1) + +let test_turn_right_100 () = + test_turn "incorrect result when turning right 100 steps" 50 (Dial.Right 100) + +let test_zero_count errmsg exp dir = + Alcotest.(check int) errmsg exp (snd (Turner.turn Dial.start 0 dir)) + +let test_zero_count_right_1000 () = + test_zero_count "zero MUST be counted each time it is passed" 10 + (Dial.Right 1000) + +let () = + let open Alcotest in + run "D01p02" + [ ("initial-state", [test_case "starting state" `Quick test_start]) + ; ( "turning-dial-regression" + , [ test_case "turning left one step" `Quick test_turn_left_one + ; test_case "turning right one step" `Quick test_turn_right_one + ; test_case "turning left 100 steps" `Quick test_turn_left_100 + ; test_case "turning right 100 steps" `Quick test_turn_right_100 ] ) + ; ( "zero-count" + , [ test_case "zero count after turning right 1000 steps" `Quick + test_zero_count_right_1000 ] ) ] diff --git a/ocaml/test/year2025/day01/part02/test_solver.ml b/ocaml/test/year2025/day01/part02/test_solver.ml new file mode 100644 index 0000000..c4c1123 --- /dev/null +++ b/ocaml/test/year2025/day01/part02/test_solver.ml @@ -0,0 +1,23 @@ +open Year2025.Day01.Part02.Solver + +let example_data = {|L68 +L30 +R48 +L5 +R60 +L55 +L1 +L99 +R14 +L82|} + +let test_full_given_example () = + Alcotest.(check int) + "full given example" 6 + (match solve example_data () with Error _ -> 0 | Ok ans -> ans) + +let () = + let open Alcotest in + run "D01p02" + [ ( "given-example" + , [test_case "full given example" `Quick test_full_given_example] ) ] |
