Missing tests
okorneliuk opened this issue · comments
Q | A |
---|---|
Version | 5.x.x |
Question
Where tests are gone in 5.x.x version? Methods unions()
and gaps()
of Sequence
are not working as expected! It can be easily caught by tests, but tests are missing!
@okorneliuk thanks for using the library. Can you be more precise ? What is not working ? Do you have a precise example ?
Without examples and tests script I am afraid I can not investigate your claims.
Please add more informations in your ticket
@nyamsprod Thanks you for your response.
Example:
<?php
$period1 = Period::fromDate('2022-01-01 00:00', '2022-01-01 00:10');
echo "Period 1:\n";
echo $period1->startDate->format('Y-m-d H:i') . ' - ' . $period1->endDate->format('Y-m-d H:i') . "\n";
$period2 = Period::fromDate('2022-01-01 00:10', '2022-01-01 00:20');
echo "Period 2:\n";
echo $period2->startDate->format('Y-m-d H:i') . ' - ' . $period2->endDate->format('Y-m-d H:i') . "\n";
$sequence = new Sequence($period1, $period2);
echo "Union (expected one united period) :\n";
foreach ($sequence->unions() as $period) {
echo $period->startDate->format('Y-m-d H:i') . ' - ' . $period->endDate->format('Y-m-d H:i') . "\n";
}
echo "Gaps (expected no gaps) :\n";
foreach ($sequence->gaps() as $period) {
echo $period->startDate->format('Y-m-d H:i') . ' - ' . $period->endDate->format('Y-m-d H:i') . "\n";
}
Output:
Period 1:
2022-01-01 00:00 - 2022-01-01 00:10
Period 2:
2022-01-01 00:10 - 2022-01-01 00:20
Union (expected one united period) :
2022-01-01 00:00 - 2022-01-01 00:10
2022-01-01 00:10 - 2022-01-01 00:20
Gaps (expected no gaps) :
2022-01-01 00:10 - 2022-01-01 00:10
@okorneliuk thanks for providing more informations. It may not be what you expect but the behaviour that you are experimenting is expected behaviour and is covered by tests and explain in the documentation.
A quick way to see why you get that behaviour is to use the Gant chart capabilities of the library:
use League\Period\Chart;
use League\Period\Period;
use League\Period\Sequence;
$period1 = Period::fromDate('2022-01-01 00:00', '2022-01-01 00:10');
$period2 = Period::fromDate('2022-01-01 00:10', '2022-01-01 00:20');
$sequence = new Sequence($period1, $period2);
$dataset = new Chart\Dataset([
['period1', $period1],
['period2', $period2],
['unions', $sequence->unions()],
['gaps', $sequence->gaps()],
]);
(new Chart\GanttChart())->stroke($dataset);
Which will output something like this in your terminal
period1 [----------------------------)
period2 [----------------------------)
unions [----------------------------)[----------------------------)
gaps )[
Please refer to the documentation for a full explanation.
@nyamsprod Thank you for the explanation 🙏 Now I got it. I should use Bounds::IncludeAll
to get the behavior I expect.