Skip to content

Commit caae97c

Browse files
authored
Ensure bitset can handle single entries (#9)
1 parent b3db9a3 commit caae97c

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Util/BitSet.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function toBinaryString(): string
9797
$words = [];
9898

9999
// ensure all slots between 0 and maxKey have a value
100-
$maxKey = max(...array_keys($this->words));
100+
$maxKey = max(0, ...array_keys($this->words));
101101
for ($i = 0; $i <= $maxKey; $i++) {
102102
$words[$i] = $this->words[$i] ?? 0;
103103
}

tests/Unit/Util/BitSetTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,17 @@ public function testSerializeBinaryString(): void
142142
static::assertEquals($bitSet, $newBitSet);
143143
}
144144

145+
public function testSerializeBinaryStringSingleEntry(): void
146+
{
147+
$bitSet = new BitSet();
148+
$bitSet->set(5, 6);
149+
150+
$binaryString = $bitSet->toBinaryString();
151+
$newBitSet = BitSet::fromBinaryString($binaryString);
152+
153+
static::assertEquals($bitSet, $newBitSet);
154+
}
155+
145156
public function testSerializeBinaryStringEmptyBitSet(): void
146157
{
147158
$bitSet = new BitSet();

0 commit comments

Comments
 (0)