Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Start implementing and testing the Contacts class. The Contacts should extend the built - in list class. Otherwise, you would have to implement all the

Start implementing and testing the Contacts class. The Contacts should extend the built-in list class. Otherwise, you would have to implement all the methods already provided by list.
The Contacts class should NOT have an initializer. That is, it uses its parent initializer.
A method you have to add, however, is the count_duplicates method which takes only self as an argument and returns an integer. This will be highly dependent on your correct implementation of Person.__eq__(). The count duplicate (as given by the name) should count how many of its elements are the same. For example, if we have the list [a, b, a, a], the count of duplicates is 1(even if the value a was observed three times, we say that a itself has a duplicate thus the count is 1). In your case, you will be considering a person's object instead of the letters a or b.
count duplicate should work in this test case
def setUp(self)-> None:
"""The setUp method is a built-in method on unittest that
is called freshly each time you call any of the test methods below.
"""
self.a1= person.Person("Ahmad",{'primary': 123456789, 'mobile': 223344556}, "ahmad@institution.edu")
self.a2= person.Person("Ahmad",{'primary': 123456789, 'mobile': 223344556}, "ahmad@institution.edu")
self.khaled = person.Person("Khalid",{'primary': 91919191, 'mobile': 102030405}, "khalid@institution.edu")
self.a_different_khaled = person.Person("Khaled",{'primary': 91919191, 'mobile': 102030405},
"khalid@institution.edu")
def test_duplicates(self):
"""Test if two elements in contacts are duplicates. This also depends on
the equality check for Person. However, it also depends on how you define
duplicates in Contact as the method is not inherited from list.
"""
c1= contacts.Contacts()
# only one item in the list, there is no way we have duplicates
c1.append(self.a1)
self.assertEqual(0, c1.count_duplicates())
# the same person added, we now should have one duplicate
c1.append(self.a1)
self.assertEqual(1, c1.count_duplicates())
# a different instance is added for the same person's information, the duplicate count should stay the same
c1.append(self.a2)
self.assertEqual(1, c1.count_duplicates())
# we added a person that we know was never in the list, duplicate count should stay the same
c1.append(self.khaled)
self.assertEqual(1, c1.count_duplicates())
# we added a person with very close information as with the one above but not really the same.
c1.append(self.a_different_khaled)
self.assertEqual(1, c1.count_duplicates())
# we added the original instance for Khaled, the count should go up by one.
c1.append(self.khaled)
self.assertEqual(2, c1.count_duplicates())

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analytics And Quality Management Fundamental Tools

Authors: Joseph Nguyen

1st Edition

B0CNGG3Y2W, 979-8862833232

More Books

Students also viewed these Databases questions