summaryrefslogtreecommitdiff
path: root/ocaml/test/year2024/day02
diff options
context:
space:
mode:
Diffstat (limited to 'ocaml/test/year2024/day02')
-rw-r--r--ocaml/test/year2024/day02/dune10
-rw-r--r--ocaml/test/year2024/day02/test_part01.ml41
2 files changed, 51 insertions, 0 deletions
diff --git a/ocaml/test/year2024/day02/dune b/ocaml/test/year2024/day02/dune
new file mode 100644
index 0000000..c4a75c4
--- /dev/null
+++ b/ocaml/test/year2024/day02/dune
@@ -0,0 +1,10 @@
+(tests
+ (names
+ test_part01)
+ (libraries
+ year2024
+ alcotest
+ qcheck-core
+ qcheck-alcotest)
+ (action (run %{test} -e))
+ (modes byte exe))
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 ] ) ]