Ourset: A Simple Set Adt in Python

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

CS 3240 - S21 / Guided Practice E: Test Cases

Computing ID Name

rpr6at Ryan Robinson(Partner 0)

sgf2yjh Scott Freeman

jd3pgy Jason Deng

With your partners, look at the methods from the API below and fill out the test plan on the next page. Discuss
your answers as you all work through the exercise.

OurSet: a simple set ADT in Python


● add(self, item) - If the parameter to this method is not already in the set
object, add it to the set. Return True or False to indicate if the item was added to
the set.
● union(self, set2) - Carry out a set-union operation between the current
set object and the parameter. Return the union as the return value. Do not modify
the current set object or the parameter.
● intersection(self, set2) - Carry out a set-intersection operation
between the current set object and the parameter. Return the intersection as the
return value. Do not modify the current set object or the parameter.

Methods that exist but you cannot write tests for in this exercise:

● __len__(self) - Returns the number of items in the set object. Called as


follows: len(some_set)
● __contains__(self)- Returns true if the item is in the set object. Called
as follows: item in set
Test Case Test Description Expected Results
Type ID

Equivalence 0 Take a set and add an object that’s not already in the Function should return
(add) set. true and the object
should be added to the
set

Boundary 1 Take a set and an object that is already contained Function should return
(add) within that set. false and object should
not be added to the set
again

Equivalence Take a known set and divide it into two smaller sets. The returned set from the
(union) Compute the union operation between the smaller union function should be
2 sets and compare to the original set. equivalent to the original
large set.

Boundary Input two sets that are exactly the same. Function should return
(union) 3 union of these sets
without altering either of
them.

Boundary 4 Input two sets where one of the sets is a subset of Function should identify
(union) the other. the larger set and return
that one without altering
either of them.

Equivalence Take a known set and create two versions of it with Function should return a
(intersect 5 different additional values. Compute the intersection set equivalent to the
ion) function on the two new versions of the known set original known set
and compare to the original known set.

Boundary Input two sets that have no common values Function should return a
(intersect set that is empty without
ion) 6 altering either of original
sets.

Boundary Input two sets that are exactly the same Function should return
(intersect either of the sets without
ion) 7 altering them.

Exception Input a set and an object that is not a set Function should catch
(union) the exception and tell the
8 user not to input not-set
objects.

You might also like