Merge two spans when they have non-empty intersection.

This commit is contained in:
Sergey Magidovich 2015-12-08 14:05:37 +03:00 committed by Sergey Yershov
parent d93962c547
commit 55a4c8f054
2 changed files with 9 additions and 16 deletions

View file

@ -48,7 +48,7 @@ UNIT_TEST(TestTimeTable_ExcludeTime)
tt.SetOpeningTime({8_h + 15_min, 18_h + 30_min});
TEST(tt.AddExcludeTime({10_h, 12_h}), ());
TEST(!tt.AddExcludeTime({11_h, 13_h}), ());
TEST(tt.AddExcludeTime({11_h, 13_h}), ());
TEST(tt.AddExcludeTime({15_h, 17_h}), ());
TEST_EQUAL(tt.GetExcludeTime().size(), 2, ());
}
@ -94,12 +94,6 @@ UNIT_TEST(TestTimeTable_ExcludeTime)
tt.SetOpeningTime({8_h + 15_min, 15_h + 30_min});
TEST(!tt.AddExcludeTime({10_h, 16_h}), ());
}
{
auto tt = TimeTable::GetPredefinedTimeTable();
tt.SetTwentyFourHours(false);
tt.SetOpeningTime({8_h + 15_min, 15_h + 30_min});
TEST(!tt.AddExcludeTime({7_h, 14_h}), ());
}
{
@ -111,8 +105,12 @@ UNIT_TEST(TestTimeTable_ExcludeTime)
TEST(tt.AddExcludeTime({12_h, 13_h}), ());
TEST(tt.AddExcludeTime({15_h, 17_h}), ());
TEST(tt.ReplaceExcludeTime({13_h, 14_h}, 1), ());
TEST(!tt.ReplaceExcludeTime({10_h + 30_min, 14_h}, 1), ());
TEST_EQUAL(tt.GetExcludeTime().size(), 3, ());
TEST(tt.ReplaceExcludeTime({10_h + 30_min, 14_h}, 1), ());
TEST_EQUAL(tt.GetExcludeTime().size(), 2, ());
TEST_EQUAL(tt.GetExcludeTime()[0].GetStart().GetHourMinutes().GetHoursCount(), 10, ());
TEST_EQUAL(tt.GetExcludeTime()[0].GetEnd().GetHourMinutes().GetHoursCount(), 14, ());
TEST_EQUAL(tt.GetExcludeTime()[1].GetStart().GetHourMinutes().GetHoursCount(), 15, ());
TEST_EQUAL(tt.GetExcludeTime()[1].GetEnd().GetHourMinutes().GetHoursCount(), 17, ());
}
{
auto tt = TimeTable::GetPredefinedTimeTable();

View file

@ -43,7 +43,7 @@ bool FixTimeSpans(osmoh::TTimespans & spans, osmoh::Timespan const & openingTime
for (auto i = 1, j = 0; i < spans.size(); ++i)
{
auto const start2 = spans[i].GetStart().GetHourMinutes().GetDuration();
auto const end1 = spans[i - 1].GetEnd().GetHourMinutes().GetDuration();
auto const end1 = spans[j].GetEnd().GetHourMinutes().GetDuration();
auto const end2 = spans[i].GetEnd().GetHourMinutes().GetDuration();
// The first one includes the second.
@ -52,12 +52,7 @@ bool FixTimeSpans(osmoh::TTimespans & spans, osmoh::Timespan const & openingTime
continue;
}
// Two spans have non-empty intersection.
else if (start2 < end1)
{
return false;
}
// The second span continue the first one.
else if(start2 == end1)
else if (start2 <= end1)
{
result.back().SetEnd(spans[i].GetEnd());
}