Answered step by step
Verified Expert Solution
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 builtin 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 countduplicates 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 even if the value a was observed three times, we say that a itself has a duplicate thus the count is 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 setUpself None:
The setUp method is a builtin method on unittest that
is called freshly each time you call any of the test methods below.
self.a person.PersonAhmadprimary: 'mobile': "ahmad@institution.edu"
self.a person.PersonAhmadprimary: 'mobile': "ahmad@institution.edu"
self.khaled person.PersonKhalidprimary: 'mobile': "khalid@institution.edu"
self.adifferentkhaled person.PersonKhaledprimary: 'mobile':
"khalid@institution.edu"
def testduplicatesself:
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.
c contacts.Contacts
# only one item in the list, there is no way we have duplicates
cappendselfa
self.assertEqual ccountduplicates
# the same person added, we now should have one duplicate
cappendselfa
self.assertEqual ccountduplicates
# a different instance is added for the same person's information, the duplicate count should stay the same
cappendselfa
self.assertEqual ccountduplicates
# we added a person that we know was never in the list, duplicate count should stay the same
cappendselfkhaled
self.assertEqual ccountduplicates
# we added a person with very close information as with the one above but not really the same.
cappendselfadifferentkhaled
self.assertEqual ccountduplicates
# we added the original instance for Khaled, the count should go up by one.
cappendselfkhaled
self.assertEqual ccountduplicates
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started