def test_missedLectureCheck(self): day = datetime.date.today().weekday() hour = datetime.datetime.now().hour minute = datetime.datetime.now().minute if minute > 45: hour = hour + 1 self.userEntity.history = [] self.userEntity.lectures = [] # adds a single lecture which has already occured, and therefore should be counted as 'missed' self.userEntity.lectures.append(Lecture(module='GENG0013', title='0', location='2', day=day, time=hour-1 , duration=1)) # adds a double lecture which has already occured, and therefore should be counted as 'missed' self.userEntity.lectures.append(Lecture(module='GENG0013', title='1', location='2', day=day, time=hour-2 , duration=2)) # adds a single lecture which is currently occuring, so shouldn't be missed self.userEntity.lectures.append(Lecture(module='GENG0013', title='2', location='2', day=day, time=hour , duration=1)) # adds a double lecture which is currently occuring, so shouldn't be missed self.userEntity.lectures.append(Lecture(module='GENG0013', title='3', location='2', day=day, time=hour-1 , duration=2)) missedLectureCheck(self.userEntity) # checks that, in all of the previous weeks, there is a match for each timetabled lecture in the history for i in range(1, getCurrentWeek()): for lecture in self.userEntity.lectures: matched = False for pastLecture in self.userEntity.history: if pastLecture.week == i and pastLecture.day == lecture.day and pastLecture.time == lecture.time: matched = True self.assertTrue(matched) # an array representing the 4 lectures defined above # if they have been added to history, they invert their corresponding value # so the first two lectures should invert the first two values to True # while the second two should leave their values as True checked = [False, False, True, True] for pastLecture in self.userEntity.history: if pastLecture.week == getCurrentWeek(): checked[int(pastLecture.title)] = not checked[int(pastLecture.title)] for checkedLecture in checked: self.assertTrue(checkedLecture)
def test_chall10(self): self.userEntity.history = [] lecture1 = Lecture(module='GENG0013', title='TT Math Support', location='2', day=0, time=14, duration=1, week=getCurrentWeek(), attended=True) lecture2 = Lecture(module='GENG0013', title='TT Math Support', location='2', day=0, time=15, duration=1, week=getCurrentWeek(), attended=True) lecture3 = Lecture(module='GENG0013', title='TT Math Support', location='2', day=0, time=16, duration=1, week=getCurrentWeek(), attended=True) lecture4 = Lecture(module='GENG0013', title='TT Math Support', location='2', day=0, time=17, duration=1, week=getCurrentWeek(), attended=True) checkin1 = CheckIn(student=self.userEntity, lecture=lecture1, date=datetime.date.today(), time=datetime.datetime.now().time()) checkin2 = CheckIn(student=self.userEntity, lecture=lecture2, date=datetime.date.today(), time=datetime.datetime.now().time()) checkin3 = CheckIn(student=self.userEntity, lecture=lecture3, date=datetime.date.today(), time=datetime.datetime.now().time()) checkin4 = CheckIn(student=self.userEntity, lecture=lecture4, date=datetime.date.today(), time=datetime.datetime.now().time()) self.userEntity.history.append(lecture1) complete = challengecheck(self.userEntity, lecture1, checkin1) self.assertEqual(complete, []) self.userEntity.history.append(lecture2) complete = challengecheck(self.userEntity, lecture2, checkin2) self.assertEqual(complete, []) self.userEntity.history.append(lecture3) complete = challengecheck(self.userEntity, lecture3, checkin3) self.assertEqual(complete, []) self.userEntity.history.append(lecture4) complete = challengecheck(self.userEntity, lecture4, checkin4) self.assertEqual(complete[0].challengeid, 10)
def test_chall9(self): lecture1 = Lecture(module='GENG0013', title='TT Math Support', location='2', day=0, time=10, duration=1, week=getCurrentWeek(), attended=True) checkin1 = CheckIn(student=self.userEntity, lecture=lecture1, date=datetime.date.today(), time=datetime.datetime.now().time()) complete = challengecheck(self.userEntity, lecture1, checkin1) self.assertEqual(complete, []) lecture2 = Lecture(module='GENG0013', title='TT Math Support', location='2', day=0, time=9, duration=1, week=getCurrentWeek(), attended=True) checkin2 = CheckIn(student=self.userEntity, lecture=lecture2, date=datetime.date.today(), time=datetime.datetime.now().time()) complete = challengecheck(self.userEntity, lecture2, checkin2) self.assertEqual(complete[0].challengeid, 9)