From bc8b9edc0860f4804dfd0ea868ee7beaa564e62a Mon Sep 17 00:00:00 2001 From: DJ O'Leary Date: Sat, 27 Jun 2026 04:28:48 +0200 Subject: test: fix ocaml tests 2024 {WIP} --- ocaml/test/year2024/day01/test_part01.ml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 ocaml/test/year2024/day01/test_part01.ml (limited to 'ocaml/test/year2024/day01/test_part01.ml') diff --git a/ocaml/test/year2024/day01/test_part01.ml b/ocaml/test/year2024/day01/test_part01.ml new file mode 100644 index 0000000..706284d --- /dev/null +++ b/ocaml/test/year2024/day01/test_part01.ml @@ -0,0 +1,30 @@ +open Year2024.Day01.Part01 + +let test_solve haveLeft haveRight want () = + Alcotest.(check int) "incorrect solution" want @@ solve haveLeft haveRight + +let test_distance_calculation haveX haveY want () = + Alcotest.(check int) "incorrect solution" want + @@ calculate_distance haveX haveY + +let () = + let open Alcotest in + run "test suite for day 01 part 01" + [ ( "test solutions" + , [ test_case "empty list is 0" `Quick @@ (test_solve [] []) 0 + ; test_case "distance between 0 and 1 is 1" `Quick + @@ (test_solve [0] [1]) 1 + ; test_case "distance between 1 and 0 is 1" `Quick + @@ (test_solve [1] [0]) 1 + ; test_case "smallest are paired, then next smallest, ..." `Quick + @@ (test_solve [1; 2; 3] [3; 2; 1]) 0 + ; test_case "solves example correctly" `Quick + @@ (test_solve [3; 4; 2; 1; 3; 3] [4; 3; 5; 3; 9; 3]) 11 + ; test_case "same number is 0 distance apart" `Quick + @@ (test_distance_calculation 0 0) 0 + ; test_case "same number is 0 distance apart" `Quick + @@ (test_distance_calculation 1 1) 0 + ; test_case "distance is equal to abs(x - y)" `Quick + @@ (test_distance_calculation 0 1) 1 + ; test_case "order of inputs doesn't matter" `Quick + @@ (test_distance_calculation 1 0) 1 ] ) ] -- cgit v1.2.3