@@ -39,8 +39,7 @@ let normalize_and_assert (matrix : Matrix.t) (solution : Matrix.t) =
3939 " The matrix to normalize and the solution have different dimensions!"
4040 else
4141 match Matrix. normalize matrix with
42- | None ->
43- assert_failure " The matrix is normalizable but was not normalized!"
42+ | None -> assert_failure " The normalization returned None."
4443 | Some reduced_matrix -> assert_equal reduced_matrix solution
4544
4645(* *
@@ -244,6 +243,54 @@ let is_covered_big _ =
244243 let result = Matrix. is_covered_by m1 m2 in
245244 assert_bool " Matrix m1 is covered by m2, but was false" (result)
246245
246+ (* *
247+ Normalization works on an empty matrix.
248+ *)
249+ let normalize_empty _ =
250+ let width = 3 in
251+ let empty_matrix =
252+ Matrix. append_row
253+ (Matrix. append_row
254+ (Matrix. append_row (Matrix. empty () ) (Vector. zero_vec width))
255+ (Vector. zero_vec width))
256+ (Vector. zero_vec width)
257+ in
258+ normalize_and_assert empty_matrix empty_matrix
259+
260+ let normalize_two_columns _ =
261+ let width = 2 in
262+ let two_col_matrix =
263+ Matrix. append_row
264+ (Matrix. append_row (Matrix. empty () )
265+ (Vector. of_sparse_list width [ (0 , int 3 ); (1 , int 2 ) ]))
266+ (Vector. of_sparse_list width [ (0 , int 9 ); (1 , int 6 ) ])
267+ in
268+ let normalized_matrix =
269+ Matrix. append_row
270+ (Matrix. append_row (Matrix. empty () )
271+ (Vector. of_sparse_list width
272+ [ (0 , int 1 ); (1 , D. div (int 2 ) (int 3 )) ]))
273+ (Vector. of_sparse_list width [] )
274+ in
275+ normalize_and_assert two_col_matrix normalized_matrix
276+
277+ let int_domain_to_rational _ =
278+ let width = 3 in
279+ let int_matrix =
280+ Matrix. append_row
281+ (Matrix. append_row (Matrix. empty () )
282+ (Vector. of_sparse_list width [ (0 , int 3 ); (2 , int 1 ) ]))
283+ (Vector. of_sparse_list width [ (0 , int 2 ); (1 , int 1 ); (2 , int 1 ) ])
284+ in
285+ let normalized_matrix =
286+ Matrix. append_row
287+ (Matrix. append_row (Matrix. empty () )
288+ (Vector. of_sparse_list width
289+ [ (0 , int 1 ); (2 , D. div (int 1 ) (int 3 )) ]))
290+ (Vector. of_sparse_list width [ (1 , int 1 ); (2 , D. div (int 1 ) (int 3 )) ])
291+ in
292+ normalize_and_assert int_matrix normalized_matrix
293+
247294let tests =
248295 " SparseMatrixImplementationTest"
249296 > ::: [
@@ -260,6 +307,9 @@ let tests =
260307 " zero vector is covered by m2" > :: is_zero_vec_covered;
261308 " m1 is not covered by m2" > :: is_not_covered;
262309 " m1 is covered by m2 with big matrix" > :: is_covered_big;
310+ " does not change an empty matrix" > :: normalize_empty;
311+ " can correctly normalize a two column matrix" > :: normalize_two_columns;
312+ " can handle a rational solution" > :: int_domain_to_rational;
263313 ]
264314
265315let () = run_test_tt_main tests
0 commit comments