‪TYPO3CMS  10.4
BitSetTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪BitSetTest extends UnitTestCase
27 {
31  public function ‪defaultBitSetOnlyHasZeroByteSet(): void
32  {
33  $bitSet = new ‪BitSet();
34  self::assertTrue($bitSet->get(0b0));
35  self::assertFalse($bitSet->get(0b1));
36  }
37 
41  public function ‪constructorSetsInternalSet(): void
42  {
43  $bitSet = new ‪BitSet(0b1 | 0b100);
44  self::assertTrue($bitSet->get(0b1));
45  self::assertTrue($bitSet->get(0b100));
46  self::assertFalse($bitSet->get(0b10));
47  }
48 
52  public function ‪setSetsBit(): void
53  {
54  $bitSet = new ‪BitSet(0b101);
55  self::assertTrue($bitSet->get(0b1));
56  self::assertTrue($bitSet->get(0b100));
57  self::assertFalse($bitSet->get(0b10));
58 
59  $bitSet->set(0b10);
60  self::assertTrue($bitSet->get(0b10));
61  }
62 
66  public function ‪setValueSetsBit(): void
67  {
68  $bitSet = new ‪BitSet();
69  self::assertFalse($bitSet->get(0b1));
70 
71  $bitSet->setValue(0b1, true);
72  self::assertTrue($bitSet->get(0b1));
73 
74  $bitSet->setValue(0b1, false);
75  self::assertFalse($bitSet->get(0b1));
76  }
77 
81  public function ‪clearUnsetsBit(): void
82  {
83  $bitSet = new ‪BitSet(0b111);
84  $bitSet->unset(0b10);
85  self::assertTrue($bitSet->get(0b1));
86  self::assertTrue($bitSet->get(0b100));
87  self::assertFalse($bitSet->get(0b10));
88  }
89 
93  public function ‪andPerformsABinaryAnd(): void
94  {
95  $bitSet = new ‪BitSet(0b101);
96  $bitSet->and(new ‪BitSet(0b111));
97 
98  // 0b101 & 0b111 === 0b101 ≙ 5
99  self::assertSame(5, $bitSet->__toInt());
100  self::assertSame('0b101', $bitSet->__toString());
101  }
102 
106  public function ‪orPerformsABinaryOr(): void
107  {
108  $bitSet = new ‪BitSet(0b101);
109  $bitSet->or(new ‪BitSet(0b011));
110 
111  // 0b101 | 0b011 === 0b111 ≙ 7
112  self::assertSame(7, $bitSet->__toInt());
113  self::assertSame('0b111', $bitSet->__toString());
114  }
115 
119  public function ‪xorPerformsABinaryXor(): void
120  {
121  $bitSet = new ‪BitSet(0b1001);
122  $bitSet->xor(new ‪BitSet(0b1010));
123 
124  // 0b1001 ^ 0b1010 === 0b11 ≙ 3
125  self::assertSame(3, $bitSet->__toInt());
126  self::assertSame('0b11', $bitSet->__toString());
127  }
128 
132  public function ‪andNotPerformsABinaryAndNot(): void
133  {
134  $bitSet = new ‪BitSet(0b111);
135  $bitSet->andNot(new ‪BitSet(0b101));
136 
137  // 0b111 & ~0b101 === 0b10 ≙ 2
138  self::assertSame(2, $bitSet->__toInt());
139  self::assertSame('0b10', $bitSet->__toString());
140  }
141 
146  {
147  $bitSet = new ‪BitSet(0b010);
148  self::assertSame(2, $bitSet->__toInt());
149  }
150 
155  {
156  $bitSet = new ‪BitSet(13);
157  self::assertSame('0b1101', $bitSet->__toString());
158  }
159 }
‪TYPO3\CMS\Core\Tests\Unit\Type\BitSetTest\xorPerformsABinaryXor
‪xorPerformsABinaryXor()
Definition: BitSetTest.php:119
‪TYPO3\CMS\Core\Tests\Unit\Type\BitSetTest\andPerformsABinaryAnd
‪andPerformsABinaryAnd()
Definition: BitSetTest.php:93
‪TYPO3\CMS\Core\Tests\Unit\Type\BitSetTest\__toIntReturnsIntegerRepresentationOfBitSet
‪__toIntReturnsIntegerRepresentationOfBitSet()
Definition: BitSetTest.php:145
‪TYPO3\CMS\Core\Tests\Unit\Type\BitSetTest\clearUnsetsBit
‪clearUnsetsBit()
Definition: BitSetTest.php:81
‪TYPO3\CMS\Core\Tests\Unit\Type\BitSetTest\constructorSetsInternalSet
‪constructorSetsInternalSet()
Definition: BitSetTest.php:41
‪TYPO3\CMS\Core\Type\BitSet
Definition: BitSet.php:62
‪TYPO3\CMS\Core\Tests\Unit\Type\BitSetTest\setSetsBit
‪setSetsBit()
Definition: BitSetTest.php:52
‪TYPO3\CMS\Core\Tests\Unit\Type\BitSetTest\setValueSetsBit
‪setValueSetsBit()
Definition: BitSetTest.php:66
‪TYPO3\CMS\Core\Tests\Unit\Type\BitSetTest\__toStringReturnsBinaryStringRepresentationOfBitSet
‪__toStringReturnsBinaryStringRepresentationOfBitSet()
Definition: BitSetTest.php:154
‪TYPO3\CMS\Core\Tests\Unit\Type
Definition: BitSetTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Type\BitSetTest\andNotPerformsABinaryAndNot
‪andNotPerformsABinaryAndNot()
Definition: BitSetTest.php:132
‪TYPO3\CMS\Core\Tests\Unit\Type\BitSetTest\orPerformsABinaryOr
‪orPerformsABinaryOr()
Definition: BitSetTest.php:106
‪TYPO3\CMS\Core\Tests\Unit\Type\BitSetTest
Definition: BitSetTest.php:27
‪TYPO3\CMS\Core\Tests\Unit\Type\BitSetTest\defaultBitSetOnlyHasZeroByteSet
‪defaultBitSetOnlyHasZeroByteSet()
Definition: BitSetTest.php:31