Skip to content

Commit 62e0b92

Browse files
authored
Merge pull request #40 from samsonasik/fix-no-space-interval-exclude
Fix no space or 1 on min vs max on Interval::isExclusiveOf()
2 parents b1c641c + eca383d commit 62e0b92

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

src/Interval.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace ArrayLookup;
66

77
use ArrayLookup\Assert\Filter;
8+
use InvalidArgumentException;
89
use Traversable;
910
use Webmozart\Assert\Assert;
1011

@@ -59,7 +60,9 @@ public static function isExclusiveOf(
5960
Filter::boolean($filter);
6061

6162
if ($max - $min <= 1) {
62-
return false;
63+
throw new InvalidArgumentException(
64+
'The difference between min and max must be greater than 1 for an exclusive interval.'
65+
);
6366
}
6467

6568
$totalFound = 0;

tests/IntervalTest.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace ArrayLookup\Tests;
66

77
use ArrayLookup\Interval;
8+
use InvalidArgumentException;
89
use Iterator;
910
use PHPUnit\Framework\Attributes\DataProvider;
1011
use PHPUnit\Framework\TestCase;
@@ -134,12 +135,20 @@ public static function exclusiveDataProvider(): Iterator
134135
5,
135136
false,
136137
];
137-
yield 'no space between bounds' => [
138-
[1, 2, 3],
139-
static fn($datum): bool => $datum > 1,
140-
2,
141-
3,
142-
false,
143-
];
138+
}
139+
140+
public function testNoSpaceIntervalIsExclusiveOf(): void
141+
{
142+
$this->expectException(InvalidArgumentException::class);
143+
$this->expectExceptionMessage(
144+
'The difference between min and max must be greater than 1 for an exclusive interval.'
145+
);
146+
147+
$data = [1, 2, 3];
148+
$filter = static fn($datum): bool => $datum > 1;
149+
$min = 2;
150+
$max = 3;
151+
152+
Interval::isExclusiveOf($data, $filter, $min, $max);
144153
}
145154
}

0 commit comments

Comments
 (0)