def test_cmp(self): assert_equal(TimeInterval(2.22), TimeInterval(2, microseconds=220000)) assert_gt(TimeInterval(2.22), TimeInterval(2.20)) assert_gt(TimeInterval(3.22), TimeInterval(2.5)) assert_lt(TimeInterval(0), TimeInterval(microseconds=1)) assert_lt(TimeInterval(-3), TimeInterval(2.5))
def test_div_micro(self): i1 = TimeInterval(2, microseconds=22) i2 = i1 / 2 assert_equal(i2.seconds, 1) assert_equal(i2.microseconds, 11)
def test(self): start_t = Time.now() end_t = start_t + 5*60 times = list(TimeSpanIterator(TimeSpan(start_t, end_t), TimeInterval(60))) assert_equal(len(times), 5) assert_equal(times[0].start, start_t) assert_equal(times[-1].end, end_t)
def test_time_add(self): t1 = Time(2014, 4, 18, 17, 50, 21) ti = TimeInterval(2.22) t2 = t1 + ti assert_equal(t2.second, 23) assert_equal(t2.microsecond, 220000)
def test_time_sub(self): t1 = Time(2014, 4, 18, 17, 50, 21) ti = TimeInterval(2.22) t2 = t1 - ti assert_equal(t2.second, 18) assert_equal(t2.microsecond, 780000)
def test_timedelta(self): td = datetime.timedelta(days=1, seconds=10, microseconds=1000) i = TimeInterval.from_timedelta(td) assert_equal(i.seconds, round(td.total_seconds())) assert_equal(i.microseconds, td.microseconds) assert_equal(float(i), td.total_seconds())
def test_sub_int(self): i1 = TimeInterval(2) i2 = 1 i3 = i1 - i2 assert_equal(i3.seconds, 1) i4 = i2 - i1 assert_equal(i4, -1)
def test_add_int(self): i1 = TimeInterval(1) i2 = 1 i3 = i1 + i2 assert_equal(i3.seconds, 2) i4 = i2 + i1 assert_equal(i4.seconds, 2)
def test_div(self): i1 = TimeInterval(5) i2 = i1 / 2 assert_equal(float(i2), 2.5)
def test_mul(self): i1 = TimeInterval(2) i2 = i1 * 3 assert_equal(int(i2), 6)
def test_sub_neg(self): i1 = TimeInterval(1) i2 = TimeInterval(2) i3 = i1 - i2 assert_equal(i3.seconds, -1)
def test_hours(self): i = TimeInterval(hours=1) assert_equal(i.seconds, 3600) assert_equal(i.microseconds, 0)
def test_seconds(self): i = TimeInterval(21) assert_equal(i.seconds, 21) assert_equal(i.microseconds, 0)
def test_int_round(self): i = TimeInterval(4, microseconds=600000) assert_equal(int(i), 5)
def test_int(self): i = TimeInterval(4) assert_equal(int(i), 4)
def test_microsecond_overflow(self): i = TimeInterval(seconds=1.9, microseconds=200000) assert_equal(i.seconds, 2) assert_equal(i.microseconds, 100000)
def test_microseconds(self): i = TimeInterval(microseconds=10) assert_equal(i.seconds, 0) assert_equal(i.microseconds, 10)
def test_float_seconds(self): i = TimeInterval(1.2) assert_equal(i.seconds, 1) assert_equal(i.microseconds, 200000)
def test_str(self): i = TimeInterval(hours=1, minutes=45, seconds=21, microseconds=600000) assert_equal(str(i), "+01:45:21.6")
def test_abs(self): i1 = TimeInterval(2.22) i2 = abs(i1) assert_equal(float(i1), 2.22)
def test_add(self): i1 = TimeInterval(1) i2 = TimeInterval(1) i3 = i1 + i2 assert_equal(i3.seconds, 2)
def test_float(self): i = TimeInterval(4, microseconds=600000) assert_equal(float(i), 4.6)
def test_minutes(self): i = TimeInterval(minutes=2) assert_equal(i.seconds, 120) assert_equal(i.microseconds, 0)