12. Data Structures
Feel free to use your laptop
You are strongly encourage to work with others
When you get stuck, ask those sitting around you for help
Get used to working together in the labs
Peer teaching and peer learning has been empirically shown to be very effective
12.1. Pre Lab Exercises
Have all classes from the previous lab complete
-
6
Write unit tests for the class
Writing tests for collections can be difficult, so do your best
Use the CountryCatalogueTest class as an example from assignment 4.
12.2. Before Kattis
Have a complete
Personclass from the previous labWrite a
Contactsclass that will manage a collection ofPersonobjectsThe class will keep track of many instances of
PersonobjectsA method for getting the
size()of theContactsNo duplicate/equivalent
Personobjects are allowed to be in the collectionA method for adding a
Personto theContactscalledaddthat takes aPersonas a parameterIf someone tries to
adda duplicate/equivalentPerson, the method shouldraiseaValueError
A method to remove a
Personcalledremovethat takes aPersonas a parameter (the one to be removed)If someone tries to
removea nonexistentPerson, the method shouldraiseaValueError
A
__repr__that returns a string containing the details of allPersonobjectsBe sure to make use of the
Personclass’__repr__method
Make an instance of the class, add/remove
Personobjects to it, and writeasserttests to verify correctness
Create unittest classes for the
ContactsclassWrite tests for each of the methods in each class
You may find the
Courseclass’unittests helpfulRun the tests with
unittest.main(argv=[''], verbosity=2, exit=False)Ensure all tests pass
12.3. Kattis Problems
Go back and work on Kattis problems from previous labs that you have yet to solve. I’m betting there are several of the earlier ones you can revisit and solve. Remember, the Kattis problems are great for practice, and practice is the only way to get better at programming.