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

View file

@ -116,7 +116,7 @@ class TestTrack(TestCase):
"""Test adding an overlapping interval fails""" """Test adding an overlapping interval fails"""
self.t("track 20160709T1400 - 20160709T1500 foo") self.t("track 20160709T1400 - 20160709T1500 foo")
code, out, err = self.t.runError("track 20160709T1430 - 20160709T1530 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__": if __name__ == "__main__":
from simpletap import TAPTestRunner from simpletap import TAPTestRunner