Skip to content

Commit

Permalink
Applied code review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwojs committed Dec 11, 2023
1 parent 92f2d75 commit 2f10844
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function __toString(): string

public function equalsTo(Range $value): bool
{
return $this->from === $value->from && $this->to === $value->to;
return $this->from == $value->from && $this->to == $value->to;
}

private function getRangeValueAsString($value): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function generate(): array
}

$values = range($this->start, $this->end, $this->step);
for ($i = 1; $i < count($values); ++$i) {
for ($i = 1, $count = count($values); $i < $count; ++$i) {
$ranges[] = Range::ofFloat($values[$i - 1], $values[$i]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function generate(): Generator
}

$values = range($this->start, $this->end, $this->step);
for ($i = 1; $i < count($values); ++$i) {
for ($i = 1, $count = count($values); $i < $count; ++$i) {
yield Range::ofInt($values[$i - 1], $values[$i]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,69 @@ public function testOfDateTime(): void
$this->assertEquals(new Range($a, $b), Range::ofDateTime($a, $b));
$this->assertEquals(new Range($a, null), Range::ofDateTime($a, null));
}

/**
* @dataProvider dataProviderForEqualsTo
*/
public function testEqualsTo(Range $rangeA, Range $rangeB, bool $expectedResult): void
{
self::assertEquals($expectedResult, $rangeA->equalsTo($rangeB));
self::assertEquals($expectedResult, $rangeB->equalsTo($rangeA));
}

/**
* @return iterable<string, array{Range, Range, bool}>
*/
public function dataProviderForEqualsTo(): iterable
{
yield 'int (true)' => [
Range::ofInt(1, 10),
Range::ofInt(1, 10),
true,
];

yield 'int (false)' => [
Range::ofInt(1, 10),
Range::ofInt(1, 100),
false,
];

yield 'float (true)' => [
Range::ofFloat(1.0, 10.0),
Range::ofFloat(1.0, 10.0),
true,
];

yield 'float (false)' => [
Range::ofFloat(1.0, 10.0),
Range::ofFloat(1.0, 100.0),
false,
];

yield 'data & time (true)' => [
Range::ofDateTime(
new DateTimeImmutable('2023-01-01 00:00:00'),
new DateTimeImmutable('2023-12-01 00:00:00')
),
Range::ofDateTime(
new DateTimeImmutable('2023-01-01 00:00:00'),
new DateTimeImmutable('2023-12-01 00:00:00')
),
true,
];

yield 'data & time (false)' => [
Range::ofDateTime(
new DateTimeImmutable('2023-01-01 00:00:00'),
new DateTimeImmutable('2023-12-01 00:00:00')
),
Range::ofDateTime(
new DateTimeImmutable('2024-01-01 00:00:00'),
new DateTimeImmutable('2024-12-01 00:00:00')
),
false,
];
}
}

class_alias(RangeTest::class, 'eZ\Publish\API\Repository\Tests\Values\Content\Query\Aggregation\RangeTest');

0 comments on commit 2f10844

Please sign in to comment.