-
Notifications
You must be signed in to change notification settings - Fork 2
/
tests.php
53 lines (46 loc) · 864 Bytes
/
tests.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
require 'bitstream.php';
/**
* Test the bit array using the binary data
* 10000000 11111111 110
*/
$array = new BitArray (19);
for ($i = 0; $i < 19; $i++)
{
assert ($array[$i] == 0);
if ($i == 0 || ($i > 7 && $i < 18))
{
$array[$i] = 1;
}
else
{
$array[$i] = 0;
}
}
for ($i = 0; $i < 19; $i++)
{
if ($i == 0 || ($i > 7 && $i < 18))
{
assert ($array[$i] == 1);
}
else
{
assert ($array[$i] == 0);
}
}
// double-check the internal representation
$vals = unpack ("C*", $array->getData ());
assert ($vals[1] == 1);
assert ($vals[2] == 255);
assert ($vals[3] == 3);
// exercise the BitStreamReader and BitStreamWriter a bit
$writer = new BitStreamWriter ();
foreach ($array as $bit)
{
$writer->writeBit ($bit);
}
$reader = new BitStreamReader ($writer->getData ());
foreach ($array as $bit)
{
assert ($bit == $reader->readBit ());
}