def test_updateActivityInList(): activityList = [] activityList.append(Activity(4, [4, 5], '12.04.2019', '00:10', 'rugby')) updateActivityInList( activityList, 4, Activity(10, [1, 2, 4], '12.04.2019', '10:00', 'golf')) assert len(activityList) == 1 and activityList[0].get_activity_id() == 10
def test(self): personList = [] personList.append(Person(1, None, None, None)) activityList = [] activityList.append(Activity(4, [4,5], '12.04.2025', '00:10', 'rugby')) activityList.append(Activity(10, [1,2,3], '12.04.2025', '10:00', 'golf')) participatesList = personParticipatesToUpcoming(activityList, personList, 1) assert len(participatesList) == 1 and participatesList[0].get_activity_id() == 10
def test_activitiesForWeek(self): activityList = [] activityList.append(Activity(1, [1,2], '11.11.2018', '16:00', 'rugby')) activityList.append(Activity(2, [2,8], '10.11.2018', '15:00', 'tennis')) activityList.append(Activity(3, [1,8,9,10], '05.12.2018', '12:30', 'basketball')) activityList.append(Activity(4, [4,5,10], '10.11.2018', '14:45', 'football')) activityList.append(Activity(5, [3,6,7], '05.01.2019', '09:15', 'swimming')) matchingList = activitiesForWeek(activityList, '08.11.2018') assert len(matchingList) == 3 and matchingList[0].get_activity_id() == 4 and matchingList[1].get_activity_id() == 2 and matchingList[2].get_activity_id() == 1
def test(self): personList = [] personList.append(Person(1, 'Pop_Adrian', '0745739772', 'aleea_Peana_13')) personList.append(Person(2, 'Luca_Iulian', '0743877389', 'aleea_Rucar_2')) personList.append(Person(3, 'Pindelea_Ionela', '0748966321', 'strada_Primaverii_14')) activityList = [] activityList.append(Activity(4, [1,3], '12.04.2025', '00:10', 'rugby')) activityList.append(Activity(10, [1,2,3], '12.04.2025', '10:00', 'golf')) newList = peopleInDescendingOrderByActivities(activityList, personList) assert len(newList) == 3 and newList[0].get_id() == 1 and newList[1].get_id() == 3 and newList[2].get_id() == 2
def test_searchActivityInList(self): activityList = [] activityList.append(Activity(4, [4,5], '12.04.2019', '00:10', 'rugby')) activityList.append(Activity(10, [1,2,3], '12.04.2019', '10:00', 'golf')) matchingList = searchActivityInList(activityList, 'g') assert len(matchingList) == 2 and matchingList[0].get_activity_id() == 4 matchingList = searchActivityInList(activityList, '04.2019') assert len(matchingList) == 2 and matchingList[0].get_activity_id() == 4 matchingList = searchActivityInList(activityList, '10:') assert len(matchingList) == 1 and matchingList[0].get_activity_id() == 10 matchingList = searchActivityInList(activityList, '2019 00:') assert len(matchingList) == 1 and matchingList[0].get_activity_id() == 4
def test(self): activityList = [] activityList.append(Activity(1, [1,2], '11.11.2025', '16:00', 'rugby')) activityList.append(Activity(2, [2,8], '10.12.2025', '08:00', 'tennis')) activityList.append(Activity(3, [1,8,9,10], '10.12.2025', '12:30', 'basketball')) activityList.append(Activity(4, [4,5,10], '11.11.2025', '14:45', 'football')) activityList.append(Activity(5, [3,6,7], '10.01.2026', '16:15', 'swimming')) activityList.append(Activity(6, [2,3,4], '20.02.2026', '18:55', 'baseball')) activityList.append(Activity(7, [1,2,3,4,5,6,7,8,9], '20.02.2026', '20:30', 'bowling')) activityList.append(Activity(8, [5,6,7,8], '11.11.2025', '22:00', 'football')) activityList.append(Activity(9, [1,8,9,10], '10.12.2025', '23:10', 'tennis')) activityList.append(Activity(10, [4,5,8,9], '11.11.2025', '17:00', 'golf')) busiestDaysList = busiestDays(activityList) assert len(busiestDaysList) == 4 and busiestDaysList[0] == '11.11.2025' and busiestDaysList[1] == '10.12.2025' and busiestDaysList[2] == '20.02.2026' and busiestDaysList[3] == '10.01.2026'
def test_undoRedo(): personList = [] activityList = [] undoList = [] redoList = [] addPersonToList(personList, Person(15, None, None, None), activityList) undoList.append([removePersonFromList, personList, activityList, 15]) assert len(personList) == 1 undo(undoList, redoList, personList, activityList) assert len(undoList) == 0 and len(redoList) == 1 and len(personList) == 0 redo(undoList, redoList, personList, activityList) assert len(undoList) == 1 and len(redoList) == 0 and len( personList) == 1 and personList[0].get_id() == 15 addActivityToList(activityList, personList, Activity(10, [15], None, None, None)) undoList.append([removeActivityFromList, activityList, 10]) assert len(activityList) == 1 undo(undoList, redoList, personList, activityList) assert len(undoList) == 1 and len(redoList) == 1 and len(activityList) == 0 redo(undoList, redoList, personList, activityList) assert len(undoList) == 2 and len(redoList) == 0 and len( activityList) == 1 and activityList[0].get_activity_id() == 10 undoList.append([ addPersonToList, personList, Person(15, None, None, None), activityList, personParticipatesTo(activityList, personList, 15) ]) removePersonFromList(personList, activityList, 15) assert len(personList) == 0 undo(undoList, redoList, personList, activityList) assert len(undoList) == 2 and len(redoList) == 1 and len( personList) == 1 and personList[0].get_id() == 15 redo(undoList, redoList, personList, activityList) assert len(undoList) == 3 and len(redoList) == 0 and len(personList) == 0 undo(undoList, redoList, personList, activityList) redoList = [] removeActivityFromList(activityList, 10) undoList.append([ addActivityToList, activityList, personList, Activity(10, [15], None, None, None) ]) assert len(activityList) == 0 undo(undoList, redoList, personList, activityList) assert len(undoList) == 2 and len(redoList) == 1 and len( activityList) == 1 and activityList[0].get_activity_id() == 10 redo(undoList, redoList, personList, activityList) assert len(undoList) == 3 and len(redoList) == 0 and len(activityList) == 0 undo(undoList, redoList, personList, activityList) redoList = []
def populateActivityList(): # Creates a random list of 100 activities activityList = [] numbersList = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] descriptionList = [ 'rugby', 'volleyball', 'basketball', 'football', 'cricket', 'hokey', 'baseball', 'tennis', 'bowling', 'golf' ] for ID in range(1, 101): personIDs = [0, 0, 0] while personIDs[0] == personIDs[1] or personIDs[0] == personIDs[ 2] or personIDs[1] == personIDs[2]: personIDs = [ random.randrange(1, 100), random.randrange(1, 100), random.randrange(1, 100) ] date = random.choice(numbersList[0:3]) + random.choice( numbersList[1:9]) + '.0' + random.choice( numbersList[1:10]) + '.20' + random.choice( numbersList[1:3]) + random.choice(numbersList) time = random.choice(numbersList[:2]) + random.choice( numbersList) + ':' + random.choice( numbersList[0:6]) + random.choice(numbersList) description = random.choice(descriptionList) activityList.append(Activity(ID, personIDs, date, time, description)) return activityList
def test_stringActivityList(): activityList = [] assert stringActivityList(activityList) == 'List of activities is void.' activityList.append(Activity(4, [4, 5], '12.04.2019', '00:10', 'rugby')) assert stringActivityList( activityList ) == 'Activities list:\n4 : [4, 5] : 12.04.2019 : 00:10 : rugby\n'
def test_addActivityToList(): personList = [] personList.append(Person(1, 'Pop_Adrian', '0745739772', 'aleea_Peana_13')) personList.append(Person(2, 'Luca_Iulian', '0743877389', 'aleea_Rucar_2')) personList.append( Person(3, 'Pindelea_Ionela', '0748966321', 'strada_Primaverii_14')) activityList = [] addActivityToList(activityList, personList, Activity(10, [1, 2, 3], '12.04.2019', '10:00', 'golf')) assert len(activityList) == 1 and activityList[0].get_activity_id() == 10
def createActivityList(): activityList = [] activityList.append(Activity(1, [1, 2], '11.11.2018', '16:00', 'rugby')) activityList.append(Activity(2, [2, 8], '10.12.2018', '08:00', 'tennis')) activityList.append( Activity(3, [1, 8, 9, 10], '09.08.2018', '12:30', 'basketball')) activityList.append( Activity(4, [4, 5, 10], '06.01.2019', '14:45', 'football')) activityList.append( Activity(5, [3, 6, 7], '10.01.2019', '16:15', 'swimming')) activityList.append( Activity(6, [2, 3, 4], '20.02.2019', '18:55', 'baseball')) activityList.append( Activity(7, [1, 2, 3, 4, 5, 6, 7, 8, 9], '13.03.2019', '20:30', 'bowling')) activityList.append( Activity(8, [5, 6, 7, 8], '17.01.2019', '22:00', 'football')) activityList.append( Activity(9, [1, 8, 9, 10], '09.11.2018', '23:10', 'tennis')) activityList.append( Activity(10, [4, 5, 8, 9], '14.04.2019', '17:00', 'golf')) return activityList
def readActivitiesFromTextFile(fileName): activityList = [] try: file0 = open(fileName, "r") line = file0.readline().strip().split(":") while not (len(line) == 1 and line[0] == ''): try: activity = Activity(None, None, None, None, None) activity.set_activity_id(int(line[0].strip())) line[1] = line[1].strip() line[1] = line[1][1:(len(line[1]) - 1)].split(",") personsIDs = [] for ID in line[1]: personsIDs.append(int(ID.strip())) activity.set_person_ids(personsIDs) activity.set_date(line[2].strip()) activity.set_time(line[3].strip() + ":" + line[4].strip()) activity.set_description(line[5].strip()) activityList.append(activity) except ValueError as error: print("Could not validate person with id ", line[0].strip(), ": ", error) line = file0.readline().strip().split(":") file0.close() except IOError as error: print("Input error: ", error) return activityList
def test_removeActivityFromList(): activityList = [] activityList.append(Activity(4, [4, 5], '12.04.2019', '00:10', 'rugby')) removeActivityFromList(activityList, 4) assert len(activityList) == 0
def test_findActivityInList(): activityList = [] activityList.append(Activity(4, [4, 5], '12.04.2019', '00:10', 'rugby')) assert findActivityInList(activityList, 4) == 0 assert findActivityInList(activityList, 1) == -1
def readActivity(personList, message): activity = Activity(None, None, None, None, None) while True: try: print(message) activity.set_activity_id(readID('')) activity.set_person_ids(readPersonIDs(personList)) activity.set_date(input('Date (day.month.year): ')) activity.set_time(input('Time (hour:minute): ')) activity.set_description(input('Description: ')) return activity except ValueError as error: print(error)