packages/sql-parser/tests/Unit/Automaton/BitsetTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Automaton;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Small;
9use PHPUnit\Framework\TestCase;
10use SqlParser\Automaton\Bitset;
11
12#[CoversClass(Bitset::class)]
13#[Small]
14final class BitsetTest extends TestCase
15{
16 public function testEmpty(): void
17 {
18 self::assertSame([0, 0], Bitset::empty(33));
19 self::assertSame([0], Bitset::empty(32));
20 self::assertSame([], Bitset::empty(0));
21 }
22
23 public function testAdd(): void
24 {
25 $set = Bitset::empty(64);
26 Bitset::add($set, 3);
27 Bitset::add($set, 40);
28
29 self::assertSame([8, 256], $set);
30 }
31
32 public function testHas(): void
33 {
34 $set = Bitset::empty(64);
35 Bitset::add($set, 40);
36
37 self::assertTrue(Bitset::has($set, 40));
38 self::assertFalse(Bitset::has($set, 41));
39 }
40
41 public function testUnion(): void
42 {
43 $into = Bitset::empty(64);
44 $from = Bitset::empty(64);
45 Bitset::add($into, 1);
46 Bitset::add($from, 33);
47 Bitset::union($into, $from);
48
49 self::assertSame([1, 33], Bitset::members($into));
50 }
51
52 public function testMembers(): void
53 {
54 $set = Bitset::empty(70);
55 Bitset::add($set, 0);
56 Bitset::add($set, 31);
57 Bitset::add($set, 32);
58 Bitset::add($set, 69);
59
60 self::assertSame([0, 31, 32, 69], Bitset::members($set));
61 self::assertSame([], Bitset::members(Bitset::empty(8)));
62 }
63}
64