imip-agent

Annotated tests/internal/periods.py

1362:d96b4761e6f0
2017-10-24 Paul Boddie Remove superfluous result collection slicing and count method parameter.
paul@1189 1
#!/usr/bin/env python
paul@1189 2
paul@1189 3
"""
paul@1189 4
Test periods.
paul@1189 5
paul@1189 6
Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
paul@1189 7
paul@1189 8
This program is free software; you can redistribute it and/or modify it under
paul@1189 9
the terms of the GNU General Public License as published by the Free Software
paul@1189 10
Foundation; either version 3 of the License, or (at your option) any later
paul@1189 11
version.
paul@1189 12
paul@1189 13
This program is distributed in the hope that it will be useful, but WITHOUT
paul@1189 14
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
paul@1189 15
FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
paul@1189 16
details.
paul@1189 17
paul@1189 18
You should have received a copy of the GNU General Public License along with
paul@1189 19
this program.  If not, see <http://www.gnu.org/licenses/>.
paul@1189 20
"""
paul@1189 21
paul@1189 22
from imiptools.dates import format_datetime
paul@1189 23
from imiptools.period import Period, get_overlapping
paul@1189 24
paul@1189 25
l1 = [
paul@1189 26
    Period("20160501T020000Z", "20160501T045000Z"),
paul@1189 27
    Period("20160501T023000Z", "20160501T030000Z"),
paul@1189 28
    Period("20160501T024500Z", "20160501T031500Z"),
paul@1189 29
    Period("20160501T040000Z", "20160501T043000Z"),
paul@1189 30
    Period("20160501T050000Z", "20160501T060000Z"),
paul@1189 31
    Period("20160501T051500Z", "20160501T054500Z"),
paul@1189 32
    Period("20160501T052000Z", "20160501T053000Z"),
paul@1189 33
    Period("20160501T090000Z", "20160501T093000Z"),
paul@1189 34
    Period("20160501T094000Z", "20160501T104000Z"),
paul@1189 35
    Period("20160501T100000Z", "20160501T110000Z"),
paul@1189 36
    ]
paul@1189 37
paul@1189 38
l2 = [
paul@1189 39
    Period("20160501T010000Z", "20160501T020000Z"),
paul@1189 40
    Period("20160501T013000Z", "20160501T014000Z"),
paul@1189 41
    Period("20160501T014000Z", "20160501T015000Z"),
paul@1189 42
    Period("20160501T020000Z", "20160501T033000Z"),
paul@1189 43
    Period("20160501T040000Z", "20160501T044000Z"),
paul@1189 44
    Period("20160501T050000Z", "20160501T051000Z"),
paul@1189 45
    Period("20160501T052000Z", "20160501T053000Z"),
paul@1189 46
    Period("20160501T085900Z", "20160501T090000Z"),
paul@1189 47
    Period("20160501T085900Z", "20160501T090100Z"),
paul@1189 48
    Period("20160501T100000Z", "20160501T110000Z"),
paul@1189 49
    ]
paul@1189 50
paul@1189 51
o1 = [
paul@1189 52
    Period("20160501T020000Z", "20160501T045000Z"),
paul@1189 53
    Period("20160501T023000Z", "20160501T030000Z"),
paul@1189 54
    Period("20160501T024500Z", "20160501T031500Z"),
paul@1189 55
    Period("20160501T040000Z", "20160501T043000Z"),
paul@1189 56
    Period("20160501T050000Z", "20160501T060000Z"),
paul@1189 57
    Period("20160501T051500Z", "20160501T054500Z"),
paul@1189 58
    Period("20160501T052000Z", "20160501T053000Z"),
paul@1189 59
    Period("20160501T090000Z", "20160501T093000Z"),
paul@1189 60
    Period("20160501T094000Z", "20160501T104000Z"),
paul@1189 61
    Period("20160501T100000Z", "20160501T110000Z"),
paul@1189 62
    ]
paul@1189 63
paul@1189 64
o2 = [
paul@1189 65
    Period("20160501T020000Z", "20160501T033000Z"),
paul@1189 66
    Period("20160501T040000Z", "20160501T044000Z"),
paul@1189 67
    Period("20160501T050000Z", "20160501T051000Z"),
paul@1189 68
    Period("20160501T052000Z", "20160501T053000Z"),
paul@1189 69
    Period("20160501T085900Z", "20160501T090100Z"),
paul@1189 70
    Period("20160501T100000Z", "20160501T110000Z"),
paul@1189 71
    ]
paul@1189 72
paul@1189 73
print o1 == get_overlapping(l1, l2)
paul@1189 74
paul@1189 75
for p in get_overlapping(l1, l2):
paul@1189 76
    print format_datetime(p.get_start_point()), format_datetime(p.get_end_point())
paul@1189 77
paul@1189 78
print "----"
paul@1189 79
paul@1189 80
print o2 == get_overlapping(l2, l1)
paul@1189 81
paul@1189 82
for p in get_overlapping(l2, l1):
paul@1189 83
    print format_datetime(p.get_start_point()), format_datetime(p.get_end_point())
paul@1189 84
paul@1189 85
print "----"
paul@1189 86
paul@1189 87
l1[0] = Period("20160501T020000Z", "20160501T120000Z")
paul@1189 88
o1[0] = l1[0]
paul@1189 89
print o1 == get_overlapping(l1, l2)
paul@1189 90
paul@1189 91
for p in get_overlapping(l1, l2):
paul@1189 92
    print format_datetime(p.get_start_point()), format_datetime(p.get_end_point())
paul@1189 93
paul@1189 94
print "----"
paul@1189 95
paul@1189 96
o2 = l2[3:]
paul@1189 97
print o2 == get_overlapping(l2, l1)
paul@1189 98
paul@1189 99
for p in get_overlapping(l2, l1):
paul@1189 100
    print format_datetime(p.get_start_point()), format_datetime(p.get_end_point())
paul@1189 101
paul@1189 102
# vim: tabstop=4 expandtab shiftwidth=4