# HG changeset patch # User Dirk Olmes # Date 1231556962 -3600 # Node ID 5fa902852779da49241e3ce594157a90904da97f # Parent 78a59d65bfcc34940441f8be47ba1a6f988962c1 add unit tests for timedelta function diff -r 78a59d65bfcc -r 5fa902852779 timedelta_tests.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/timedelta_tests.py Sat Jan 10 04:09:22 2009 +0100 @@ -0,0 +1,50 @@ + +import unittest +from timedelta import timedelta +from datetime import time + +class TimeDeltaTests(unittest.TestCase): + def testDeltaWrongArgumentOrder(self): + t1 = time(microsecond=4) + t2 = time(microsecond=5) + expected = time(microsecond=1) + self.assert_(expected == timedelta(t2, t1)) + + def testDeltaMicroseconds(self): + t1 = time(microsecond=4) + t2 = time(microsecond=5) + expected = time(microsecond=1) + self.assert_(expected == timedelta(t1, t2)) + + def testDeltaSeconds(self): + t1 = time(second=4) + t2 = time(second=5) + expected = time(second=1) + self.assert_(expected == timedelta(t1, t2)) + + def testDeltaMinutes(self): + t1 = time(minute=4) + t2 = time(minute=5) + expected = time(minute=1) + self.assert_(expected == timedelta(t1, t2)) + + def testDeltaHours(self): + t1 = time(hour=4) + t2 = time(hour=5) + expected = time(hour=1) + self.assert_(expected == timedelta(t1, t2)) + + def testDeltaMixed(self): + t1 = time(11, 32, 10) + t2 = time(11, 35, 30) + expected = time(minute=3, second=20) + self.assert_(expected == timedelta(t1, t2)) + + def testDeltaMax(self): + t1 = time(0, 0, 0, 0) + t2 = time(23, 59, 59, 999999) + expected = time(23, 59, 59, 999999) + self.assert_(expected == timedelta(t1, t2)) + +if __name__ == "__main__": + unittest.main()