PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.4
Booking for Appointments and Events Calendar – Amelia v2.4.4
2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / vendor / bacon / bacon-qr-code / test / Encoder / MaskUtilTest.php
ameliabooking / vendor / bacon / bacon-qr-code / test / Encoder Last commit date
EncoderTest.php 8 months ago MaskUtilTest.php 8 months ago MatrixUtilTest.php 8 months ago
MaskUtilTest.php
252 lines
1 <?php
2 declare(strict_types = 1);
3
4 namespace BaconQrCodeTest\Encoder;
5
6 use BaconQrCode\Encoder\ByteMatrix;
7 use BaconQrCode\Encoder\MaskUtil;
8 use PHPUnit\Framework\TestCase;
9
10 class MaskUtilTest extends TestCase
11 {
12 public function dataMaskBits() : array
13 {
14 return [
15 [0, [
16 [1, 0, 1, 0, 1, 0],
17 [0, 1, 0, 1, 0, 1],
18 [1, 0, 1, 0, 1, 0],
19 [0, 1, 0, 1, 0, 1],
20 [1, 0, 1, 0, 1, 0],
21 [0, 1, 0, 1, 0, 1],
22 ]],
23 [1, [
24 [1, 1, 1, 1, 1, 1],
25 [0, 0, 0, 0, 0, 0],
26 [1, 1, 1, 1, 1, 1],
27 [0, 0, 0, 0, 0, 0],
28 [1, 1, 1, 1, 1, 1],
29 [0, 0, 0, 0, 0, 0],
30 ]],
31 [2, [
32 [1, 0, 0, 1, 0, 0],
33 [1, 0, 0, 1, 0, 0],
34 [1, 0, 0, 1, 0, 0],
35 [1, 0, 0, 1, 0, 0],
36 [1, 0, 0, 1, 0, 0],
37 [1, 0, 0, 1, 0, 0],
38 ]],
39 [3, [
40 [1, 0, 0, 1, 0, 0],
41 [0, 0, 1, 0, 0, 1],
42 [0, 1, 0, 0, 1, 0],
43 [1, 0, 0, 1, 0, 0],
44 [0, 0, 1, 0, 0, 1],
45 [0, 1, 0, 0, 1, 0],
46 ]],
47 [4, [
48 [1, 1, 1, 0, 0, 0],
49 [1, 1, 1, 0, 0, 0],
50 [0, 0, 0, 1, 1, 1],
51 [0, 0, 0, 1, 1, 1],
52 [1, 1, 1, 0, 0, 0],
53 [1, 1, 1, 0, 0, 0],
54 ]],
55 [5, [
56 [1, 1, 1, 1, 1, 1],
57 [1, 0, 0, 0, 0, 0],
58 [1, 0, 0, 1, 0, 0],
59 [1, 0, 1, 0, 1, 0],
60 [1, 0, 0, 1, 0, 0],
61 [1, 0, 0, 0, 0, 0],
62 ]],
63 [6, [
64 [1, 1, 1, 1, 1, 1],
65 [1, 1, 1, 0, 0, 0],
66 [1, 1, 0, 1, 1, 0],
67 [1, 0, 1, 0, 1, 0],
68 [1, 0, 1, 1, 0, 1],
69 [1, 0, 0, 0, 1, 1],
70 ]],
71 [7, [
72 [1, 0, 1, 0, 1, 0],
73 [0, 0, 0, 1, 1, 1],
74 [1, 0, 0, 0, 1, 1],
75 [0, 1, 0, 1, 0, 1],
76 [1, 1, 1, 0, 0, 0],
77 [0, 1, 1, 1, 0, 0],
78 ]],
79 ];
80 }
81
82 /**
83 * @dataProvider dataMaskBits
84 */
85 public function testGetDatMaskBit(int $maskPattern, array $expected) : void
86 {
87 for ($x = 0; $x < 6; ++$x) {
88 for ($y = 0; $y < 6; ++$y) {
89 $this->assertSame(
90 1 === $expected[$y][$x],
91 MaskUtil::getDataMaskBit($maskPattern, $x, $y)
92 );
93 }
94 }
95 }
96
97 public function testApplyMaskPenaltyRule1() : void
98 {
99 $matrix = new ByteMatrix(4, 1);
100 $matrix->set(0, 0, 0);
101 $matrix->set(1, 0, 0);
102 $matrix->set(2, 0, 0);
103 $matrix->set(3, 0, 0);
104
105 $this->assertSame(0, MaskUtil::applyMaskPenaltyRule1($matrix));
106
107 // Horizontal
108 $matrix = new ByteMatrix(6, 1);
109 $matrix->set(0, 0, 0);
110 $matrix->set(1, 0, 0);
111 $matrix->set(2, 0, 0);
112 $matrix->set(3, 0, 0);
113 $matrix->set(4, 0, 0);
114 $matrix->set(5, 0, 1);
115 $this->assertSame(3, MaskUtil::applyMaskPenaltyRule1($matrix));
116 $matrix->set(5, 0, 0);
117 $this->assertSame(4, MaskUtil::applyMaskPenaltyRule1($matrix));
118
119 // Vertical
120 $matrix = new ByteMatrix(1, 6);
121 $matrix->set(0, 0, 0);
122 $matrix->set(0, 1, 0);
123 $matrix->set(0, 2, 0);
124 $matrix->set(0, 3, 0);
125 $matrix->set(0, 4, 0);
126 $matrix->set(0, 5, 1);
127 $this->assertSame(3, MaskUtil::applyMaskPenaltyRule1($matrix));
128 $matrix->set(0, 5, 0);
129 $this->assertSame(4, MaskUtil::applyMaskPenaltyRule1($matrix));
130 }
131
132 public function testApplyMaskPenaltyRule2() : void
133 {
134 $matrix = new ByteMatrix(1, 1);
135 $matrix->set(0, 0, 0);
136 $this->assertSame(0, MaskUtil::applyMaskPenaltyRule2($matrix));
137
138 $matrix = new ByteMatrix(2, 2);
139 $matrix->set(0, 0, 0);
140 $matrix->set(1, 0, 0);
141 $matrix->set(0, 1, 0);
142 $matrix->set(1, 1, 1);
143 $this->assertSame(0, MaskUtil::applyMaskPenaltyRule2($matrix));
144
145 $matrix = new ByteMatrix(2, 2);
146 $matrix->set(0, 0, 0);
147 $matrix->set(1, 0, 0);
148 $matrix->set(0, 1, 0);
149 $matrix->set(1, 1, 0);
150 $this->assertSame(3, MaskUtil::applyMaskPenaltyRule2($matrix));
151
152 $matrix = new ByteMatrix(3, 3);
153 $matrix->set(0, 0, 0);
154 $matrix->set(1, 0, 0);
155 $matrix->set(2, 0, 0);
156 $matrix->set(0, 1, 0);
157 $matrix->set(1, 1, 0);
158 $matrix->set(2, 1, 0);
159 $matrix->set(0, 2, 0);
160 $matrix->set(1, 2, 0);
161 $matrix->set(2, 2, 0);
162 $this->assertSame(3 * 4, MaskUtil::applyMaskPenaltyRule2($matrix));
163 }
164
165 public function testApplyMaskPenalty3() : void
166 {
167 // Horizontal 00001011101
168 $matrix = new ByteMatrix(11, 1);
169 $matrix->set(0, 0, 0);
170 $matrix->set(1, 0, 0);
171 $matrix->set(2, 0, 0);
172 $matrix->set(3, 0, 0);
173 $matrix->set(4, 0, 1);
174 $matrix->set(5, 0, 0);
175 $matrix->set(6, 0, 1);
176 $matrix->set(7, 0, 1);
177 $matrix->set(8, 0, 1);
178 $matrix->set(9, 0, 0);
179 $matrix->set(10, 0, 1);
180 $this->assertSame(40, MaskUtil::applyMaskPenaltyRule3($matrix));
181
182 // Horizontal 10111010000
183 $matrix = new ByteMatrix(11, 1);
184 $matrix->set(0, 0, 1);
185 $matrix->set(1, 0, 0);
186 $matrix->set(2, 0, 1);
187 $matrix->set(3, 0, 1);
188 $matrix->set(4, 0, 1);
189 $matrix->set(5, 0, 0);
190 $matrix->set(6, 0, 1);
191 $matrix->set(7, 0, 0);
192 $matrix->set(8, 0, 0);
193 $matrix->set(9, 0, 0);
194 $matrix->set(10, 0, 0);
195 $this->assertSame(40, MaskUtil::applyMaskPenaltyRule3($matrix));
196
197 // Vertical 00001011101
198 $matrix = new ByteMatrix(1, 11);
199 $matrix->set(0, 0, 0);
200 $matrix->set(0, 1, 0);
201 $matrix->set(0, 2, 0);
202 $matrix->set(0, 3, 0);
203 $matrix->set(0, 4, 1);
204 $matrix->set(0, 5, 0);
205 $matrix->set(0, 6, 1);
206 $matrix->set(0, 7, 1);
207 $matrix->set(0, 8, 1);
208 $matrix->set(0, 9, 0);
209 $matrix->set(0, 10, 1);
210 $this->assertSame(40, MaskUtil::applyMaskPenaltyRule3($matrix));
211
212 // Vertical 10111010000
213 $matrix = new ByteMatrix(1, 11);
214 $matrix->set(0, 0, 1);
215 $matrix->set(0, 1, 0);
216 $matrix->set(0, 2, 1);
217 $matrix->set(0, 3, 1);
218 $matrix->set(0, 4, 1);
219 $matrix->set(0, 5, 0);
220 $matrix->set(0, 6, 1);
221 $matrix->set(0, 7, 0);
222 $matrix->set(0, 8, 0);
223 $matrix->set(0, 9, 0);
224 $matrix->set(0, 10, 0);
225 $this->assertSame(40, MaskUtil::applyMaskPenaltyRule3($matrix));
226 }
227
228 public function testApplyMaskPenaltyRule4() : void
229 {
230 // Dark cell ratio = 0%
231 $matrix = new ByteMatrix(1, 1);
232 $matrix->set(0, 0, 0);
233 $this->assertSame(100, MaskUtil::applyMaskPenaltyRule4($matrix));
234
235 // Dark cell ratio = 5%
236 $matrix = new ByteMatrix(2, 1);
237 $matrix->set(0, 0, 0);
238 $matrix->set(0, 0, 1);
239 $this->assertSame(0, MaskUtil::applyMaskPenaltyRule4($matrix));
240
241 // Dark cell ratio = 66.67%
242 $matrix = new ByteMatrix(6, 1);
243 $matrix->set(0, 0, 0);
244 $matrix->set(1, 0, 1);
245 $matrix->set(2, 0, 1);
246 $matrix->set(3, 0, 1);
247 $matrix->set(4, 0, 1);
248 $matrix->set(5, 0, 0);
249 $this->assertSame(30, MaskUtil::applyMaskPenaltyRule4($matrix));
250 }
251 }
252