summaryrefslogtreecommitdiff
path: root/2025/ocaml/test/domain/test_d03p01.ml
diff options
context:
space:
mode:
authorDJ O'Leary <dijitol@proton.me>2025-12-13 03:06:38 +0100
committerDJ O'Leary <dijitol@proton.me>2025-12-13 03:06:38 +0100
commitbd10ab845c8fb630c57730fb56fc9c525f33fd36 (patch)
treea1ed34b85aa42557195259803b02dacbf9479e2a /2025/ocaml/test/domain/test_d03p01.ml
parent0f2faca977da2d24c8a654d9d9ef4b2581c673a1 (diff)
test(2025d3): add property tests
Diffstat (limited to '2025/ocaml/test/domain/test_d03p01.ml')
-rw-r--r--2025/ocaml/test/domain/test_d03p01.ml27
1 files changed, 26 insertions, 1 deletions
diff --git a/2025/ocaml/test/domain/test_d03p01.ml b/2025/ocaml/test/domain/test_d03p01.ml
index f2d64d1..4832e9b 100644
--- a/2025/ocaml/test/domain/test_d03p01.ml
+++ b/2025/ocaml/test/domain/test_d03p01.ml
@@ -5,6 +5,27 @@ let test_highest_joltage have want () =
"highest joltage in battery bank" want
(BatteryBank.of_string have |> BatteryBank.highest_joltage)
+let largest_digit_always_in_highest_joltage =
+ QCheck2.Test.make ~count:1000
+ ~name:
+ "highest joltage always has the largest number first unless the largest \
+ digit in the input is the final digit or there are less than 3 digits"
+ ~print:(fun s -> s)
+ QCheck2.Gen.(string_of @@ char_range '1' '9')
+ (fun have ->
+ QCheck2.assume (String.length have > 2) ;
+ let got =
+ BatteryBank.of_string have |> BatteryBank.highest_joltage
+ |> fun x -> x / 10
+ in
+ let want =
+ String.fold_left
+ (fun acc chr -> if acc < chr then chr else acc)
+ '0' have
+ |> Char.escaped |> int_of_string
+ in
+ got = want )
+
let () =
let open Alcotest in
run "D03p01"
@@ -833,4 +854,8 @@ let () =
; test_case "I have no idea why this is right yet" `Quick
(test_highest_joltage "06760" 76)
; test_case "I have no idea why this is wrong yet" `Quick
- (test_highest_joltage "0067600" 76) ] ) ]
+ (test_highest_joltage "0067600" 76) ] )
+ ; ( "BatteryBank property tests"
+ , List.map
+ (QCheck_alcotest.to_alcotest ~colors:true ~speed_level:`Quick)
+ [largest_digit_always_in_highest_joltage] ) ]