summaryrefslogtreecommitdiff
path: root/2024/ocaml/test/day_02_part_01.ml
diff options
context:
space:
mode:
authorDJ O'Leary <dijitol@proton.me>2025-11-29 20:23:02 +0100
committerDJ O'Leary <dijitol@proton.me>2025-11-29 20:23:02 +0100
commit4c3a50166bf0f78ce89459c352cc1c6536a8b96d (patch)
tree02e4b66a1435680ef1e92bf82576747b27f16447 /2024/ocaml/test/day_02_part_01.ml
parentbe2f8528b3829f8263507da301812d852297c168 (diff)
chore: make language folders snake_case
Diffstat (limited to '2024/ocaml/test/day_02_part_01.ml')
-rw-r--r--2024/ocaml/test/day_02_part_01.ml38
1 files changed, 38 insertions, 0 deletions
diff --git a/2024/ocaml/test/day_02_part_01.ml b/2024/ocaml/test/day_02_part_01.ml
new file mode 100644
index 0000000..36af248
--- /dev/null
+++ b/2024/ocaml/test/day_02_part_01.ml
@@ -0,0 +1,38 @@
+open OUnit2
+open AoC_2024.Day_02.Part_01
+
+let tests =
+ "test suite for day 2 part 1"
+ >::: [
+ ( "empty list should have no valid reports" >:: fun _ ->
+ assert_equal 0 (solve []) );
+ ( "valid report should count as one" >:: fun _ ->
+ assert_equal 1 (solve [ [ 7; 6; 4; 2; 1 ] ]) );
+ ( "example correct" >:: fun _ ->
+ assert_equal 2
+ (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 ];
+ ]) );
+ ( "all increasing" >:: fun _ ->
+ assert_equal true (check_report_safety [ 1; 2; 3 ]) );
+ ( "all decreasing" >:: fun _ ->
+ assert_equal true (check_report_safety [ 3; 2; 1 ]) );
+ ( "increasing and decreasing" >:: fun _ ->
+ assert_equal false (check_report_safety [ 1; 3; 2 ]) );
+ ( "change of at least one" >:: fun _ ->
+ assert_equal true (check_report_safety [ 1; 2; 3 ]) );
+ ( "no change" >:: fun _ ->
+ assert_equal false (check_report_safety [ 1; 1; 2 ]) );
+ ( "change of at most three" >:: fun _ ->
+ assert_equal true (check_report_safety [ 1; 2; 4; 7 ]) );
+ ( "change of at more than three" >:: fun _ ->
+ assert_equal false (check_report_safety [ 1; 5 ]) );
+ ]
+
+let _ = run_test_tt_main tests