summaryrefslogtreecommitdiff
path: root/ocaml/test/year2024/day01/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/day01/test_part01.ml
parent976048a85403fbb0751c34fa42703a3c47f6e918 (diff)
test: fix ocaml tests 2024 {WIP}HEADmain
Diffstat (limited to 'ocaml/test/year2024/day01/test_part01.ml')
-rw-r--r--ocaml/test/year2024/day01/test_part01.ml30
1 files changed, 30 insertions, 0 deletions
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 ] ) ]