def test___eq__(self): self.assertTrue(DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100)), DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100))) self.assertTrue(DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100)), DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100)) * 3 / 3.0) self.assertTrue(DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100)), DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100.0000001))) self.assertTrue(DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100)), DayuTimeRange(DayuTimeCode(0.0000001), DayuTimeCode(100))) self.assertTrue(DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100)), DayuTimeRange(DayuTimeCode(-0.0000001), DayuTimeCode(100))) self.assertTrue(DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100)), DayuTimeRange(DayuTimeCode(0), DayuTimeCode(99.9999999)))
def test___div__(self): a = DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100)) self.assertEqual(a / DayuTimeCode(2), DayuTimeRange(DayuTimeCode(0), DayuTimeCode(50))) self.assertRaises(ZeroDivisionError, lambda: a / 0) self.assertEqual(a / 0.2, DayuTimeRange(DayuTimeCode(0), DayuTimeCode(500))) self.assertEqual(a / 20, DayuTimeRange(DayuTimeCode(0), DayuTimeCode(5))) self.assertEqual(a / -1, DayuTimeRange(DayuTimeCode(-100), DayuTimeCode(0))) a = DayuTimeRange(DayuTimeCode(100), DayuTimeCode(200)) self.assertEqual(a / DayuTimeCode(2), DayuTimeRange(DayuTimeCode(100), DayuTimeCode(150))) self.assertEqual(a / 0.5, DayuTimeRange(DayuTimeCode(100), DayuTimeCode(300))) self.assertEqual(a / 20, DayuTimeRange(DayuTimeCode(100), DayuTimeCode(105))) self.assertEqual(a / -1, DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100))) self.assertEqual(a / -2, DayuTimeRange(DayuTimeCode(50), DayuTimeCode(100))) self.assertRaises((DayuTimeRangeOutOfRange, DayuTimeRangeOperationError, TypeError, ValueError), lambda: a / None) self.assertRaises((DayuTimeRangeOutOfRange, DayuTimeRangeOperationError, TypeError, ValueError), lambda: a / '') self.assertRaises((DayuTimeRangeOutOfRange, DayuTimeRangeOperationError, TypeError, ValueError), lambda: a / a) self.assertRaises((DayuTimeRangeOutOfRange, DayuTimeRangeOperationError, TypeError, ValueError), lambda: a / []) self.assertRaises((DayuTimeRangeOutOfRange, DayuTimeRangeOperationError, TypeError, ValueError), lambda: a / tuple)
def test___idiv__(self): a = DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100)) a /= 2 self.assertEqual(a, DayuTimeRange(DayuTimeCode(0), DayuTimeCode(50))) self.assertRaises(ZeroDivisionError, lambda: a / 0) a /= 0.2 self.assertEqual(a, DayuTimeRange(DayuTimeCode(0), DayuTimeCode(250))) a /= 10 self.assertEqual(a, DayuTimeRange(DayuTimeCode(0), DayuTimeCode(25))) a /= -1 self.assertEqual(a, DayuTimeRange(DayuTimeCode(-25), DayuTimeCode(0))) a = DayuTimeRange(DayuTimeCode(100), DayuTimeCode(200)) a /= 2 self.assertEqual(a, DayuTimeRange(DayuTimeCode(100), DayuTimeCode(150))) a /= 0.5 self.assertEqual(a, DayuTimeRange(DayuTimeCode(100), DayuTimeCode(200))) a /= 20 self.assertEqual(a, DayuTimeRange(DayuTimeCode(100), DayuTimeCode(105))) a /= -0.5 self.assertEqual(a, DayuTimeRange(DayuTimeCode(90), DayuTimeCode(100))) a /= -0.01 self.assertEqual(a, DayuTimeRange(DayuTimeCode(-910), DayuTimeCode(90)))
def test___imul__(self): a = DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100)) a *= DayuTimeCode(3) self.assertEqual(a, DayuTimeRange(DayuTimeCode(0), DayuTimeCode(300))) a *= 0.5 self.assertEqual(a, DayuTimeRange(DayuTimeCode(0), DayuTimeCode(150))) self.assertEqual(a * -1, DayuTimeRange(DayuTimeCode(-150), DayuTimeCode(0))) a = DayuTimeRange(DayuTimeCode(100), DayuTimeCode(200)) a *= 3 self.assertEqual(a, DayuTimeRange(DayuTimeCode(100), DayuTimeCode(400))) a *= 0.5 self.assertEqual(a, DayuTimeRange(DayuTimeCode(100), DayuTimeCode(250))) a *= (-1) print a.start, a.end self.assertEqual(a, DayuTimeRange(DayuTimeCode(-50), DayuTimeCode(100)))
def test_duration(self): self.assertEqual(DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100)).duration, 100) self.assertEqual(DayuTimeRange(DayuTimeCode(-100), DayuTimeCode(-50)).duration, 50) self.assertEqual(DayuTimeRange(DayuTimeCode(-100), DayuTimeCode(50)).duration, 150)
def test___isub__(self): a = DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100)) a -= DayuTimeCode(100) self.assertEqual(a, DayuTimeRange(DayuTimeCode(-100), DayuTimeCode(0))) a -= 1 self.assertEqual(a, DayuTimeRange(DayuTimeCode(-101), DayuTimeCode(-1))) a -= 10.0 self.assertAlmostEqual(a, DayuTimeRange(DayuTimeCode(-111), DayuTimeCode(-11))) a -= (-20) self.assertAlmostEqual(a, DayuTimeRange(DayuTimeCode(-91), DayuTimeCode(9))) self.assertRaises((DayuTimeRangeOutOfRange, DayuTimeRangeOperationError, TypeError, ValueError), lambda: a - None) self.assertRaises((DayuTimeRangeOutOfRange, DayuTimeRangeOperationError, TypeError, ValueError), lambda: a - '') self.assertRaises((DayuTimeRangeOutOfRange, DayuTimeRangeOperationError, TypeError, ValueError), lambda: a - a) self.assertRaises((DayuTimeRangeOutOfRange, DayuTimeRangeOperationError, TypeError, ValueError), lambda: a + []) self.assertRaises((DayuTimeRangeOutOfRange, DayuTimeRangeOperationError, TypeError, ValueError), lambda: a + tuple)
def test___mul__(self): a = DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100)) self.assertEqual(a * DayuTimeCode(3), DayuTimeRange(DayuTimeCode(0), DayuTimeCode(300))) self.assertEqual(a * 0.5, DayuTimeRange(DayuTimeCode(0), DayuTimeCode(50))) self.assertRaises((DayuTimeRangeOutOfRange, DayuTimeRangeOperationError), lambda: a * 0) self.assertEqual(a * 3, DayuTimeRange(DayuTimeCode(0), DayuTimeCode(300))) self.assertEqual(a * 3.5, DayuTimeRange(DayuTimeCode(0), DayuTimeCode(350))) self.assertEqual(a * -1, DayuTimeRange(DayuTimeCode(-100), DayuTimeCode(0))) a = DayuTimeRange(DayuTimeCode(100), DayuTimeCode(200)) self.assertEqual(a * DayuTimeCode(3), DayuTimeRange(DayuTimeCode(100), DayuTimeCode(400))) self.assertEqual(a * 3, DayuTimeRange(DayuTimeCode(100), DayuTimeCode(400))) self.assertEqual(a * 3.5, DayuTimeRange(DayuTimeCode(100), DayuTimeCode(450))) self.assertEqual(a * -1, DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100))) self.assertEqual(a * -1.5, DayuTimeRange(DayuTimeCode(-50), DayuTimeCode(100))) self.assertRaises((DayuTimeRangeOutOfRange, DayuTimeRangeOperationError, TypeError, ValueError), lambda: a * None) self.assertRaises((DayuTimeRangeOutOfRange, DayuTimeRangeOperationError, TypeError, ValueError), lambda: a * '') self.assertRaises((DayuTimeRangeOutOfRange, DayuTimeRangeOperationError, TypeError, ValueError), lambda: a * a) self.assertRaises((DayuTimeRangeOutOfRange, DayuTimeRangeOperationError, TypeError, ValueError), lambda: a * []) self.assertRaises((DayuTimeRangeOutOfRange, DayuTimeRangeOperationError, TypeError, ValueError), lambda: a * tuple)
def test___add__(self): a = DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100)) self.assertEqual(a + DayuTimeCode(100), DayuTimeRange(DayuTimeCode(100), DayuTimeCode(200))) self.assertEqual(a + 0, DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100))) self.assertEqual(a + 100, DayuTimeRange(DayuTimeCode(100), DayuTimeCode(200))) self.assertEqual(a + (-100), DayuTimeRange(DayuTimeCode(-100), DayuTimeCode(0))) self.assertRaises(DayuTimeRangeOperationError, lambda: a + None) self.assertRaises(DayuTimeRangeOperationError, lambda: a + '') self.assertRaises(DayuTimeRangeOperationError, lambda: a + a) self.assertRaises(DayuTimeRangeOperationError, lambda: a + []) self.assertRaises(DayuTimeRangeOperationError, lambda: a + tuple)
def test___sub__(self): a = DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100)) self.assertEqual(a - DayuTimeCode(100), DayuTimeRange(DayuTimeCode(-100), DayuTimeCode(0))) self.assertEqual(a - 0, DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100))) self.assertEqual(a - 100, DayuTimeRange(DayuTimeCode(-100), DayuTimeCode(0))) self.assertEqual(a - (-100), DayuTimeRange(DayuTimeCode(100), DayuTimeCode(200))) self.assertRaises((DayuTimeRangeOutOfRange, DayuTimeRangeOperationError, TypeError, ValueError), lambda: a - None) self.assertRaises((DayuTimeRangeOutOfRange, DayuTimeRangeOperationError, TypeError, ValueError), lambda: a - '') self.assertRaises((DayuTimeRangeOutOfRange, DayuTimeRangeOperationError, TypeError, ValueError), lambda: a - a) self.assertRaises((DayuTimeRangeOutOfRange, DayuTimeRangeOperationError, TypeError, ValueError), lambda: a - []) self.assertRaises((DayuTimeRangeOutOfRange, DayuTimeRangeOperationError, TypeError, ValueError), lambda: a - tuple)
def test___iadd__(self): a = DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100)) a += DayuTimeCode(100) self.assertEqual(a, DayuTimeRange(DayuTimeCode(100), DayuTimeCode(200))) a += 1 self.assertEqual(a, DayuTimeRange(DayuTimeCode(101), DayuTimeCode(201))) a += 10.0 self.assertAlmostEqual(a, DayuTimeRange(DayuTimeCode(111), DayuTimeCode(211))) a += (-20) self.assertAlmostEqual(a, DayuTimeRange(DayuTimeCode(91), DayuTimeCode(191))) self.assertRaises((DayuTimeRangeOutOfRange, DayuTimeRangeOperationError, TypeError, ValueError), lambda: a + None) self.assertRaises((DayuTimeRangeOutOfRange, DayuTimeRangeOperationError, TypeError, ValueError), lambda: a + '') self.assertRaises((DayuTimeRangeOutOfRange, DayuTimeRangeOperationError, TypeError, ValueError), lambda: a + a) self.assertRaises((DayuTimeRangeOutOfRange, DayuTimeRangeOperationError, TypeError, ValueError), lambda: a + []) self.assertRaises((DayuTimeRangeOutOfRange, DayuTimeRangeOperationError, TypeError, ValueError), lambda: a + tuple)
def test___xor__(self): a = DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100)) b = DayuTimeRange(DayuTimeCode(-200), DayuTimeCode(-100)) c = DayuTimeRange(DayuTimeCode(-200), DayuTimeCode(20)) d = DayuTimeRange(DayuTimeCode(-200), DayuTimeCode(100)) e = DayuTimeRange(DayuTimeCode(-200), DayuTimeCode(400)) self.assertEqual(a ^ b, (DayuTimeRange(DayuTimeCode(-200), DayuTimeCode(-100)), DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100)))) self.assertEqual(a ^ c, (DayuTimeRange(DayuTimeCode(-200), DayuTimeCode(0)), DayuTimeRange(DayuTimeCode(20), DayuTimeCode(100)))) self.assertEqual(a ^ d, (DayuTimeRange(DayuTimeCode(-200), DayuTimeCode(0)), None)) self.assertEqual(a ^ e, (DayuTimeRange(DayuTimeCode(-200), DayuTimeCode(0)), DayuTimeRange(DayuTimeCode(100), DayuTimeCode(400)))) b = DayuTimeRange(DayuTimeCode(-1), DayuTimeCode(0)) c = DayuTimeRange(DayuTimeCode(0), DayuTimeCode(20)) d = DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100)) e = DayuTimeRange(DayuTimeCode(0), DayuTimeCode(400)) self.assertEqual(a ^ b, (DayuTimeRange(DayuTimeCode(-1), DayuTimeCode(-0)), DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100)))) self.assertEqual(a ^ c, (None, DayuTimeRange(DayuTimeCode(20), DayuTimeCode(100)))) self.assertEqual(a ^ d, (None, None)) self.assertEqual(a ^ e, (None, DayuTimeRange(DayuTimeCode(100), DayuTimeCode(400)))) b = DayuTimeRange(DayuTimeCode(19), DayuTimeCode(20)) c = DayuTimeRange(DayuTimeCode(20), DayuTimeCode(50)) d = DayuTimeRange(DayuTimeCode(20), DayuTimeCode(100)) e = DayuTimeRange(DayuTimeCode(20), DayuTimeCode(400)) self.assertEqual(a ^ b, (DayuTimeRange(DayuTimeCode(-0), DayuTimeCode(19)), DayuTimeRange(DayuTimeCode(20), DayuTimeCode(100)))) self.assertEqual(a ^ c, (DayuTimeRange(DayuTimeCode(0), DayuTimeCode(20)), DayuTimeRange(DayuTimeCode(50), DayuTimeCode(100)))) self.assertEqual(a ^ d, (DayuTimeRange(DayuTimeCode(0), DayuTimeCode(20)), None)) self.assertEqual(a ^ e, (DayuTimeRange(DayuTimeCode(0), DayuTimeCode(20)), DayuTimeRange(DayuTimeCode(100), DayuTimeCode(400)))) b = DayuTimeRange(DayuTimeCode(100), DayuTimeCode(101)) c = DayuTimeRange(DayuTimeCode(100), DayuTimeCode(400)) self.assertEqual(a ^ b, (DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100)), DayuTimeRange(DayuTimeCode(100), DayuTimeCode(101)))) self.assertEqual(a ^ c, (DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100)), DayuTimeRange(DayuTimeCode(100), DayuTimeCode(400)))) b = DayuTimeRange(DayuTimeCode(200), DayuTimeCode(400)) c = DayuTimeRange(DayuTimeCode(400), DayuTimeCode(401)) self.assertEqual(a ^ b, (DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100)), DayuTimeRange(DayuTimeCode(200), DayuTimeCode(400)))) self.assertEqual(a ^ c, (DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100)), DayuTimeRange(DayuTimeCode(400), DayuTimeCode(401))))
def test___or__(self): a = DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100)) b = DayuTimeRange(DayuTimeCode(-200), DayuTimeCode(-100)) c = DayuTimeRange(DayuTimeCode(-200), DayuTimeCode(20)) d = DayuTimeRange(DayuTimeCode(-200), DayuTimeCode(100)) e = DayuTimeRange(DayuTimeCode(-200), DayuTimeCode(400)) self.assertEqual(a | b, DayuTimeRange(DayuTimeCode(-200), DayuTimeCode(100))) self.assertEqual(a | c, DayuTimeRange(DayuTimeCode(-200), DayuTimeCode(100))) self.assertEqual(a | d, DayuTimeRange(DayuTimeCode(-200), DayuTimeCode(100))) self.assertEqual(a | e, DayuTimeRange(DayuTimeCode(-200), DayuTimeCode(400))) b = DayuTimeRange(DayuTimeCode(-1), DayuTimeCode(0)) c = DayuTimeRange(DayuTimeCode(0), DayuTimeCode(20)) d = DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100)) e = DayuTimeRange(DayuTimeCode(0), DayuTimeCode(400)) self.assertEqual(a | b, DayuTimeRange(DayuTimeCode(-1), DayuTimeCode(100))) self.assertEqual(a | c, DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100))) self.assertEqual(a | d, DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100))) self.assertEqual(a | e, DayuTimeRange(DayuTimeCode(0), DayuTimeCode(400))) b = DayuTimeRange(DayuTimeCode(19), DayuTimeCode(20)) c = DayuTimeRange(DayuTimeCode(20), DayuTimeCode(50)) d = DayuTimeRange(DayuTimeCode(20), DayuTimeCode(100)) e = DayuTimeRange(DayuTimeCode(20), DayuTimeCode(400)) self.assertEqual(a | b, DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100))) self.assertEqual(a | c, DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100))) self.assertEqual(a | d, DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100))) self.assertEqual(a | e, DayuTimeRange(DayuTimeCode(0), DayuTimeCode(400))) b = DayuTimeRange(DayuTimeCode(100), DayuTimeCode(101)) c = DayuTimeRange(DayuTimeCode(100), DayuTimeCode(400)) self.assertEqual(a | b, DayuTimeRange(DayuTimeCode(0), DayuTimeCode(101))) self.assertEqual(a | c, DayuTimeRange(DayuTimeCode(0), DayuTimeCode(400))) b = DayuTimeRange(DayuTimeCode(200), DayuTimeCode(400)) c = DayuTimeRange(DayuTimeCode(400), DayuTimeCode(401)) self.assertEqual(a | b, DayuTimeRange(DayuTimeCode(0), DayuTimeCode(400))) self.assertEqual(a | c, DayuTimeRange(DayuTimeCode(0), DayuTimeCode(401)))
def test___and__(self): a = DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100)) b = DayuTimeRange(DayuTimeCode(-200), DayuTimeCode(-100)) c = DayuTimeRange(DayuTimeCode(-200), DayuTimeCode(20)) d = DayuTimeRange(DayuTimeCode(-200), DayuTimeCode(100)) e = DayuTimeRange(DayuTimeCode(-200), DayuTimeCode(400)) self.assertIsNone(a & b) self.assertEqual(a & c, DayuTimeRange(DayuTimeCode(0), DayuTimeCode(20))) self.assertEqual(a & d, DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100))) self.assertEqual(a & e, DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100))) b = DayuTimeRange(DayuTimeCode(-1), DayuTimeCode(0)) c = DayuTimeRange(DayuTimeCode(0), DayuTimeCode(20)) d = DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100)) e = DayuTimeRange(DayuTimeCode(0), DayuTimeCode(400)) self.assertIsNone(a & b) self.assertEqual(a & c, DayuTimeRange(DayuTimeCode(0), DayuTimeCode(20))) self.assertEqual(a & d, DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100))) self.assertEqual(a & e, DayuTimeRange(DayuTimeCode(0), DayuTimeCode(100))) b = DayuTimeRange(DayuTimeCode(19), DayuTimeCode(20)) c = DayuTimeRange(DayuTimeCode(20), DayuTimeCode(50)) d = DayuTimeRange(DayuTimeCode(20), DayuTimeCode(100)) e = DayuTimeRange(DayuTimeCode(20), DayuTimeCode(400)) self.assertEqual(a & b, DayuTimeRange(DayuTimeCode(19), DayuTimeCode(20))) self.assertEqual(a & c, DayuTimeRange(DayuTimeCode(20), DayuTimeCode(50))) self.assertEqual(a & d, DayuTimeRange(DayuTimeCode(20), DayuTimeCode(100))) self.assertEqual(a & e, DayuTimeRange(DayuTimeCode(20), DayuTimeCode(100))) b = DayuTimeRange(DayuTimeCode(100), DayuTimeCode(101)) c = DayuTimeRange(DayuTimeCode(100), DayuTimeCode(400)) self.assertIsNone(a & b) self.assertIsNone(a & c) b = DayuTimeRange(DayuTimeCode(200), DayuTimeCode(400)) c = DayuTimeRange(DayuTimeCode(400), DayuTimeCode(401)) self.assertIsNone(a & b) self.assertIsNone(a & c)
def test___contains__(self): tr = DayuTimeRange(DayuTimeCode(0), DayuTimeCode(2880)) for tc in DayuTimeRange(DayuTimeCode(-100), DayuTimeCode(14400)): if tr.start <= tc <= tr.end: self.assertTrue(tc in tr) else: self.assertFalse(tc in tr) self.assertFalse(DayuTimeRange(DayuTimeCode(-200), DayuTimeCode(-150)) in tr) self.assertFalse(DayuTimeRange(DayuTimeCode(-200), DayuTimeCode(-100)) in tr) self.assertFalse(DayuTimeRange(DayuTimeCode(-200), DayuTimeCode(50)) in tr) self.assertFalse(DayuTimeRange(DayuTimeCode(-200), DayuTimeCode(2880)) in tr) self.assertFalse(DayuTimeRange(DayuTimeCode(-200), DayuTimeCode(30000)) in tr) self.assertTrue(DayuTimeRange(DayuTimeCode(0), DayuTimeCode(50)) in tr) self.assertTrue(DayuTimeRange(DayuTimeCode(0), DayuTimeCode(2880)) in tr) self.assertFalse(DayuTimeRange(DayuTimeCode(0), DayuTimeCode(30000)) in tr) self.assertTrue(DayuTimeRange(DayuTimeCode(50), DayuTimeCode(100)) in tr) self.assertTrue(DayuTimeRange(DayuTimeCode(50), DayuTimeCode(2880)) in tr) self.assertFalse(DayuTimeRange(DayuTimeCode(50), DayuTimeCode(3000)) in tr) self.assertFalse(DayuTimeRange(DayuTimeCode(2880), DayuTimeCode(2881)) in tr) self.assertFalse(DayuTimeRange(DayuTimeCode(2880), DayuTimeCode(30000)) in tr)