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 / Common / BitArrayTest.php
ameliabooking / vendor / bacon / bacon-qr-code / test / Common Last commit date
BitArrayTest.php 8 months ago BitMatrixTest.php 8 months ago BitUtilsTest.php 8 months ago ErrorCorrectionLevelTest.php 8 months ago FormatInformationTest.php 8 months ago ModeTest.php 8 months ago ReedSolomonCodecTest.php 8 months ago VersionTest.php 8 months ago
BitArrayTest.php
223 lines
1 <?php
2 declare(strict_types = 1);
3
4 namespace BaconQrCodeTest\Common;
5
6 use BaconQrCode\Common\BitArray;
7 use PHPUnit\Framework\TestCase;
8 use PHPUnit\Runner\Version as PHPUnitVersion;
9
10 final class BitArrayTest extends TestCase
11 {
12 private function getPhpUnitMajorVersion(): int
13 {
14 return (int) explode('.', PHPUnitVersion::id())[0];
15 }
16
17 public function testGetSet() : void
18 {
19 $array = new BitArray(33);
20
21 for ($i = 0; $i < 33; ++$i) {
22 $this->assertFalse($array->get($i));
23 $array->set($i);
24 $this->assertTrue($array->get($i));
25 }
26 }
27
28 public function testGetNextSet1() : void
29 {
30 $array = new BitArray(32);
31
32 for ($i = 0; $i < $array->getSize(); ++$i) {
33 if ($this->getPhpUnitMajorVersion() === 7) {
34 $this->assertEquals($i, 32, '', $array->getNextSet($i));
35 } else {
36 $this->assertEqualsWithDelta($i, 32, $array->getNextSet($i));
37 }
38 }
39
40 $array = new BitArray(33);
41
42 for ($i = 0; $i < $array->getSize(); ++$i) {
43 if ($this->getPhpUnitMajorVersion() === 7) {
44 $this->assertEquals($i, 33, '', $array->getNextSet($i));
45 } else {
46 $this->assertEqualsWithDelta($i, 33, $array->getNextSet($i));
47 }
48 }
49 }
50
51 public function testGetNextSet2() : void
52 {
53 $array = new BitArray(33);
54
55 for ($i = 0; $i < $array->getSize(); ++$i) {
56 if ($this->getPhpUnitMajorVersion() === 7) {
57 $this->assertEquals($i, $i <= 31 ? 31 : 33, '', $array->getNextSet($i));
58 } else {
59 $this->assertEqualsWithDelta($i, $i <= 31 ? 31 : 33, $array->getNextSet($i));
60 }
61 }
62
63 $array = new BitArray(33);
64
65 for ($i = 0; $i < $array->getSize(); ++$i) {
66 if ($this->getPhpUnitMajorVersion() === 7) {
67 $this->assertEquals($i, 32, '', $array->getNextSet($i));
68 } else {
69 $this->assertEqualsWithDelta($i, 32, $array->getNextSet($i));
70 }
71 }
72 }
73
74 public function testGetNextSet3() : void
75 {
76 $array = new BitArray(63);
77 $array->set(31);
78 $array->set(32);
79
80 for ($i = 0; $i < $array->getSize(); ++$i) {
81 if ($i <= 31) {
82 $expected = 31;
83 } elseif ($i <= 32) {
84 $expected = 32;
85 } else {
86 $expected = 63;
87 }
88
89 if ($this->getPhpUnitMajorVersion() === 7) {
90 $this->assertEquals($i, $expected, '', $array->getNextSet($i));
91 } else {
92 $this->assertEqualsWithDelta($i, $expected, $array->getNextSet($i));
93 }
94 }
95 }
96
97 public function testGetNextSet4() : void
98 {
99 $array = new BitArray(63);
100 $array->set(33);
101 $array->set(40);
102
103 for ($i = 0; $i < $array->getSize(); ++$i) {
104 if ($i <= 33) {
105 $expected = 33;
106 } elseif ($i <= 40) {
107 $expected = 40;
108 } else {
109 $expected = 63;
110 }
111
112 if ($this->getPhpUnitMajorVersion() === 7) {
113 $this->assertEquals($i, $expected, '', $array->getNextSet($i));
114 } else {
115 $this->assertEqualsWithDelta($i, $expected, $array->getNextSet($i));
116 }
117 }
118 }
119
120 public function testGetNextSet5() : void
121 {
122 mt_srand(0xdeadbeef, MT_RAND_PHP);
123
124 for ($i = 0; $i < 10; ++$i) {
125 $array = new BitArray(mt_rand(1, 100));
126 $numSet = mt_rand(0, 19);
127
128 for ($j = 0; $j < $numSet; ++$j) {
129 $array->set(mt_rand(0, $array->getSize() - 1));
130 }
131
132 $numQueries = mt_rand(0, 19);
133
134 for ($j = 0; $j < $numQueries; ++$j) {
135 $query = mt_rand(0, $array->getSize() - 1);
136 $expected = $query;
137
138 while ($expected < $array->getSize() && ! $array->get($expected)) {
139 ++$expected;
140 }
141
142 $actual = $array->getNextSet($query);
143
144 if ($actual !== $expected) {
145 $array->getNextSet($query);
146 }
147
148 $this->assertEquals($expected, $actual);
149 }
150 }
151 }
152
153 public function testSetBulk() : void
154 {
155 $array = new BitArray(64);
156 $array->setBulk(32, 0xFFFF0000);
157
158 for ($i = 0; $i < 48; ++$i) {
159 $this->assertFalse($array->get($i));
160 }
161
162 for ($i = 48; $i < 64; ++$i) {
163 $this->assertTrue($array->get($i));
164 }
165 }
166
167 public function testClear() : void
168 {
169 $array = new BitArray(32);
170
171 for ($i = 0; $i < 32; ++$i) {
172 $array->set($i);
173 }
174
175 $array->clear();
176
177 for ($i = 0; $i < 32; ++$i) {
178 $this->assertFalse($array->get($i));
179 }
180 }
181
182 public function testGetArray() : void
183 {
184 $array = new BitArray(64);
185 $array->set(0);
186 $array->set(63);
187
188 $ints = $array->getBitArray();
189
190 $this->assertSame(1, $ints[0]);
191 $this->assertSame(0x80000000, $ints[1]);
192 }
193
194 public function testIsRange() : void
195 {
196 $array = new BitArray(64);
197 $this->assertTrue($array->isRange(0, 64, false));
198 $this->assertFalse($array->isRange(0, 64, true));
199
200 $array->set(32);
201 $this->assertTrue($array->isRange(32, 33, true));
202
203 $array->set(31);
204 $this->assertTrue($array->isRange(31, 33, true));
205
206 $array->set(34);
207 $this->assertFalse($array->isRange(31, 35, true));
208
209 for ($i = 0; $i < 31; ++$i) {
210 $array->set($i);
211 }
212
213 $this->assertTrue($array->isRange(0, 33, true));
214
215 for ($i = 33; $i < 64; ++$i) {
216 $array->set($i);
217 }
218
219 $this->assertTrue($array->isRange(0, 64, true));
220 $this->assertFalse($array->isRange(0, 64, false));
221 }
222 }
223