Skip to content

Commit fe984fb

Browse files
committed
Add some is_covered_by tests
1 parent 315dac6 commit fe984fb

File tree

1 file changed

+78
-12
lines changed

1 file changed

+78
-12
lines changed

tests/unit/cdomains/affineEqualityDomain/sparseImplementation/sparseMatrixImplementationTest.ml

Lines changed: 78 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ let frac numerator denominator = D.of_frac numerator denominator
2020
(** Shorthands for common functions. *)
2121
let float x = D.of_float x
2222

23+
let make_matrix_of_2d_list l =
24+
List.fold_left
25+
(fun acc row -> Matrix.append_row acc (Vector.of_list row))
26+
(Matrix.empty ())
27+
l
28+
2329
(** This function runs the equality assertion with the solution after normalizing the matrix. *)
2430
let normalize_and_assert (matrix : Matrix.t) (solution : Matrix.t) =
2531
let get_dimensions m = (Matrix.num_rows m, Matrix.num_cols m) in
@@ -183,17 +189,77 @@ let does_not_change_normalized_matrix _ =
183189
in
184190
normalize_and_assert already_normalized already_normalized
185191

186-
let tests =
187-
"SparseMatrixImplementationTest"
188-
>::: [
189-
"can solve a standard normalization" >:: standard_normalize;
190-
"does sort already reduzed" >:: does_just_sort;
191-
"does eliminate dependent rows" >:: does_eliminate_dependent_rows;
192-
(* Looks like the tests are deadlock or inifinite execution when those are activated. *)
193-
(*"can handle float domain" >:: does_handle_floats;*)
194-
(*"can handle fraction domain" >:: does_handle_fractions;*)
195-
"does negate negative matrix" >:: does_negate_negative;
196-
"does not change already normalized matrix" >:: does_not_change_normalized_matrix;
197-
]
192+
let is_covered_by_simple _ =
193+
let m1 = Matrix.init_with_vec (Vector.of_list [int 1; int 1; int 2; int 10]) in
194+
let m2 = Matrix.append_row
195+
(Matrix.append_row
196+
(Matrix.empty ())
197+
(Vector.of_list [int 1; int 1; int 0; int 6]))
198+
(Vector.of_list [int 0; int 0; int 1; int 2]) in
199+
let result = Matrix.is_covered_by m1 m2 in
200+
assert_bool "Matrix m1 is covered by m2, but was false" result
201+
202+
let is_covered_by_vector_first_row _ =
203+
let m1 = Matrix.init_with_vec (Vector.of_list [int 1; int 2; int 0; int 7]) in
204+
let m2 = Matrix.append_row
205+
(Matrix.append_row
206+
(Matrix.empty ())
207+
(Vector.of_list [int 1; int 2; int 0; int 7]))
208+
(Vector.of_list [int 0; int 0; int 1; int 2]) in
209+
let result = Matrix.is_covered_by m1 m2 in
210+
assert_bool "Matrix m1 is covered by m2, but was false" result
211+
212+
let is_zero_vec_covered _ =
213+
let m1 = Matrix.init_with_vec (Vector.zero_vec 4) in
214+
let m2 = Matrix.append_row
215+
(Matrix.append_row
216+
(Matrix.empty ())
217+
(Vector.of_list [int 1; int 2; int 0; int 7]))
218+
(Vector.of_list [int 0; int 0; int 1; int 2]) in
219+
let result = Matrix.is_covered_by m1 m2 in
220+
assert_bool "Matrix m1 is covered by m2, but was false" result
221+
222+
let is_not_covered _ =
223+
let m1 = Matrix.init_with_vec (Vector.of_list [int 1; int 1; int 2; int 10]) in
224+
let m2 = Matrix.append_row
225+
(Matrix.append_row
226+
(Matrix.empty ())
227+
(Vector.of_list [int 1; int 1; int 0; int 6]))
228+
(Vector.of_list [int 0; int 0; int 1; int 3]) in
229+
let result = Matrix.is_covered_by m2 m1 in
230+
assert_bool "Matrix m1 is not covered by m2, but was true" (not result)
231+
232+
let is_covered_big _ =
233+
let m1 = make_matrix_of_2d_list @@
234+
[[int 1; int 0; int 0; int 0; int 0; int (-1); int 0];
235+
[int 0; int 1; int 0; int 0; int 0; int (-2); int 0];
236+
[int 0; int 0; int 1; (frac (-1) 3); frac 1 3; int 0; frac 1 3]] in
237+
238+
let m2 = make_matrix_of_2d_list @@
239+
[[int 1; int 0; int 0; int 0; int 0; int 0; int 0];
240+
[int 0; int 1; int 0; int 0; int 0; int 0; int 0];
241+
[int 0; int 0; int 1; frac (-1) 3; frac 1 3; int 0; frac 1 3];
242+
[int 0; int 0; int 0; int 0; int 0; int 1; int 0]] in
243+
244+
let result = Matrix.is_covered_by m1 m2 in
245+
assert_bool "Matrix m1 is covered by m2, but was false" (result)
246+
247+
let tests =
248+
"SparseMatrixImplementationTest"
249+
>::: [
250+
"can solve a standard normalization" >:: standard_normalize;
251+
"does sort already reduzed" >:: does_just_sort;
252+
"does eliminate dependent rows" >:: does_eliminate_dependent_rows;
253+
(* Looks like the tests are deadlock or inifinite execution when those are activated. *)
254+
(*"can handle float domain" >:: does_handle_floats;*)
255+
(*"can handle fraction domain" >:: does_handle_fractions;*)
256+
"does negate negative matrix" >:: does_negate_negative;
257+
"does not change already normalized matrix" >:: does_not_change_normalized_matrix;
258+
"m1 is covered by m2" >:: is_covered_by_simple;
259+
"m1 is covered by m2 with vector in first row" >:: is_covered_by_vector_first_row;
260+
"zero vector is covered by m2" >:: is_zero_vec_covered;
261+
"m1 is not covered by m2" >:: is_not_covered;
262+
"m1 is covered by m2 with big matrix" >:: is_covered_big;
263+
]
198264

199265
let () = run_test_tt_main tests

0 commit comments

Comments
 (0)