def test_addlist_nonempty_dup(): """S5: Add list to nonempty""" s1 = OurSet() s1.add_list([2, 3, 4]) s1.add_list([1, 2, 3]) assert len(s1) == 4 assert str(s1) == "<2,3,4,1>"
def test_add_non_duplicate(): """ 3: Add non-duplicate value to set """ s = OurSet() res = s.add(5) res = s.add(6) assert len(s) == 2 assert res == True
def test_add_duplicate(): """ 2: Add duplicate value to set """ s = OurSet() res = s.add(5) res = s.add(5) assert len(s) == 1 assert res == False
def test_addList_non_duplicate(): """ 5: Add list containing some non-duplicate values to set """ s = OurSet() res = s.add(5) res = s.add(6) res = s.add_list([3, 2, 5]) assert len(s) == 4 assert res == True
def test_addList_duplicate(): """ 4: Add list containing only duplicate values to set """ s = OurSet() res = s.add(5) res = s.add(6) res = s.add_list([5, 6]) assert len(s) == 2 assert res == False
class TestSet1(unittest.TestCase): def setUp(self): self.emptySet = OurSet() self.s1 = OurSet() self.s1.add_list([1,2,3]) def test_union_nonempty_with_empty(self): """S8: Union of nonempty with empty""" self.assertEqual(len(self.s1), len(self.s1.union(self.emptySet))) def test_union_two_nonempty(self): """S9: Union of two nonempty with overlap""" s2 = OurSet() s2.add_list([2,3,4]) self.assertEqual(4,len(s2.union(self.s1))) def test_intersect_empty_nonempty(self): """S10: Intersect empty with nonempty""" self.assertEqual(0,len(self.s1.intersection(self.emptySet))) def test_intersect_two_nonempty(self): """S11: Intersect two nonempty with some overlap""" self.s1.add(4) s2 = OurSet() s2.add_list([3,4,5,6]) self.assertEqual(2, len(self.s1.intersection(s2)))
def test_add_nonempty_dup(): """S2: Add duplicate item to nonempty set """ s1 = OurSet() s1.add_list([1, 2, 3]) s1.add(1) assert len(s1) == 3 assert str(s1) == "<1,2,3>"
def test_add_nonempty(): """S3: Add unique item to nonempty""" s1 = OurSet() s1.add_list([2, 3]) s1.add(1) assert len(s1) == 3 assert str(s1) == "<2,3,1>"
class TestSet(unittest.TestCase): def setUp(self): self.s1 = OurSet() self.s1.add_list([1, 3, 5, 7, 9]) self.s2 = OurSet() self.s2.add_list([1, 2, 3, 4, 5]) def test_union(self): """ 8: union """ out1 = self.s1.union(self.s2) self.assertEqual(len(out1), 7, "Union didn't have the correct number of items") def test_intersect(self): """ 9: intersection """ out2 = self.s1.intersection(self.s2) self.assertEqual(len(out2), 3, "Intersect didn't have the correct number of items")
def setUp(self): self.emptySet = OurSet() self.s1 = OurSet() self.s1.add_list([1,2,3])
def test_addlist_empty(): """S4: Add list to empty""" s1 = OurSet() s1.add_list([1, 2, 3]) assert len(s1) == 3 assert str(s1) == "<1,2,3>"
def test_intersect_two_nonempty(self): """S11: Intersect two nonempty with some overlap""" self.s1.add(4) s2 = OurSet() s2.add_list([3,4,5,6]) self.assertEqual(2, len(self.s1.intersection(s2)))
def test_union_two_nonempty(self): """S9: Union of two nonempty with overlap""" s2 = OurSet() s2.add_list([2,3,4]) self.assertEqual(4,len(s2.union(self.s1)))
def setUp(self): self.s1 = OurSet() self.s1.add_list([1, 3, 5, 7, 9]) self.s2 = OurSet() self.s2.add_list([1, 2, 3, 4, 5])
def test_len_non_empty_set(): """ 7: Length of non-empty set """ s = OurSet() s.add(5) assert len(s) == 1
def test_len_empty_set(): """ 6: Length of empty set """ s = OurSet() assert len(s) == 0
def test_add_empty(): """S1: Add item to empty set""" s1 = OurSet() s1.add(1) assert len(s1) == 1 assert str(s1) == "<1>"
def test_add_empty_set(): """ 1: Add value to empty set """ s = OurSet() res = s.add(5) assert len(s) == 1 assert res == True
def test_len_empty(): """S6: Len of empty set""" s1 = OurSet() assert len(s1) == 0
def test_len_nonempty(): """S7: Len of nonempty set""" s1 = OurSet() s1.add_list([1, 2, 3]) assert len(s1) == 3