def test_updatePersonInList(): personList = [] personList.append( Person(1, 'Pascan_Adrian', '0745711455', 'Aleea_Trandafirilor_1')) updatePersonInList( personList, [], 1, Person(3, 'Pindelea_Ionela', '0748966321', 'strada_Primaverii_14')) assert len(personList) == 1 and personList[0].get_id() == 3
def test_searchPersonInList(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')) matchingList = searchPersonInList(personList, 'an') assert len(matchingList) == 2 and matchingList[0].get_id() == 1 matchingList = searchPersonInList(personList, '66321') assert len(matchingList) == 1 and matchingList[0].get_id() == 3
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_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 readPerson(message): person = Person(None, None, None, None) while True: try: print(message) person.set_id(readID('')) person.set_name( input('Name (LastName_FirstName1-FirstName2-...): ')) person.set_phone_number(input('Phone number (0xxxxxxxxx): ')) person.set_address(input('Address: ')) return person except ValueError as error: print(error)
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 createPersonList(): personList = [] personList.append(Person(1, 'Pop_Adrian', '0745739772', 'Peana 13')) personList.append(Person(2, 'Luca_Iulian', '0743877389', 'Rucar 2')) personList.append( Person(3, 'Pindelea_Ionela', '0748966321', 'Primaverii 14')) personList.append(Person(4, 'Ignat_Olga', '0714243435', 'Motilor 78')) personList.append(Person(5, 'Cioata_Viorel', '0741235896', 'Zorilor 8')) personList.append(Person(6, 'Nituca_Razvan', '0741725869', 'Campului 105')) personList.append(Person(7, 'Florea_Raluca', '0796855875', 'Traian 52')) personList.append(Person(8, 'Todasca_Rebeca', '0722568696', 'Baladei 47')) personList.append( Person(9, 'Pascanu_Mircea', '0733002001', 'Dostoievski 21')) personList.append( Person(10, 'Lerda_Maricica', '0758693210', 'Repulicii 140')) return personList
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_stringPersonList(): personList = [] assert stringPersonList(personList) == 'List of people is void.' personList.append( Person(1, 'Pascan_Adrian', '0745711455', 'Aleea_Trandafirilor_1')) assert stringPersonList( personList ) == 'Person list:\n1 : Pascan_Adrian : 0745711455 : Aleea_Trandafirilor_1\n'
def readPersonsFromTextFile(fileName): personList = [] try: file0 = open(fileName, "r") line = file0.readline().strip().split(":") while not (len(line) == 1 and line[0] == ''): try: person = Person(None, None, None, None) person.set_id(int(line[0].strip())) person.set_name(line[1].strip()) person.set_phone_number(line[2].strip()) person.set_address(line[3].strip()) personList.append(person) 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 personList
def populatePersonList(): # Creates a random list of 100 persons personList = [] lastNameList = [ 'Popescu', 'Aelenei', 'Iuga', 'Pascan', 'Bulai', 'Candrea', 'Doroftiese', 'Morosanu', 'Danea', 'Florea' ] firstNameList = [ 'Adrian', 'Diana', 'Ruxandra', 'Olga', 'Maricica', 'Mircea', 'Luca', 'Ciprian', 'Bogdan', 'Iulian' ] numbersList = ['48', '75', '14', '10', '99', '66', '70', '39', '00', '55'] addressList = [['Trandafirilor', 'Peana', 'Kogalniceanu', 'Primaverii', 'Petreni', 'Transilvaniei', 'Chilia', 'Oltului', 'Rucar', 'Islazului'],\ ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '']] for ID in range(1, 101): name = random.choice(lastNameList) + '_' + random.choice(firstNameList) phoneNumber = '07' + random.choice(numbersList) + random.choice( numbersList) + random.choice(numbersList) + random.choice( numbersList) address = random.choice(addressList[0]) + ' ' + random.choice( addressList[1][1:10]) + random.choice(addressList[1]) personList.append(Person(ID, name, phoneNumber, address)) return personList
def test_removePersonFromList(): personList = [] personList.append( Person(1, 'Pascan_Adrian', '0745711455', 'Aleea_Trandafirilor_1')) removePersonFromList(personList, [], 1) assert len(personList) == 0
def test_addPersonInList(): personList = [] addPersonToList( personList, Person(11, 'Pop_Magdalena', '0745555100', 'Strada_Camplului_5'), []) assert len(personList) == 1 and personList[0].get_id() == 11
def test_findPersonInList(): personList = [] personList.append( Person(1, 'Pascan_Adrian', '0745711455', 'Aleea_Trandafirilor_1')) assert findPersonInList(personList, 1) == 0 assert findPersonInList(personList, 9) == -1