1
+ <?php
2
+
3
+ namespace Sokil ;
4
+
5
+ class BitmaskTest extends \PHPUnit_Framework_Testcase
6
+ {
7
+ public function testIsBitSet ()
8
+ {
9
+ // 5 => 101
10
+ $ bitmap = new Bitmap (5 );
11
+
12
+ $ this ->assertTrue ($ bitmap ->isBitSet (2 ));
13
+ }
14
+
15
+ public function testSetBit ()
16
+ {
17
+ $ bitmap = new Bitmap ();
18
+
19
+ $ this ->assertEquals (8 , $ bitmap ->setBit (3 )->getInt ());
20
+ }
21
+
22
+ public function testSetBits ()
23
+ {
24
+ $ bitmap = new Bitmap ();
25
+
26
+ $ this ->assertEquals (10 , $ bitmap ->setBits (array (1 , 3 ))->getInt ());
27
+ }
28
+
29
+ public function testSetBitsByMask ()
30
+ {
31
+ $ bitmap = new Bitmap ();
32
+
33
+ $ this ->assertEquals (10 , $ bitmap ->setBitsByMask (10 )->getInt ());
34
+ }
35
+
36
+ public function testUnsetBit ()
37
+ {
38
+ $ bitmap = new Bitmap (5 );
39
+
40
+ $ this ->assertEquals (4 , $ bitmap ->unsetBit (0 )->getInt ());
41
+ }
42
+
43
+ public function testUnsetBits ()
44
+ {
45
+ $ bitmap = new Bitmap (5 );
46
+
47
+ $ this ->assertEquals (4 , $ bitmap ->unsetBits (array (0 , 1 ))->getInt ());
48
+ }
49
+
50
+ public function testUnsetBitsByMask ()
51
+ {
52
+ $ bitmap = new Bitmap (5 );
53
+
54
+ $ this ->assertEquals (1 , $ bitmap ->unsetBitsByMask (4 )->getInt ());
55
+ }
56
+
57
+ public function testInvert ()
58
+ {
59
+ $ bitmap = new Bitmap (5 );
60
+ $ bitmap ->invert ();
61
+
62
+ $ this ->assertEquals (-6 , $ bitmap ->getInt ());
63
+ }
64
+
65
+ public function testGetInt ()
66
+ {
67
+ $ bitmap = new Bitmap ();
68
+ $ bitmap ->setBit (0 );
69
+ $ bitmap ->setBit (2 );
70
+
71
+ $ this ->assertEquals (5 , $ bitmap ->getInt ());
72
+ }
73
+
74
+ public function testBitmap ()
75
+ {
76
+ $ bitmap = new Bitmap ();
77
+ $ bitmap ->setBit (0 );
78
+ $ bitmap ->setBit (2 );
79
+
80
+ $ this ->assertEquals ('101 ' , $ bitmap ->getBinary ());
81
+ }
82
+ }
0 commit comments