def test_phone_and_surname(self): c = a1.Contact(surname='world', cp='647-000-1000') self.assertIsNotNone(c, 'Failed to create Contact with surname and cell phone') c = a1.Contact(surname='world', hp='647-000-2000') self.assertIsNotNone(c, 'Failed to create Contact with surname and home phone') c = a1.Contact(surname='world', wp='647-000-3000') self.assertIsNotNone(c, 'Failed to create Contact with surname and work phone')
def test_get_multiple_housemates(self): names = [{'surname': 'Arron', 'name': 'Ben', 'hp': '416-200-3000', 'ha': '1 Loop Dr.'}, {'surname': 'Bell', 'name': 'John', 'hp': '437-000-1000', 'ha': '10 Infinite Loop Dr.'}, {'surname': 'Chan', 'name': 'Joshua', 'hp': '416-200-3000', 'ha': '1 Loop Dr.'}] head, tail, size = build_node_list(names) self.pb_actual._set_list(head, tail, size) actual = self.pb_actual.get_housemate('416-200-3000') self.assertEqual(2, actual.size(), 'Two people share this phone number.') c1 = a1.Contact(surname='Arron', name='Ben', hp='416-200-3000', ha='1 Loop Dr.') c2 = a1.Contact(surname='Chan', name='Joshua', hp='416-200-3000', ha='1 Loop Dr.') self.assertEqual(c1, actual.get_head().get_element(), 'First Contact not the same.') self.assertEqual(c2, actual.get_tail().get_element(), 'Second Contact not the same.')
def test_sublist_multiple_contacts(self): names = [{'surname': 'Arron', 'name': 'Ben', 'hp': '416-200-3000', 'ha': '1 Loop Dr.'}, {'surname': 'Bell', 'name': 'John', 'hp': '437-000-1000', 'ha': '10 Infinite Loop Dr.'}, {'surname': 'Ben', 'name': 'Andrew', 'hp': '416-200-3000', 'ha': '1 Loop Dr.'}] head, tail, size = build_node_list(names) self.pb_actual._set_list(head, tail, size) actual = self.pb_actual.get_sublist('B') self.assertEqual(2, actual.size(), 'Sublist contains 2 contacts') c1 = a1.Contact(surname='Bell', name='John', hp='437-000-1000', ha='10 Infinite Loop Dr.') c2 = a1.Contact(surname='Ben', name='Andrew', hp='416-200-3000', ha='1 Loop Dr.') self.assertEqual(c1, actual.get_head().get_element(), 'First Contact not the same.') self.assertEqual(c2, actual.get_tail().get_element(), 'Second Contact not the same.')
def test_group_remove(self): names_exp = [{'surname': 'Kiwi', 'name': 'Frank', 'cp': '437-222-1890', 'ha': '10 Infinite Loop Dr.'}, {'surname': 'Op', 'name': 'Erica', 'hp': '522-354-1890', 'email': '*****@*****.**', 'ha': '13 Infinite Loop Dr.'}] names_act = [{'name': 'John', 'hp': '437-000-1000', 'fav': True}, {'surname': 'Kiwi', 'name': 'Frank', 'cp': '437-222-1890', 'ha': '10 Infinite Loop Dr.'}, {'surname': 'Larry', 'name': 'Sans', 'wp': '616-000-8501', 'fav': True}, {'surname': 'Op', 'name': 'Erica', 'hp': '522-354-1890', 'email': '*****@*****.**', 'ha': '13 Infinite Loop Dr.'}] head, tail, size = build_node_list(names_exp) self.pb_expect._set_list(head, tail, size) head, tail, size = build_node_list(names_act) self.pb_actual._set_list(head, tail, size) c1 = a1.Contact(name='John', hp='437-000-1000', fav=True) c2 = a1.Contact(surname='Larry', name='Sans', wp='616-000-8501', fav=True) self.pb_actual.group_remove([c1, c2]) self.assertTrue(compare_phonebooks(self.pb_expect, self.pb_actual), 'Rearranged phone books are not the same')
def test_add_to_empty_phonebook(self): c = a1.Contact(surname='Alan', name='Dino', cp='285-000-0010') self.pb_actual.add(c) self.assertEqual(c, self.pb_actual.get_head().get_element(), 'Failed to add one contact. Head node is different') self.assertEqual(c, self.pb_actual.get_tail().get_element(), 'Failed to add one contact. Tail node is different') self.assertEqual(1, self.pb_actual.size(), 'Failed to add one contact. Size is different')
def test_get_one_housemate(self): names = [{'surname': 'Bell', 'name': 'John', 'hp': '437-000-1000', 'ha': '1 Loop Dr.'}, {'surname': 'Chan', 'name': 'Joshua', 'hp': '647-100-2000', 'ha': '20 Loop Dr.'}] head, tail, size = build_node_list(names) self.pb_actual._set_list(head, tail, size) actual = self.pb_actual.get_housemate('437-000-1000') self.assertEqual(1, actual.size(), 'Only one person share this phone number.') c = a1.Contact(surname='Bell', name='John', hp='437-000-1000', ha='1 Loop Dr.') self.assertEqual(c, actual.get_head().get_element(), 'Contact not the same.')
def test_add_same_name_no_surname(self): names_exp = [{'name': 'Edward', 'wp': '437-000-1000'}, {'name': 'edwARD', 'hp': '209-613-7600'}] names_act = [{'name': 'Edward', 'wp': '437-000-1000'}] head, tail, size = build_node_list(names_exp) self.pb_expect._set_list(head, tail, size) head, tail, size = build_node_list(names_act) self.pb_actual._set_list(head, tail, size) self.pb_actual.add(a1.Contact(name='edwARD', hp='209-613-7600')) self.assertTrue(compare_phonebooks(self.pb_expect, self.pb_actual), 'Phone books are not the same')
def test_add_contact_no_surname(self): names_exp = [{'name': 'Allan', 'wp': '519-100-2345'}, {'surname': 'Bell', 'name': 'John', 'wp': '437-000-1000'}, {'surname': 'George', 'name': 'Brown', 'hp': '209-613-7600'}] names_act = [{'surname': 'Bell', 'name': 'John', 'wp': '437-000-1000'}, {'surname': 'George', 'name': 'Brown', 'hp': '209-613-7600'}] head, tail, size = build_node_list(names_exp) self.pb_expect._set_list(head, tail, size) head, tail, size = build_node_list(names_act) self.pb_actual._set_list(head, tail, size) self.pb_actual.add(a1.Contact(name='Allan', wp='519-100-2345')) self.assertTrue(compare_phonebooks(self.pb_expect, self.pb_actual), 'Phone books are not the same')
def test_add_to_head(self): names_exp = [{'surname': 'Alan', 'name': 'Ted', 'cp': '345-790-0001'}, {'surname': 'Bell', 'name': 'John', 'wp': '437-000-1000'}, {'surname': 'Dean', 'name': 'Allan', 'wp': '519-100-2345'}] names_act = [{'surname': 'Bell', 'name': 'John', 'wp': '437-000-1000'}, {'surname': 'Dean', 'name': 'Allan', 'wp': '519-100-2345'}] head, tail, size = build_node_list(names_exp) self.pb_expect._set_list(head, tail, size) head, tail, size = build_node_list(names_act) self.pb_actual._set_list(head, tail, size) self.pb_actual.add(a1.Contact(surname='Alan', name='Ted', cp='345-790-0001')) self.assertTrue(compare_phonebooks(self.pb_expect, self.pb_actual), 'Phone books are not the same')
def test_remove_body(self): names_exp = [{'surname': 'Albert', 'name': 'Edward', 'wp': '437-000-1000'}, {'surname': 'Markus', 'name': 'Word', 'cp': '647-000-1100'}] names_act = [{'surname': 'Albert', 'name': 'Edward', 'wp': '437-000-1000'}, {'surname': 'Amber', 'name': 'Yeti', 'hp': '209-613-7600'}, {'surname': 'Markus', 'name': 'Word', 'cp': '647-000-1100'}] head, tail, size = build_node_list(names_exp) self.pb_expect._set_list(head, tail, size) head, tail, size = build_node_list(names_act) self.pb_actual._set_list(head, tail, size) c = a1.Contact(surname='Amber', name='Yeti', hp='209-613-7600') actual = self.pb_actual.remove(c) self.assertEqual(c, actual, 'Failed to remove from phone book') self.assertEqual(2, self.pb_actual.size(), 'Size incorrect after remove')
def test_remove_not_exist(self): names_exp = [{'surname': 'Albert', 'name': 'Edward', 'wp': '437-000-1000'}, {'surname': 'Amber', 'name': 'Yeti', 'hp': '209-613-7600'}, {'surname': 'Markus', 'name': 'Word', 'cp': '647-000-1100'}] names_act = [{'surname': 'Albert', 'name': 'Edward', 'wp': '437-000-1000'}, {'surname': 'Amber', 'name': 'Yeti', 'hp': '209-613-7600'}, {'surname': 'Markus', 'name': 'Word', 'cp': '647-000-1100'}] head, tail, size = build_node_list(names_exp) self.pb_expect._set_list(head, tail, size) head, tail, size = build_node_list(names_act) self.pb_actual._set_list(head, tail, size) c = a1.Contact(surname='Chan', name='Edward', hp='519-008-2345') actual = self.pb_actual.remove(c) self.assertIsNone(actual, 'Contact does not exist in the phone book') self.assertEqual(3, self.pb_actual.size(), 'Size incorrect after remove')
def build_node_list(name_list: list): head = tail = curr = None for i, d in enumerate(name_list): c = a1.Contact(surname=d['surname'] if d.get('surname', None) else None, name=d['name'] if d.get('name', None) else None, cp=d['cp'] if d.get('cp', None) else None, hp=d['hp'] if d.get('hp', None) else None, wp=d['wp'] if d.get('wp', None) else None, email=d['email'] if d.get('email', None) else None, ha=d['ha'] if d.get('ha', None) else None, fav=d['fav'] if d.get('fav', False) else False) node = a1.Node(c) if i == 0: head = tail = curr = node else: curr.set_next(node) tail = curr = node return head, tail, len(name_list)
import phonebook contact_1 = phonebook.Contact('Василий', 'Иванов', 89213457896, email='*****@*****.**') contact_2 = phonebook.Contact('Пётр', 'Сидоров', 756392, 89213457896, email='*****@*****.**', vk='vk.com/1234455433', home=998877) telephone_book = phonebook.PhoneBook('Новая телефонная книга') telephone_book.add_contact(contact_1) telephone_book.add_contact(contact_2) telephone_book.add_contact('Иван', 'Конюхов', 83246544466, 332211, email='*****@*****.**') telephone_book.add_contact('Unknown', 'number', 88001239090) telephone_book.show_contacts() telephone_book.delete_contact_by_number(88001239090) telephone_book.show_contacts() print('Список избранных номеров:') print(telephone_book.find_all_favorite_numbers()) print()
def test_all_arguments(self): c = a1.Contact(surname='world', name='hello', cp='647-000-1000', hp='647-000-2000', wp='647-000-3000', email='*****@*****.**', ha='1 Infinite loop', fav=True) self.assertIsNotNone(c, 'Failed to create Contact with fulfilled arguments')
def test_init_wp(self): c = a1.Contact(surname='world', name='hello', wp='647-000-1000') self.assertIsNotNone(c, 'Failed to create Contact with name, surname and work phone')
def test_init_with_contact(self): c = a1.Contact(surname='Alex', cp='647-000-1000') pb = a1.PhoneBook(c) self.assertEqual(c, pb.get_head().get_element(), 'Failed to create new Phone book with only one contact') self.assertEqual(c, pb.get_tail().get_element(), 'Failed to create new Phone book with only one contact') self.assertEqual(1, pb.size(), 'Failed to create new Phone book with only one contact')