From 59aa8a1ceef3b425fe6f870c28ee42429a0505f0 Mon Sep 17 00:00:00 2001 From: DJ O'Leary Date: Sun, 7 Dec 2025 03:28:50 +0100 Subject: refactor(2025d4p1): document pp_matrix and add expect_test for it test fails as of now as matrix is rotated --- 2025/ocaml/lib/application/d04p01.ml | 42 +++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 8 deletions(-) (limited to '2025/ocaml/lib/application/d04p01.ml') 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 = {|..@@.@@@@. -- cgit v1.2.3