From d8db8ecb24e4705db07c4a057179fb985caf8b73 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 17 Feb 2026 12:45:53 +0700 Subject: [PATCH 1/7] Fix no space or 1 on min vs max on Interval::isExclusiveOf() --- src/Interval.php | 5 ++++- tests/IntervalTest.php | 30 +++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/Interval.php b/src/Interval.php index 6a21aac..9da613a 100644 --- a/src/Interval.php +++ b/src/Interval.php @@ -5,6 +5,7 @@ namespace ArrayLookup; use ArrayLookup\Assert\Filter; +use InvalidArgumentException; use Traversable; use Webmozart\Assert\Assert; @@ -59,7 +60,9 @@ public static function isExclusiveOf( Filter::boolean($filter); if ($max - $min <= 1) { - return false; + throw new InvalidArgumentException( + 'The difference between min and max must be greater than 1 for an exclusive interval.' + ); } $totalFound = 0; diff --git a/tests/IntervalTest.php b/tests/IntervalTest.php index 85aaad2..640aa43 100644 --- a/tests/IntervalTest.php +++ b/tests/IntervalTest.php @@ -5,6 +5,7 @@ namespace ArrayLookup\Tests; use ArrayLookup\Interval; +use InvalidArgumentException; use Iterator; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; @@ -134,12 +135,39 @@ public static function exclusiveDataProvider(): Iterator 5, false, ]; + } + + /** + * @param int[] $data + */ + #[DataProvider('noSpaceExclusiveDataProvider')] + public function testNoSpaceInterval( + array $data, + callable $filter, + int $min, + int $max + ): void { + $this->expectException(InvalidArgumentException::class); + Interval::isExclusiveOf($data, $filter, $min, $max); + } + + /** + * @return Iterator + */ + public static function noSpaceExclusiveDataProvider(): Iterator + { + yield 'equal between bounds' => [ + [1, 2, 3], + static fn($datum): bool => $datum > 1, + 2, + 2, + ]; + yield 'no space between bounds' => [ [1, 2, 3], static fn($datum): bool => $datum > 1, 2, 3, - false, ]; } } From 7968f153f00c498cddc8cf7c9f833d0a847dea64 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 17 Feb 2026 12:48:11 +0700 Subject: [PATCH 2/7] trigger CI From 6c028e2000e7da3084305039ecd8b2e9429d5155 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 17 Feb 2026 12:49:32 +0700 Subject: [PATCH 3/7] update test name --- tests/IntervalTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/IntervalTest.php b/tests/IntervalTest.php index 640aa43..dc0fb63 100644 --- a/tests/IntervalTest.php +++ b/tests/IntervalTest.php @@ -141,7 +141,7 @@ public static function exclusiveDataProvider(): Iterator * @param int[] $data */ #[DataProvider('noSpaceExclusiveDataProvider')] - public function testNoSpaceInterval( + public function testNoSpaceIntervalIsExclusiveOf( array $data, callable $filter, int $min, From b87d1561190a02e88299c327b6734d96a03fa5e9 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 17 Feb 2026 12:51:48 +0700 Subject: [PATCH 4/7] add message --- tests/IntervalTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/IntervalTest.php b/tests/IntervalTest.php index dc0fb63..3b4492e 100644 --- a/tests/IntervalTest.php +++ b/tests/IntervalTest.php @@ -148,6 +148,8 @@ public function testNoSpaceIntervalIsExclusiveOf( int $max ): void { $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('The difference between min and max must be greater than 1 for an exclusive interval.'); + Interval::isExclusiveOf($data, $filter, $min, $max); } From f6ef6d01b114d6548b4457d4aaf5dc61e6a47094 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 17 Feb 2026 12:54:33 +0700 Subject: [PATCH 5/7] fix --- tests/IntervalTest.php | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/tests/IntervalTest.php b/tests/IntervalTest.php index 3b4492e..d754483 100644 --- a/tests/IntervalTest.php +++ b/tests/IntervalTest.php @@ -140,36 +140,16 @@ public static function exclusiveDataProvider(): Iterator /** * @param int[] $data */ - #[DataProvider('noSpaceExclusiveDataProvider')] - public function testNoSpaceIntervalIsExclusiveOf( - array $data, - callable $filter, - int $min, - int $max - ): void { + public function testNoSpaceIntervalIsExclusiveOf(): void + { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('The difference between min and max must be greater than 1 for an exclusive interval.'); - Interval::isExclusiveOf($data, $filter, $min, $max); - } - - /** - * @return Iterator - */ - public static function noSpaceExclusiveDataProvider(): Iterator - { - yield 'equal between bounds' => [ - [1, 2, 3], - static fn($datum): bool => $datum > 1, - 2, - 2, - ]; + $data = [1, 2, 3]; + $filter = static fn($datum): bool => $datum > 1; + $min = 2; + $max = 3; - yield 'no space between bounds' => [ - [1, 2, 3], - static fn($datum): bool => $datum > 1, - 2, - 3, - ]; + Interval::isExclusiveOf($data, $filter, $min, $max); } } From a07f9b2f2e5b43c4034f99e83e1c44921ced9f92 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 17 Feb 2026 12:55:12 +0700 Subject: [PATCH 6/7] fix cs --- tests/IntervalTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/IntervalTest.php b/tests/IntervalTest.php index d754483..f138b4e 100644 --- a/tests/IntervalTest.php +++ b/tests/IntervalTest.php @@ -145,10 +145,10 @@ public function testNoSpaceIntervalIsExclusiveOf(): void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('The difference between min and max must be greater than 1 for an exclusive interval.'); - $data = [1, 2, 3]; + $data = [1, 2, 3]; $filter = static fn($datum): bool => $datum > 1; - $min = 2; - $max = 3; + $min = 2; + $max = 3; Interval::isExclusiveOf($data, $filter, $min, $max); } From eca383d285cace97e773dc34d6eb60dcc77b5fc8 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 17 Feb 2026 12:57:21 +0700 Subject: [PATCH 7/7] fix cs --- tests/IntervalTest.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/IntervalTest.php b/tests/IntervalTest.php index f138b4e..2d8d79c 100644 --- a/tests/IntervalTest.php +++ b/tests/IntervalTest.php @@ -137,13 +137,12 @@ public static function exclusiveDataProvider(): Iterator ]; } - /** - * @param int[] $data - */ public function testNoSpaceIntervalIsExclusiveOf(): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('The difference between min and max must be greater than 1 for an exclusive interval.'); + $this->expectExceptionMessage( + 'The difference between min and max must be greater than 1 for an exclusive interval.' + ); $data = [1, 2, 3]; $filter = static fn($datum): bool => $datum > 1;