1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/tests/internal/periods.py Sat May 14 18:46:04 2016 +0200
1.3 @@ -0,0 +1,102 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"""
1.7 +Test periods.
1.8 +
1.9 +Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
1.10 +
1.11 +This program is free software; you can redistribute it and/or modify it under
1.12 +the terms of the GNU General Public License as published by the Free Software
1.13 +Foundation; either version 3 of the License, or (at your option) any later
1.14 +version.
1.15 +
1.16 +This program is distributed in the hope that it will be useful, but WITHOUT
1.17 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.18 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.19 +details.
1.20 +
1.21 +You should have received a copy of the GNU General Public License along with
1.22 +this program. If not, see <http://www.gnu.org/licenses/>.
1.23 +"""
1.24 +
1.25 +from imiptools.dates import format_datetime
1.26 +from imiptools.period import Period, get_overlapping
1.27 +
1.28 +l1 = [
1.29 + Period("20160501T020000Z", "20160501T045000Z"),
1.30 + Period("20160501T023000Z", "20160501T030000Z"),
1.31 + Period("20160501T024500Z", "20160501T031500Z"),
1.32 + Period("20160501T040000Z", "20160501T043000Z"),
1.33 + Period("20160501T050000Z", "20160501T060000Z"),
1.34 + Period("20160501T051500Z", "20160501T054500Z"),
1.35 + Period("20160501T052000Z", "20160501T053000Z"),
1.36 + Period("20160501T090000Z", "20160501T093000Z"),
1.37 + Period("20160501T094000Z", "20160501T104000Z"),
1.38 + Period("20160501T100000Z", "20160501T110000Z"),
1.39 + ]
1.40 +
1.41 +l2 = [
1.42 + Period("20160501T010000Z", "20160501T020000Z"),
1.43 + Period("20160501T013000Z", "20160501T014000Z"),
1.44 + Period("20160501T014000Z", "20160501T015000Z"),
1.45 + Period("20160501T020000Z", "20160501T033000Z"),
1.46 + Period("20160501T040000Z", "20160501T044000Z"),
1.47 + Period("20160501T050000Z", "20160501T051000Z"),
1.48 + Period("20160501T052000Z", "20160501T053000Z"),
1.49 + Period("20160501T085900Z", "20160501T090000Z"),
1.50 + Period("20160501T085900Z", "20160501T090100Z"),
1.51 + Period("20160501T100000Z", "20160501T110000Z"),
1.52 + ]
1.53 +
1.54 +o1 = [
1.55 + Period("20160501T020000Z", "20160501T045000Z"),
1.56 + Period("20160501T023000Z", "20160501T030000Z"),
1.57 + Period("20160501T024500Z", "20160501T031500Z"),
1.58 + Period("20160501T040000Z", "20160501T043000Z"),
1.59 + Period("20160501T050000Z", "20160501T060000Z"),
1.60 + Period("20160501T051500Z", "20160501T054500Z"),
1.61 + Period("20160501T052000Z", "20160501T053000Z"),
1.62 + Period("20160501T090000Z", "20160501T093000Z"),
1.63 + Period("20160501T094000Z", "20160501T104000Z"),
1.64 + Period("20160501T100000Z", "20160501T110000Z"),
1.65 + ]
1.66 +
1.67 +o2 = [
1.68 + Period("20160501T020000Z", "20160501T033000Z"),
1.69 + Period("20160501T040000Z", "20160501T044000Z"),
1.70 + Period("20160501T050000Z", "20160501T051000Z"),
1.71 + Period("20160501T052000Z", "20160501T053000Z"),
1.72 + Period("20160501T085900Z", "20160501T090100Z"),
1.73 + Period("20160501T100000Z", "20160501T110000Z"),
1.74 + ]
1.75 +
1.76 +print o1 == get_overlapping(l1, l2)
1.77 +
1.78 +for p in get_overlapping(l1, l2):
1.79 + print format_datetime(p.get_start_point()), format_datetime(p.get_end_point())
1.80 +
1.81 +print "----"
1.82 +
1.83 +print o2 == get_overlapping(l2, l1)
1.84 +
1.85 +for p in get_overlapping(l2, l1):
1.86 + print format_datetime(p.get_start_point()), format_datetime(p.get_end_point())
1.87 +
1.88 +print "----"
1.89 +
1.90 +l1[0] = Period("20160501T020000Z", "20160501T120000Z")
1.91 +o1[0] = l1[0]
1.92 +print o1 == get_overlapping(l1, l2)
1.93 +
1.94 +for p in get_overlapping(l1, l2):
1.95 + print format_datetime(p.get_start_point()), format_datetime(p.get_end_point())
1.96 +
1.97 +print "----"
1.98 +
1.99 +o2 = l2[3:]
1.100 +print o2 == get_overlapping(l2, l1)
1.101 +
1.102 +for p in get_overlapping(l2, l1):
1.103 + print format_datetime(p.get_start_point()), format_datetime(p.get_end_point())
1.104 +
1.105 +# vim: tabstop=4 expandtab shiftwidth=4