diff --git a/config/infection.json.dist b/config/infection.json.dist index bc6796ec..c2ee2166 100644 --- a/config/infection.json.dist +++ b/config/infection.json.dist @@ -21,6 +21,48 @@ } }, "timeout": 10, - "minMsi": 98, - "minCoveredMsi": 100 + "minMsi": 100, + "minCoveredMsi": 100, + "mutators": { + "@default": true, + "Break_": { + "ignore": [ + "Psl\\Collection\\*Map::zip" + ] + }, + "DecrementInteger": { + "ignore": [ + "Psl\\DataStructure\\PriorityQueue::peek" + ] + }, + "FunctionCallRemoval": { + "ignore": [ + "Psl\\Result\\Success::getThrowable" + ] + }, + "IncrementInteger": { + "ignore": [ + "Psl\\DataStructure\\PriorityQueue::peek" + ] + }, + "LogicalNot": { + "ignore": [ + "Psl\\Hash\\Context::update" + ] + }, + "MethodCallRemoval": { + "ignore": [ + "Psl\\Iter\\Iterator::seek", + "Psl\\Iter\\Iterator::count" + ] + }, + "Throw_": { + "ignore": [ + "Psl\\File\\ReadHandle::__construct", + "Psl\\File\\WriteHandle::__construct", + "Psl\\File\\ReadWriteHandle::__construct", + "Psl\\Hash\\Context::update" + ] + } + } } diff --git a/config/phpunit.xml.dist b/config/phpunit.xml.dist index 05d39d27..a34c1531 100644 --- a/config/phpunit.xml.dist +++ b/config/phpunit.xml.dist @@ -33,6 +33,7 @@ + diff --git a/src/Psl/Collection/MutableMap.php b/src/Psl/Collection/MutableMap.php index 56cd4eb1..3c67de07 100644 --- a/src/Psl/Collection/MutableMap.php +++ b/src/Psl/Collection/MutableMap.php @@ -247,7 +247,7 @@ public function get(string|int $k): mixed */ public function values(): MutableVector { - return MutableVector::fromArray(array_values($this->elements)); + return MutableVector::fromArray($this->elements); } /** diff --git a/tests/unit/Collection/AbstractMapTest.php b/tests/unit/Collection/AbstractMapTest.php index 28821e16..c08f9cce 100644 --- a/tests/unit/Collection/AbstractMapTest.php +++ b/tests/unit/Collection/AbstractMapTest.php @@ -373,6 +373,13 @@ public function testZip(): void static::assertCount(2, $zipped); static::assertSame(['hello', 'foo'], $zipped->at(1)); static::assertSame(['world', 'bar'], $zipped->at(2)); + + $map = $this->create([1 => 'hello', 2 => 'world']); + $zipped = $map->zip(['foo' => 'foo', 'bar' => 'bar']); + static::assertInstanceOf($this->mapClass, $zipped); + static::assertCount(2, $zipped); + static::assertSame(['hello', 'foo'], $zipped->at(1)); + static::assertSame(['world', 'bar'], $zipped->at(2)); } public function testTake(): void diff --git a/tests/unit/Collection/MapTest.php b/tests/unit/Collection/MapTest.php index 89966903..3cb5b2dc 100644 --- a/tests/unit/Collection/MapTest.php +++ b/tests/unit/Collection/MapTest.php @@ -29,6 +29,6 @@ final class MapTest extends AbstractMapTest */ protected function create(iterable $items): Map { - return new Map($items); + return Map::fromArray($items); } } diff --git a/tests/unit/Collection/MutableMapTest.php b/tests/unit/Collection/MutableMapTest.php index b5e82011..6896e8b7 100644 --- a/tests/unit/Collection/MutableMapTest.php +++ b/tests/unit/Collection/MutableMapTest.php @@ -152,6 +152,6 @@ public function testRemove(): void */ protected function create(iterable $items): MutableMap { - return new MutableMap($items); + return MutableMap::fromArray($items); } } diff --git a/tests/unit/DataStructure/PriorityQueueTest.php b/tests/unit/DataStructure/PriorityQueueTest.php index 9cd2e8bd..d22a87de 100644 --- a/tests/unit/DataStructure/PriorityQueueTest.php +++ b/tests/unit/DataStructure/PriorityQueueTest.php @@ -24,6 +24,24 @@ public function testEnqueueAndDequeue(): void static::assertSame('hi', $queue->dequeue()); } + public function testDefaultEnqueueSettings(): void + { + $queue = new DataStructure\PriorityQueue(); + $queue->enqueue('hey'); + $queue->enqueue('ho', 0); + $queue->enqueue('hi', -1); + $queue->enqueue('hello', 1); + + static::assertCount(4, $queue); + static::assertSame('hello', $queue->dequeue()); + static::assertCount(3, $queue); + static::assertSame('hey', $queue->dequeue()); + static::assertCount(2, $queue); + static::assertSame('ho', $queue->dequeue()); + static::assertCount(1, $queue); + static::assertSame('hi', $queue->dequeue()); + } + public function testMultipleNodesWithSamePriority(): void { $queue = new DataStructure\PriorityQueue(); diff --git a/tests/unit/File/ReadHandleTest.php b/tests/unit/File/ReadHandleTest.php index e918ad35..3941fe14 100644 --- a/tests/unit/File/ReadHandleTest.php +++ b/tests/unit/File/ReadHandleTest.php @@ -35,4 +35,13 @@ public function testNonExisting(): void $this->expectException(File\Exception\NotFoundException::class); File\open_read_only($temporary_file); } + + public function testNonFile(): void + { + $temporary_file = Filesystem\create_temporary_file(); + Filesystem\delete_file($temporary_file); + + $this->expectException(File\Exception\NotFileException::class); + File\open_read_only(dirname($temporary_file)); + } } diff --git a/tests/unit/Math/AcosTest.php b/tests/unit/Math/AcosTest.php index 1cc47180..ef194530 100644 --- a/tests/unit/Math/AcosTest.php +++ b/tests/unit/Math/AcosTest.php @@ -9,12 +9,14 @@ final class AcosTest extends TestCase { + use FloatAsserts; + /** * @dataProvider provideData */ public function testAcos(float $expected, float $number): void { - static::assertSame($expected, Math\acos($number)); + static::assertFloatEquals($expected, Math\acos($number)); } public function provideData(): array diff --git a/tests/unit/Math/AsinTest.php b/tests/unit/Math/AsinTest.php index 1ff32e7f..18f830cf 100644 --- a/tests/unit/Math/AsinTest.php +++ b/tests/unit/Math/AsinTest.php @@ -9,12 +9,14 @@ final class AsinTest extends TestCase { + use FloatAsserts; + /** * @dataProvider provideData */ public function testAsin(float $expected, float $number): void { - static::assertSame($expected, Math\asin($number)); + static::assertFloatEquals($expected, Math\asin($number)); } public function provideData(): array diff --git a/tests/unit/Math/Atan2Test.php b/tests/unit/Math/Atan2Test.php index 8b0c47fa..736b8541 100644 --- a/tests/unit/Math/Atan2Test.php +++ b/tests/unit/Math/Atan2Test.php @@ -9,12 +9,14 @@ final class Atan2Test extends TestCase { + use FloatAsserts; + /** * @dataProvider provideData */ public function testAtan2(float $expected, float $y, float $x): void { - static::assertSame($expected, Math\atan2($y, $x)); + static::assertFloatEquals($expected, Math\atan2($y, $x)); } public function provideData(): array diff --git a/tests/unit/Math/AtanTest.php b/tests/unit/Math/AtanTest.php index b41510e9..4d1bdaa5 100644 --- a/tests/unit/Math/AtanTest.php +++ b/tests/unit/Math/AtanTest.php @@ -9,12 +9,14 @@ final class AtanTest extends TestCase { + use FloatAsserts; + /** * @dataProvider provideData */ public function testAtan(float $expected, float $number): void { - static::assertSame($expected, Math\atan($number)); + static::assertFloatEquals($expected, Math\atan($number)); } public function provideData(): array diff --git a/tests/unit/Math/CosTest.php b/tests/unit/Math/CosTest.php index d43b4a10..5a37e952 100644 --- a/tests/unit/Math/CosTest.php +++ b/tests/unit/Math/CosTest.php @@ -9,12 +9,14 @@ final class CosTest extends TestCase { + use FloatAsserts; + /** * @dataProvider provideData */ public function testCos(float $expected, float $number): void { - static::assertSame($expected, Math\cos($number)); + static::assertFloatEquals($expected, Math\cos($number)); } public function provideData(): array diff --git a/tests/unit/Math/FloatAsserts.php b/tests/unit/Math/FloatAsserts.php new file mode 100644 index 00000000..99634946 --- /dev/null +++ b/tests/unit/Math/FloatAsserts.php @@ -0,0 +1,25 @@ +