def testShiftSUN2330by60min(self): t2330 = Time.getInstance(EnumWeekday.SUNDAY, 23, 30) tShift = t2330.shift(60) tReal = Time.getInstance(EnumWeekday.MONDAY, 00, 30) self.assertEqual( tReal, tShift, myMsg("test sunday to monday shift", str(tReal), str(tShift)))
def testShiftMon1230by30min(self): t1230 = makeMon1230() t1300_shifted = t1230.shift(30) t1300_real = Time.getInstance(EnumWeekday.MONDAY, 13, 00) self.assertEqual( t1300_real, t1300_shifted, myMsg("test shift", str(t1300_real), str(t1300_shifted)))
def testConstructorNormalCase(self): mon = EnumWeekday.MONDAY hour = 12 mini = 30 t = Time.getInstance(mon, hour, mini) self.assertEqual(mon, t.getWeekday(), "Weekday: Expect " + str(mon) + " but receive " + str(t.getWeekday())) self.assertEqual(hour, t.getHour(), "Hour: Expect " + str(hour) + " but receive " + str(t.getHour())) self.assertEqual(mini, t.getMini(), "Miniute: Expect " + str(mini) + " but receive " + str(t.getMini()))
def testAddTimeEndAndStartAtTheSameTime(self): t2 = Time.getInstance(EnumWeekday.MONDAY, 9, 30) tr2 = TimeRange.getInstance(t2, 60) tr = makeCSE403TimeRange() trs = TimeRanges.getInstance() trs.addTimeRange(tr) trs.addTimeRange(tr2)
def testDataBaseHasElement(self): mon = EnumWeekday.MONDAY hour = 12 mini = 30 myTime = datetime.time(12,30) # no object in database L = Time.objects.filter(time=myTime, dayIndex=mon()) # add object in database t = Time.getInstance(mon, hour, mini) self.assertTrue(1 == len(L), myMsg("Test Time Exist in Database", '1', str(len(L))))
def testGetAll(self): tr = makeCSE403TimeRange() t2 = Time.getInstance(EnumWeekday.MONDAY, 9, 30) tr2 = TimeRange.getInstance(t2, 60) t3 = Time.getInstance(EnumWeekday.MONDAY, 8, 30) tr3 = TimeRange.getInstance(t3, 60) trs = TimeRanges.getInstance() trs.addTimeRange(tr) trs.addTimeRange(tr2) trs.addTimeRange(tr3) allTRs = trs.getAll() self.assertTrue(tr in allTRs, str(tr) + " not in trs when getall is called") self.assertTrue(tr2 in allTRs, str(tr2) + " not in trs when getall is called") self.assertTrue(tr3 in allTRs, str(tr3) + " not in trs when getall is called")
def testAdd1Add2Remove1And2Exist(self): tr = makeCSE403TimeRange() t2 = Time.getInstance(EnumWeekday.MONDAY, 9, 30) tr2 = TimeRange.getInstance(t2, 60) trs = TimeRanges.getInstance() trs.addTimeRange(tr) trs.addTimeRange(tr2) trs.removeTimeRange(tr) self.assertTrue(trs.containTime(tr2), "tr2 should be in trs but got removed")
def testDataBaseHasElement(self): mon = EnumWeekday.MONDAY hour = 12 mini = 30 myTime = datetime.time(12, 30) # no object in database L = Time.objects.filter(time=myTime, dayIndex=mon()) # add object in database t = Time.getInstance(mon, hour, mini) self.assertTrue(1 == len(L), myMsg("Test Time Exist in Database", '1', str(len(L))))
def testConstructorNormalCase(self): mon = EnumWeekday.MONDAY hour = 12 mini = 30 t = Time.getInstance(mon, hour, mini) self.assertEqual( mon, t.getWeekday(), "Weekday: Expect " + str(mon) + " but receive " + str(t.getWeekday())) self.assertEqual( hour, t.getHour(), "Hour: Expect " + str(hour) + " but receive " + str(t.getHour())) self.assertEqual( mini, t.getMini(), "Miniute: Expect " + str(mini) + " but receive " + str(t.getMini()))
def makeMon1230(): mon = EnumWeekday.MONDAY hour = 12 mini = 30 myTime = datetime.time(12, 30) return Time.getInstance(mon, hour, mini)
def makeMon1230(): mon = EnumWeekday.MONDAY hour = 12 mini = 30 myTime = datetime.time(12,30) return Time.getInstance(mon, hour, mini)
def testSameDay1230MoreThan1200(self): t1 = makeMon1230() t2 = Time.getInstance(EnumWeekday.MONDAY, 12, 00) self.assertTrue(t1 > t2, myMsg("test same day compare", "12:30 > 12:00", str(t1 > t2)))
def makeCSE403TimeRange(): t = Time.getInstance(EnumWeekday.MONDAY, 10, 30) return TimeRange.getInstance(t, 50)
def tearDown(self): TimeRange.removeAll() Time.removeAll()
def testShiftMon2330by30min(self): t2330 = Time.getInstance(EnumWeekday.MONDAY, 23, 30) tShift = t2330.shift(30) tReal = Time.getInstance(EnumWeekday.TUESDAY, 00, 00) self.assertEqual(tReal, tShift, myMsg("test next day shift", str(tReal), str(tShift)))
def tearDown(self): Time.removeAll()
def testMondayLessThanSunday(self): tmon = makeMon1230() tsun = Time.getInstance(EnumWeekday.SUNDAY, 12, 30) self.assertTrue(tmon < tsun, myMsg("test lt", "monday < sunday", str(tmon < tsun)))
def testShiftMon1230by30min(self): t1230 = makeMon1230() t1300_shifted = t1230.shift(30) t1300_real = Time.getInstance(EnumWeekday.MONDAY,13,00) self.assertEqual(t1300_real, t1300_shifted, myMsg("test shift", str(t1300_real), str(t1300_shifted)))
def setUp(self): TimeRanges.removeAll() TimeRange.removeAll() Time.removeAll()
def testShiftSUN2330by60min(self): t2330 = Time.getInstance(EnumWeekday.SUNDAY, 23, 30) tShift = t2330.shift(60) tReal = Time.getInstance(EnumWeekday.MONDAY, 00, 30) self.assertEqual(tReal, tShift, myMsg("test sunday to monday shift", str(tReal), str(tShift)))
def testSameDay1230MoreThan1200(self): t1 = makeMon1230() t2 = Time.getInstance(EnumWeekday.MONDAY, 12, 00) self.assertTrue( t1 > t2, myMsg("test same day compare", "12:30 > 12:00", str(t1 > t2)))
def testMondayLessThanSunday(self): tmon = makeMon1230() tsun = Time.getInstance(EnumWeekday.SUNDAY, 12, 30) self.assertTrue(tmon < tsun, myMsg("test lt", "monday < sunday", str(tmon<tsun)))
def getTime(dayNum, hour, min): return Time.getInstance(EnumWeekday.fromInt(dayNum), hour, min)