refactored tests to make results more useful
This commit is contained in:
parent
51bcf5f75c
commit
91a5545c73
1 changed files with 103 additions and 88 deletions
|
@ -59,9 +59,7 @@ class IntegerRangeTest extends TestCase
|
||||||
public function testEquals()
|
public function testEquals()
|
||||||
{
|
{
|
||||||
// fully bounded
|
// fully bounded
|
||||||
$this->checkScenarioResults(
|
$this->assertEquals(
|
||||||
new IntegerRange(10, 20),
|
|
||||||
'equals',
|
|
||||||
[
|
[
|
||||||
'same' => true,
|
'same' => true,
|
||||||
'unbounded' => false,
|
'unbounded' => false,
|
||||||
|
@ -89,12 +87,14 @@ class IntegerRangeTest extends TestCase
|
||||||
'containing same end' => false,
|
'containing same end' => false,
|
||||||
'containing same start unbounded end' => false,
|
'containing same start unbounded end' => false,
|
||||||
'containing same end unbounded start' => false,
|
'containing same end unbounded start' => false,
|
||||||
]
|
],
|
||||||
|
$this->scenarioResults(
|
||||||
|
new IntegerRange(10, 20),
|
||||||
|
'equals',
|
||||||
|
)
|
||||||
);
|
);
|
||||||
// open start
|
// open start
|
||||||
$this->checkScenarioResults(
|
$this->assertEquals(
|
||||||
new IntegerRange(null, 20),
|
|
||||||
'equals',
|
|
||||||
[
|
[
|
||||||
'same' => true,
|
'same' => true,
|
||||||
'unbounded' => false,
|
'unbounded' => false,
|
||||||
|
@ -111,12 +111,14 @@ class IntegerRangeTest extends TestCase
|
||||||
'adjacent bounded end' => false,
|
'adjacent bounded end' => false,
|
||||||
'disjoint open end' => false,
|
'disjoint open end' => false,
|
||||||
'disjoint bounded end' => false,
|
'disjoint bounded end' => false,
|
||||||
]
|
],
|
||||||
|
$this->scenarioResults(
|
||||||
|
new IntegerRange(null, 20),
|
||||||
|
'equals',
|
||||||
|
)
|
||||||
);
|
);
|
||||||
// open end
|
// open end
|
||||||
$this->checkScenarioResults(
|
$this->assertEquals(
|
||||||
new IntegerRange(10, null),
|
|
||||||
'equals',
|
|
||||||
[
|
[
|
||||||
'same' => true,
|
'same' => true,
|
||||||
'unbounded' => false,
|
'unbounded' => false,
|
||||||
|
@ -133,27 +135,31 @@ class IntegerRangeTest extends TestCase
|
||||||
'adjacent bounded start' => false,
|
'adjacent bounded start' => false,
|
||||||
'disjoint open start' => false,
|
'disjoint open start' => false,
|
||||||
'disjoint bounded start' => false,
|
'disjoint bounded start' => false,
|
||||||
]
|
],
|
||||||
|
$this->scenarioResults(
|
||||||
|
new IntegerRange(10, null),
|
||||||
|
'equals',
|
||||||
|
)
|
||||||
);
|
);
|
||||||
// fully unbounded
|
// fully unbounded
|
||||||
$this->checkScenarioResults(
|
$this->assertEquals(
|
||||||
new IntegerRange(null, null),
|
|
||||||
'equals',
|
|
||||||
[
|
[
|
||||||
'same' => true,
|
'same' => true,
|
||||||
'open start' => false,
|
'open start' => false,
|
||||||
'open end' => false,
|
'open end' => false,
|
||||||
'bounded' => false,
|
'bounded' => false,
|
||||||
]
|
],
|
||||||
|
$this->scenarioResults(
|
||||||
|
new IntegerRange(null, null),
|
||||||
|
'equals',
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIntersects()
|
public function testIntersects()
|
||||||
{
|
{
|
||||||
// fully bounded
|
// fully bounded
|
||||||
$this->checkScenarioResults(
|
$this->assertEquals(
|
||||||
new IntegerRange(10, 20),
|
|
||||||
'intersects',
|
|
||||||
[
|
[
|
||||||
'same' => true,
|
'same' => true,
|
||||||
'unbounded' => true,
|
'unbounded' => true,
|
||||||
|
@ -181,12 +187,14 @@ class IntegerRangeTest extends TestCase
|
||||||
'containing same end' => true,
|
'containing same end' => true,
|
||||||
'containing same start unbounded end' => true,
|
'containing same start unbounded end' => true,
|
||||||
'containing same end unbounded start' => true,
|
'containing same end unbounded start' => true,
|
||||||
]
|
],
|
||||||
|
$this->scenarioResults(
|
||||||
|
new IntegerRange(10, 20),
|
||||||
|
'intersects',
|
||||||
|
)
|
||||||
);
|
);
|
||||||
// open start
|
// open start
|
||||||
$this->checkScenarioResults(
|
$this->assertEquals(
|
||||||
new IntegerRange(null, 20),
|
|
||||||
'intersects',
|
|
||||||
[
|
[
|
||||||
'same' => true,
|
'same' => true,
|
||||||
'unbounded' => true,
|
'unbounded' => true,
|
||||||
|
@ -203,12 +211,14 @@ class IntegerRangeTest extends TestCase
|
||||||
'adjacent bounded end' => false,
|
'adjacent bounded end' => false,
|
||||||
'disjoint open end' => false,
|
'disjoint open end' => false,
|
||||||
'disjoint bounded end' => false,
|
'disjoint bounded end' => false,
|
||||||
]
|
],
|
||||||
|
$this->scenarioResults(
|
||||||
|
new IntegerRange(null, 20),
|
||||||
|
'intersects',
|
||||||
|
)
|
||||||
);
|
);
|
||||||
// open end
|
// open end
|
||||||
$this->checkScenarioResults(
|
$this->assertEquals(
|
||||||
new IntegerRange(10, null),
|
|
||||||
'intersects',
|
|
||||||
[
|
[
|
||||||
'same' => true,
|
'same' => true,
|
||||||
'unbounded' => true,
|
'unbounded' => true,
|
||||||
|
@ -225,27 +235,31 @@ class IntegerRangeTest extends TestCase
|
||||||
'adjacent bounded start' => false,
|
'adjacent bounded start' => false,
|
||||||
'disjoint open start' => false,
|
'disjoint open start' => false,
|
||||||
'disjoint bounded start' => false,
|
'disjoint bounded start' => false,
|
||||||
]
|
],
|
||||||
|
$this->scenarioResults(
|
||||||
|
new IntegerRange(10, null),
|
||||||
|
'intersects',
|
||||||
|
)
|
||||||
);
|
);
|
||||||
// fully unbounded
|
// fully unbounded
|
||||||
$this->checkScenarioResults(
|
$this->assertEquals(
|
||||||
new IntegerRange(null, null),
|
|
||||||
'intersects',
|
|
||||||
[
|
[
|
||||||
'same' => true,
|
'same' => true,
|
||||||
'open start' => true,
|
'open start' => true,
|
||||||
'open end' => true,
|
'open end' => true,
|
||||||
'bounded' => true,
|
'bounded' => true,
|
||||||
]
|
],
|
||||||
|
$this->scenarioResults(
|
||||||
|
new IntegerRange(null, null),
|
||||||
|
'intersects',
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testContains()
|
public function testContains()
|
||||||
{
|
{
|
||||||
// fully bounded
|
// fully bounded
|
||||||
$this->checkScenarioResults(
|
$this->assertEquals(
|
||||||
new IntegerRange(10, 20),
|
|
||||||
'contains',
|
|
||||||
[
|
[
|
||||||
'same' => true,
|
'same' => true,
|
||||||
'unbounded' => false,
|
'unbounded' => false,
|
||||||
|
@ -273,12 +287,14 @@ class IntegerRangeTest extends TestCase
|
||||||
'containing same end' => false,
|
'containing same end' => false,
|
||||||
'containing same start unbounded end' => false,
|
'containing same start unbounded end' => false,
|
||||||
'containing same end unbounded start' => false,
|
'containing same end unbounded start' => false,
|
||||||
]
|
],
|
||||||
|
$this->scenarioResults(
|
||||||
|
new IntegerRange(10, 20),
|
||||||
|
'contains',
|
||||||
|
)
|
||||||
);
|
);
|
||||||
// open start
|
// open start
|
||||||
$this->checkScenarioResults(
|
$this->assertEquals(
|
||||||
new IntegerRange(null, 20),
|
|
||||||
'contains',
|
|
||||||
[
|
[
|
||||||
'same' => true,
|
'same' => true,
|
||||||
'unbounded' => false,
|
'unbounded' => false,
|
||||||
|
@ -295,12 +311,14 @@ class IntegerRangeTest extends TestCase
|
||||||
'adjacent bounded end' => false,
|
'adjacent bounded end' => false,
|
||||||
'disjoint open end' => false,
|
'disjoint open end' => false,
|
||||||
'disjoint bounded end' => false,
|
'disjoint bounded end' => false,
|
||||||
]
|
],
|
||||||
|
$this->scenarioResults(
|
||||||
|
new IntegerRange(null, 20),
|
||||||
|
'contains',
|
||||||
|
)
|
||||||
);
|
);
|
||||||
// open end
|
// open end
|
||||||
$this->checkScenarioResults(
|
$this->assertEquals(
|
||||||
new IntegerRange(10, null),
|
|
||||||
'contains',
|
|
||||||
[
|
[
|
||||||
'same' => true,
|
'same' => true,
|
||||||
'unbounded' => false,
|
'unbounded' => false,
|
||||||
|
@ -317,18 +335,24 @@ class IntegerRangeTest extends TestCase
|
||||||
'adjacent bounded start' => false,
|
'adjacent bounded start' => false,
|
||||||
'disjoint open start' => false,
|
'disjoint open start' => false,
|
||||||
'disjoint bounded start' => false,
|
'disjoint bounded start' => false,
|
||||||
]
|
],
|
||||||
|
$this->scenarioResults(
|
||||||
|
new IntegerRange(10, null),
|
||||||
|
'contains',
|
||||||
|
)
|
||||||
);
|
);
|
||||||
// fully unbounded
|
// fully unbounded
|
||||||
$this->checkScenarioResults(
|
$this->assertEquals(
|
||||||
new IntegerRange(null, null),
|
|
||||||
'contains',
|
|
||||||
[
|
[
|
||||||
'same' => true,
|
'same' => true,
|
||||||
'open start' => true,
|
'open start' => true,
|
||||||
'open end' => true,
|
'open end' => true,
|
||||||
'bounded' => true,
|
'bounded' => true,
|
||||||
]
|
],
|
||||||
|
$this->scenarioResults(
|
||||||
|
new IntegerRange(null, null),
|
||||||
|
'contains',
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,9 +363,7 @@ class IntegerRangeTest extends TestCase
|
||||||
public function testAbutsStartOf()
|
public function testAbutsStartOf()
|
||||||
{
|
{
|
||||||
// fully bounded
|
// fully bounded
|
||||||
$this->checkScenarioResults(
|
$this->assertEquals(
|
||||||
new IntegerRange(10, 20),
|
|
||||||
'abutsStartOf',
|
|
||||||
[
|
[
|
||||||
'same' => false,
|
'same' => false,
|
||||||
'unbounded' => false,
|
'unbounded' => false,
|
||||||
|
@ -369,12 +391,14 @@ class IntegerRangeTest extends TestCase
|
||||||
'containing same end' => false,
|
'containing same end' => false,
|
||||||
'containing same start unbounded end' => false,
|
'containing same start unbounded end' => false,
|
||||||
'containing same end unbounded start' => false,
|
'containing same end unbounded start' => false,
|
||||||
]
|
],
|
||||||
|
$this->scenarioResults(
|
||||||
|
new IntegerRange(10, 20),
|
||||||
|
'abutsStartOf',
|
||||||
|
)
|
||||||
);
|
);
|
||||||
// open start
|
// open start
|
||||||
$this->checkScenarioResults(
|
$this->assertEquals(
|
||||||
new IntegerRange(null, 20),
|
|
||||||
'abutsStartOf',
|
|
||||||
[
|
[
|
||||||
'same' => false,
|
'same' => false,
|
||||||
'unbounded' => false,
|
'unbounded' => false,
|
||||||
|
@ -391,12 +415,14 @@ class IntegerRangeTest extends TestCase
|
||||||
'adjacent bounded end' => true,
|
'adjacent bounded end' => true,
|
||||||
'disjoint open end' => false,
|
'disjoint open end' => false,
|
||||||
'disjoint bounded end' => false,
|
'disjoint bounded end' => false,
|
||||||
]
|
],
|
||||||
|
$this->scenarioResults(
|
||||||
|
new IntegerRange(null, 20),
|
||||||
|
'abutsStartOf',
|
||||||
|
)
|
||||||
);
|
);
|
||||||
// open end
|
// open end
|
||||||
$this->checkScenarioResults(
|
$this->assertEquals(
|
||||||
new IntegerRange(10, null),
|
|
||||||
'abutsStartOf',
|
|
||||||
[
|
[
|
||||||
'same' => false,
|
'same' => false,
|
||||||
'unbounded' => false,
|
'unbounded' => false,
|
||||||
|
@ -413,18 +439,24 @@ class IntegerRangeTest extends TestCase
|
||||||
'adjacent bounded start' => false,
|
'adjacent bounded start' => false,
|
||||||
'disjoint open start' => false,
|
'disjoint open start' => false,
|
||||||
'disjoint bounded start' => false,
|
'disjoint bounded start' => false,
|
||||||
]
|
],
|
||||||
|
$this->scenarioResults(
|
||||||
|
new IntegerRange(10, null),
|
||||||
|
'abutsStartOf',
|
||||||
|
)
|
||||||
);
|
);
|
||||||
// fully unbounded
|
// fully unbounded
|
||||||
$this->checkScenarioResults(
|
$this->assertEquals(
|
||||||
new IntegerRange(null, null),
|
|
||||||
'abutsStartOf',
|
|
||||||
[
|
[
|
||||||
'same' => false,
|
'same' => false,
|
||||||
'open start' => false,
|
'open start' => false,
|
||||||
'open end' => false,
|
'open end' => false,
|
||||||
'bounded' => false,
|
'bounded' => false,
|
||||||
]
|
],
|
||||||
|
$this->scenarioResults(
|
||||||
|
new IntegerRange(null, null),
|
||||||
|
'abutsStartOf',
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -509,30 +541,13 @@ class IntegerRangeTest extends TestCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function checkScenarioResults(IntegerRange $range, string $method, array $expected_results)
|
protected function scenarioResults(IntegerRange $range, string $method): array
|
||||||
{
|
{
|
||||||
$scenarios = $this->createScenarios($range);
|
return array_map(
|
||||||
foreach ($scenarios as $scenario => $other) {
|
function ($s) use ($range, $method) {
|
||||||
$result = $range->$method($other);
|
return $range->$method($s);
|
||||||
if (!isset($expected_results[$scenario])) {
|
},
|
||||||
throw new Exception("No expected result for scenario '$scenario'");
|
$this->createScenarios($range)
|
||||||
}
|
);
|
||||||
$expected = $expected_results[$scenario];
|
|
||||||
unset($expected_results[$scenario]);
|
|
||||||
$this->assertEquals($expected, $result, sprintf(
|
|
||||||
"[%s,%s] %s [%s,%s] expected %s but returned %s (scenario %s)",
|
|
||||||
$range->start() ?? '-INF',
|
|
||||||
$range->end() ?? 'INF',
|
|
||||||
$method,
|
|
||||||
$other->start() ?? '-INF',
|
|
||||||
$other->end() ?? 'INF',
|
|
||||||
$expected ? 'true' : 'false',
|
|
||||||
$result ? 'true' : 'false',
|
|
||||||
$scenario
|
|
||||||
));
|
|
||||||
}
|
|
||||||
if (count($expected_results) > 0) {
|
|
||||||
throw new Exception("Expected results not used: " . implode(', ', array_keys($expected_results)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue