Debian Codegraph @

src/test_macros.rs

raw symbols SCIP
1 /// checks that bitops are symmetric
2 #[macro_export]
3 macro_rules! bitop_symmetry {
4 ($test:ty) => {
5 #[quickcheck]
6 fn bitor_symmetric(a: $test, b: $test) -> bool {
7 &a | &b == &b | &a
8 }
9
10 #[quickcheck]
11 fn bitxor_symmetric(a: $test, b: $test) -> bool {
12 &a ^ &b == &b ^ &a
13 }
14
15 #[quickcheck]
16 fn bitand_symmetric(a: $test, b: $test) -> bool {
17 &a & &b == &b & &a
18 }
19 };
20 }
21
22 /// checks properties of the empty element vs. bitops and sub
23 #[macro_export]
24 macro_rules! bitop_empty {
25 ($test:ty) => {
26 #[quickcheck]
27 fn bitand_empty_neutral(a: $test) -> bool {
28 let e = Test::empty();
29 (&a & &e) == e && (&e & &a) == e
30 }
31
32 #[quickcheck]
33 fn bitor_empty_neutral(a: $test) -> bool {
34 let e = Test::empty();
35 (&a | &e) == a && (&e | &a) == a
36 }
37
38 #[quickcheck]
39 fn bitxor_empty_neutral(a: $test) -> bool {
40 let e = Test::empty();
41 (&a ^ &e) == a && (&e ^ &a) == a
42 }
43
44 #[quickcheck]
45 fn sub_empty_neutral(a: $test) -> bool {
46 let e = Test::empty();
47 (&a - &e) == a
48 }
49 };
50 }
51
52 /// checks properties of the all element vs. bitops and sub/not
53 #[macro_export]
54 macro_rules! bitop_sub_not_all {
55 ($test:ty) => {
56 #[quickcheck]
57 fn bitand_all_neutral(x: $test) -> bool {
58 let a = Test::all();
59 (&x & &a) == x && (&a & &x) == x
60 }
61
62 #[quickcheck]
63 fn bitor_all_all(x: $test) -> bool {
64 let a = Test::all();
65 (&x | &a) == a && (&a | &x) == a
66 }
67
68 #[quickcheck]
69 fn bitxor_all_not(x: $test) -> bool {
70 let a = Test::all();
71 (&a ^ &x) == !&x && (&x ^ &a) == !&x
72 }
73
74 #[quickcheck]
75 fn sub_all_not(x: $test) -> bool {
76 let a = Test::all();
77 (&a - &x) == !&x
78 }
79
80 #[quickcheck]
81 fn sub_bitand_not(a: $test, b: $test) -> bool {
82 (&a).sub(&b) == (&a).bitand(&b.not())
83 }
84
85 #[quickcheck]
86 fn not_not_neutral(a: $test) -> bool {
87 &a == &((&a).not()).not()
88 }
89
90 #[quickcheck]
91 fn all_is_all(a: $test) -> bool {
92 let r1 = a.is_all();
93 let r2 = a == Test::all();
94 r1 == r2
95 }
96 };
97 }
98
99 /// checks consistency between op and op_assign
100 #[macro_export]
101 macro_rules! bitop_assign_consistent {
102 ($test:ty) => {
103 #[quickcheck]
104 fn bitand_assign_consistent(a: $test, b: $test) -> bool {
105 let r1 = &a & &b;
106 let mut r2 = a;
107 r2 &= b;
108 r1 == r2
109 }
110 #[quickcheck]
111 fn bitor_assign_consistent(a: $test, b: $test) -> bool {
112 let r1 = &a | &b;
113 let mut r2 = a;
114 r2 |= b;
115 r1 == r2
116 }
117 #[quickcheck]
118 fn bitxor_assign_consistent(a: $test, b: $test) -> bool {
119 let r1 = &a ^ &b;
120 let mut r2 = a;
121 r2 ^= b;
122 r1 == r2
123 }
124 #[quickcheck]
125 fn sub_assign_consistent(a: $test, b: $test) -> bool {
126 let r1 = &a - &b;
127 let mut r2 = a;
128 r2 -= b;
129 r1 == r2
130 }
131 };
132 }
133
134 // checks that the set predicates is_disjoint, is_subset, is_empty, is_all etc. are consistent with the operations
135 #[macro_export]
136 macro_rules! set_predicate_consistent {
137 ($test:ty) => {
138 #[quickcheck]
139 fn is_disjoint_bitand_consistent(a: $test, b: $test) -> bool {
140 let r1 = a.is_disjoint(&b);
141 let r2 = (&a & &b).is_empty();
142 r1 == r2
143 }
144
145 #[quickcheck]
146 fn is_subset_bitand_consistent(a: $test, b: $test) -> bool {
147 let r1 = a.is_subset(&b);
148 let r2 = &(&a & &b) == &a;
149 r1 == r2
150 }
151
152 #[quickcheck]
153 fn is_subset_is_superset_consistent(a: $test, b: $test) -> bool {
154 let r1 = a.is_subset(&b);
155 let r2 = b.is_superset(&a);
156 r1 == r2
157 }
158
159 #[quickcheck]
160 fn empty_is_empty_consistent(a: $test) -> bool {
161 let r1 = a.is_empty();
162 let r2 = a == Test::empty();
163 r1 == r2
164 }
165 };
166 }