예제 #1
0
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>"
예제 #2
0
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)))
예제 #3
0
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>"
예제 #4
0
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>"
예제 #5
0
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
예제 #6
0
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
예제 #7
0
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")
예제 #8
0
 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)))
예제 #9
0
 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)))
예제 #10
0
def test_len_nonempty():
    """S7: Len of nonempty set"""
    s1 = OurSet()
    s1.add_list([1, 2, 3])
    assert len(s1) == 3
예제 #11
0
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>"