validate: Restructured autoAdjust code

- First approach indicates there is no general case. Instead identifiable and
  correctable use cases will be gathered. No solution yet.
This commit is contained in:
Paul Beckingham 2016-07-16 11:17:14 -04:00
parent 14ca159df4
commit 36455b5115
2 changed files with 39 additions and 36 deletions

View file

@ -98,47 +98,50 @@ static void autoAdjust (
Interval range_filter;
auto tracked = getTracked (database, rules, range_filter);
// Find all overlapping intervals.
std::vector <Interval> overlapping;
for (auto& track : tracked)
{
if (interval.range.overlap (track.range))
{
debug ("Input " + interval.dump ());
debug ("Overlaps with " + track.dump ());
overlapping.push_back (track);
if (! adjust)
throw std::string ("You cannot overlap intervals. Adjust the start/end "
"time, or specify the :adjust hint.");
// Diagnostics.
debug ("Input " + interval.dump ());
debug ("Overlaps with");
for (auto& overlap : overlapping)
debug (" " + overlap.dump ());
if (interval.range.start <= track.range.start)
{
// interval [--------)
// C [----)
//
// adjusted (dominate) C deleted
// adjusted (defer) interval split, C unmodified
// Overlaps are forbidden.
if (! adjust && overlapping.size ())
throw std::string ("You cannot overlap intervals. Correct the start/end "
"time, or specify the :adjust hint.");
// interval [--------)
// D [--------)
//
// adjusted (dominate) D modified
// adjusted (defer) interval modified
}
else
{
// interval [--------)
// B [--------)
//
// adjusted (dominate) B modified
// adjusted (defer) interval modified
// TODO Accumulate identifiable and correctable cases here.
// interval [--------)
// F [-------------)
//
// adjusted (dominate) F split
// adjusted (defer) interval deleted
}
}
}
// interval [--------)
// C [----)
//
// adjusted (dominate) C deleted
// adjusted (defer) interval split, C unmodified
// interval [--------)
// D [--------)
//
// adjusted (dominate) D modified
// adjusted (defer) interval modified
// interval [--------)
// B [--------)
//
// adjusted (dominate) B modified
// adjusted (defer) interval modified
// interval [--------)
// F [-------------)
//
// adjusted (dominate) F split
// adjusted (defer) interval deleted
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -116,7 +116,7 @@ class TestTrack(TestCase):
"""Test adding an overlapping interval fails"""
self.t("track 20160709T1400 - 20160709T1500 foo")
code, out, err = self.t.runError("track 20160709T1430 - 20160709T1530 foo")
self.assertIn('You cannot overlap intervals. Adjust the start/end time, or specify the :adjust hint.', err)
self.assertIn('You cannot overlap intervals. Correct the start/end time, or specify the :adjust hint.', err)
if __name__ == "__main__":
from simpletap import TAPTestRunner