diff options
| author | DJ O'Leary <dijitol@proton.me> | 2025-12-07 03:28:50 +0100 |
|---|---|---|
| committer | DJ O'Leary <dijitol@proton.me> | 2025-12-07 03:28:50 +0100 |
| commit | 59aa8a1ceef3b425fe6f870c28ee42429a0505f0 (patch) | |
| tree | aeed2c63b5aacf8d69e0645ef4b0859595fbebea /2025 | |
| parent | fe97bbe055116c559d7e6537d2605a21a74dbcbd (diff) | |
refactor(2025d4p1): document pp_matrix and add expect_test for it
test fails as of now as matrix is rotated
Diffstat (limited to '2025')
| -rw-r--r-- | 2025/ocaml/lib/application/d04p01.ml | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/2025/ocaml/lib/application/d04p01.ml b/2025/ocaml/lib/application/d04p01.ml index 0253340..24dd8b4 100644 --- a/2025/ocaml/lib/application/d04p01.ml +++ b/2025/ocaml/lib/application/d04p01.ml @@ -23,21 +23,47 @@ let input_to_matrix input = lines ; matrix +(** [pp_matrix matrix] is the [input] that was used to create the [matrix] + via [input_to_matrix input]. *) let pp_matrix matrix = - "[\n" - ^ ( matrix - |> Array.map @@ Array.fold_left (fun acc c -> acc ^ c) "" - |> Array.fold_left - (fun acc line -> - if acc = "" then " [" ^ line ^ "]" else acc ^ "\n [" ^ line ^ "]" ) - "" ) - ^ "\n]" + matrix + |> Array.map @@ Array.fold_left (fun acc c -> acc ^ c) "" + |> Array.fold_left + (fun acc line -> if acc = "" then line else acc ^ "\n" ^ line) + "" let solve input () = let matrix = input |> input_to_matrix in Logs.debug (fun m -> m "%s" @@ pp_matrix matrix) ; 0 +let%expect_test "matrix created from input is pretty-printed as the same matrix" + = + let example = + {|..@@.@@@@. +@@@.@.@.@@ +@@@@@.@.@@ +@.@@@@..@. +@@.@@@@.@@ +.@@@@@@@.@ +.@.@.@.@@@ +@.@@@.@@@@ +.@@@@@@@@. +@.@.@@@.@.|} + in + print_string @@ pp_matrix @@ input_to_matrix example ; + [%expect + {|..@@.@@@@. +@@@.@.@.@@ +@@@@@.@.@@ +@.@@@@..@. +@@.@@@@.@@ +.@@@@@@@.@ +.@.@.@.@@@ +@.@@@.@@@@ +.@@@@@@@@. +@.@.@@@.@.|}] + let%expect_test "direct access of the matrix is in form matrix.(x).(y)" = let example = {|..@@.@@@@. |
