Example #1
0
    def test_construction(self):
        # Construct with the right parameters.
        interval1 = Interval(fromIsoString("20150825T120000"),
                             fromIsoString("20150825T160000"))
        self.assertEqual(toIsoString(interval1.getStartTime()), "20150825T120000")
        self.assertEqual(toIsoString(interval1.getEndTime()), "20150825T160000")
        self.assertTrue(interval1.isValid())

        # Construct with the invalid interval.
        interval2 = Interval()
        self.assertTrue(not interval2.isValid())

        # Construct with the empty interval.
        interval3 = Interval(True)
        self.assertTrue(interval3.isValid())
        self.assertTrue(interval3.isEmpty())
Example #2
0
    def test_construction(self):
        # Construct with the right parameters.
        interval1 = Interval(fromIsoString("20150825T120000"),
                             fromIsoString("20150825T160000"))
        self.assertEqual(toIsoString(interval1.getStartTime()), "20150825T120000")
        self.assertEqual(toIsoString(interval1.getEndTime()), "20150825T160000")
        self.assertTrue(interval1.isValid())

        # Construct with the invalid interval.
        interval2 = Interval()
        self.assertTrue(not interval2.isValid())

        # Construct with the empty interval.
        interval3 = Interval(True)
        self.assertTrue(interval3.isValid())
        self.assertTrue(interval3.isEmpty())
Example #3
0
    def test_intersection_and_union(self):
        interval1 = Interval(fromIsoString("20150825T030000"),
                             fromIsoString("20150825T050000"))
        # No intersection.
        interval2 = Interval(fromIsoString("20150825T050000"),
                             fromIsoString("20150825T070000"))
        # No intersection.
        interval3 = Interval(fromIsoString("20150825T060000"),
                             fromIsoString("20150825T070000"))
        # There's an intersection.
        interval4 = Interval(fromIsoString("20150825T010000"),
                             fromIsoString("20150825T040000"))
        # Right in interval1, there's an intersection.
        interval5 = Interval(fromIsoString("20150825T030000"),
                             fromIsoString("20150825T040000"))
        # Wrap interval1, there's an intersection.
        interval6 = Interval(fromIsoString("20150825T010000"),
                             fromIsoString("20150825T050000"))
        # Empty interval.
        interval7 = Interval(True)

        tempInterval = Interval(interval1)
        tempInterval.intersectWith(interval2)
        self.assertTrue(tempInterval.isEmpty())

        tempInterval = Interval(interval1)
        gotError = True
        try:
            tempInterval.unionWith(interval2)
            gotError = False
        except:
            pass
        if not gotError:
            self.fail("Expected error in unionWith(interval2)")

        tempInterval = Interval(interval1)
        tempInterval.intersectWith(interval3)
        self.assertTrue(tempInterval.isEmpty())

        tempInterval = Interval(interval1)
        gotError = True
        try:
            tempInterval.unionWith(interval3)
            gotError = False
        except:
            pass
        if not gotError:
            self.fail("Expected error in unionWith(interval3)")

        tempInterval = Interval(interval1)
        tempInterval.intersectWith(interval4)
        self.assertTrue(not tempInterval.isEmpty())
        self.assertEqual(toIsoString(tempInterval.getStartTime()),
                         "20150825T030000")
        self.assertEqual(toIsoString(tempInterval.getEndTime()),
                         "20150825T040000")

        tempInterval = Interval(interval1)
        tempInterval.unionWith(interval4)
        self.assertTrue(not tempInterval.isEmpty())
        self.assertEqual(toIsoString(tempInterval.getStartTime()),
                         "20150825T010000")
        self.assertEqual(toIsoString(tempInterval.getEndTime()),
                         "20150825T050000")

        tempInterval = Interval(interval1)
        tempInterval.intersectWith(interval5)
        self.assertTrue(not tempInterval.isEmpty())
        self.assertEqual(toIsoString(tempInterval.getStartTime()),
                         "20150825T030000")
        self.assertEqual(toIsoString(tempInterval.getEndTime()),
                         "20150825T040000")

        tempInterval = Interval(interval1)
        tempInterval.unionWith(interval5)
        self.assertTrue(not tempInterval.isEmpty())
        self.assertEqual(toIsoString(tempInterval.getStartTime()),
                         "20150825T030000")
        self.assertEqual(toIsoString(tempInterval.getEndTime()),
                         "20150825T050000")

        tempInterval = Interval(interval1)
        tempInterval.intersectWith(interval6)
        self.assertTrue(not tempInterval.isEmpty())
        self.assertEqual(toIsoString(tempInterval.getStartTime()),
                         "20150825T030000")
        self.assertEqual(toIsoString(tempInterval.getEndTime()),
                         "20150825T050000")

        tempInterval = Interval(interval1)
        tempInterval.unionWith(interval6)
        self.assertTrue(not tempInterval.isEmpty())
        self.assertEqual(toIsoString(tempInterval.getStartTime()),
                         "20150825T010000")
        self.assertEqual(toIsoString(tempInterval.getEndTime()),
                         "20150825T050000")

        tempInterval = Interval(interval1)
        tempInterval.intersectWith(interval7)
        self.assertTrue(tempInterval.isEmpty())

        tempInterval = Interval(interval1)
        tempInterval.unionWith(interval7)
        self.assertTrue(not tempInterval.isEmpty())
        self.assertEqual(toIsoString(tempInterval.getStartTime()),
                         "20150825T030000")
        self.assertEqual(toIsoString(tempInterval.getEndTime()),
                         "20150825T050000")
Example #4
0
    def test_intersection_and_union(self):
        interval1 = Interval(fromIsoString("20150825T030000"),
                             fromIsoString("20150825T050000"))
        # No intersection.
        interval2 = Interval(fromIsoString("20150825T050000"),
                             fromIsoString("20150825T070000"))
        # No intersection.
        interval3 = Interval(fromIsoString("20150825T060000"),
                             fromIsoString("20150825T070000"))
        # There's an intersection.
        interval4 = Interval(fromIsoString("20150825T010000"),
                             fromIsoString("20150825T040000"))
        # Right in interval1, there's an intersection.
        interval5 = Interval(fromIsoString("20150825T030000"),
                             fromIsoString("20150825T040000"))
        # Wrap interval1, there's an intersection.
        interval6 = Interval(fromIsoString("20150825T010000"),
                             fromIsoString("20150825T050000"))
        # Empty interval.
        interval7 = Interval(True)

        tempInterval = Interval(interval1)
        tempInterval.intersectWith(interval2)
        self.assertTrue(tempInterval.isEmpty())

        tempInterval = Interval(interval1)
        gotError = True
        try:
            tempInterval.unionWith(interval2)
            gotError = False
        except:
            pass
        if not gotError:
          self.fail("Expected error in unionWith(interval2)")

        tempInterval = Interval(interval1)
        tempInterval.intersectWith(interval3)
        self.assertTrue(tempInterval.isEmpty())

        tempInterval = Interval(interval1)
        gotError = True
        try:
          tempInterval.unionWith(interval3)
          gotError = False
        except:
            pass
        if not gotError:
          self.fail("Expected error in unionWith(interval3)")

        tempInterval = Interval(interval1)
        tempInterval.intersectWith(interval4)
        self.assertTrue(not tempInterval.isEmpty())
        self.assertEqual(toIsoString(tempInterval.getStartTime()), "20150825T030000")
        self.assertEqual(toIsoString(tempInterval.getEndTime()), "20150825T040000")

        tempInterval = Interval(interval1)
        tempInterval.unionWith(interval4)
        self.assertTrue(not tempInterval.isEmpty())
        self.assertEqual(toIsoString(tempInterval.getStartTime()), "20150825T010000")
        self.assertEqual(toIsoString(tempInterval.getEndTime()), "20150825T050000")

        tempInterval = Interval(interval1)
        tempInterval.intersectWith(interval5)
        self.assertTrue(not tempInterval.isEmpty())
        self.assertEqual(toIsoString(tempInterval.getStartTime()), "20150825T030000")
        self.assertEqual(toIsoString(tempInterval.getEndTime()), "20150825T040000")

        tempInterval = Interval(interval1)
        tempInterval.unionWith(interval5)
        self.assertTrue(not tempInterval.isEmpty())
        self.assertEqual(toIsoString(tempInterval.getStartTime()), "20150825T030000")
        self.assertEqual(toIsoString(tempInterval.getEndTime()), "20150825T050000")

        tempInterval = Interval(interval1)
        tempInterval.intersectWith(interval6)
        self.assertTrue(not tempInterval.isEmpty())
        self.assertEqual(toIsoString(tempInterval.getStartTime()), "20150825T030000")
        self.assertEqual(toIsoString(tempInterval.getEndTime()), "20150825T050000")

        tempInterval = Interval(interval1)
        tempInterval.unionWith(interval6)
        self.assertTrue(not tempInterval.isEmpty())
        self.assertEqual(toIsoString(tempInterval.getStartTime()), "20150825T010000")
        self.assertEqual(toIsoString(tempInterval.getEndTime()), "20150825T050000")

        tempInterval = Interval(interval1)
        tempInterval.intersectWith(interval7)
        self.assertTrue(tempInterval.isEmpty())

        tempInterval = Interval(interval1)
        tempInterval.unionWith(interval7)
        self.assertTrue(not tempInterval.isEmpty())
        self.assertEqual(toIsoString(tempInterval.getStartTime()), "20150825T030000")
        self.assertEqual(toIsoString(tempInterval.getEndTime()), "20150825T050000")