summaryrefslogtreecommitdiff
path: root/ocaml/test/year2024/day01
diff options
context:
space:
mode:
Diffstat (limited to 'ocaml/test/year2024/day01')
-rw-r--r--ocaml/test/year2024/day01/dune11
-rw-r--r--ocaml/test/year2024/day01/test_part01.ml30
-rw-r--r--ocaml/test/year2024/day01/test_part02.ml16
3 files changed, 57 insertions, 0 deletions
diff --git a/ocaml/test/year2024/day01/dune b/ocaml/test/year2024/day01/dune
new file mode 100644
index 0000000..8891ccf
--- /dev/null
+++ b/ocaml/test/year2024/day01/dune
@@ -0,0 +1,11 @@
+(tests
+ (names
+ test_part01
+ test_part02)
+ (libraries
+ year2024
+ alcotest
+ qcheck-core
+ qcheck-alcotest)
+ (action (run %{test} -e))
+ (modes byte exe))
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 ] ) ]
diff --git a/ocaml/test/year2024/day01/test_part02.ml b/ocaml/test/year2024/day01/test_part02.ml
new file mode 100644
index 0000000..142add6
--- /dev/null
+++ b/ocaml/test/year2024/day01/test_part02.ml
@@ -0,0 +1,16 @@
+open Year2024.Day01.Part02
+
+let test_solve haveLeft haveRight want () =
+ Alcotest.(check int) "incorrect solution" want @@ solve haveLeft haveRight
+
+let () =
+ let open Alcotest in
+ run "test suite for day 01 part 02"
+ [ ( "test solutions"
+ , [ test_case "empty list is 0" `Quick @@ (test_solve [] []) 0
+ ; test_case "ten x zero occurrances of ten" `Quick
+ @@ (test_solve [10] [1; 2; 3]) 0
+ ; test_case "two x three occurrances of two" `Quick
+ @@ (test_solve [2] [2; 2; 2]) 6
+ ; test_case "solves example correctly" `Quick
+ @@ (test_solve [3; 4; 2; 1; 3; 3] [4; 3; 5; 3; 9; 3]) 31 ] ) ]