Ejemplo n.º 1
0
    def test_difference(self):
        set_A = Sets()
        set_B = Sets()

        set_A.add('Ronaldo')
        set_A.add('Mbappe')
        set_A.add('Neymar')
        set_A.add('Messi')

        set_B.add('Rashford')
        set_B.add('Mbappe')
        set_B.add('Neymar')
        set_B.add('DeBruyne')

        difference_result = set_A.difference(set_B)
        assert type(difference_result) == list  # should return a list
        assert set_A.size == 4  # set A should retain its original size
        assert set_B.size == 4  # set B should retain its original size

        # Testing for Element in SET A not in SET B
        assert 'Ronaldo' in difference_result
        assert 'Messi' in difference_result

        # Testing intersecting elements are not in the difference
        assert 'Neymar' not in difference_result
        assert 'Mbappe' not in difference_result

        # Testing for Element in SET B not in SET A
        difference_result = set_B.difference(set_A)
        assert 'DeBruyne' in difference_result
        assert 'Rashford' in difference_result
Ejemplo n.º 2
0
 def test_difference(self):
     first_set = Sets([2, 3, 4, 5, 6])
     second_set = Sets([1, 2, 3, 4])
     difference_set = first_set.difference(second_set)
     assert difference_set.size == 2
     assert difference_set.contains(5) == True
     assert difference_set.contains(6) == True
     assert difference_set.contains(1) == False
     assert difference_set.contains(2) == False
     assert difference_set.contains(3) == False
     assert difference_set.contains(4) == False
Ejemplo n.º 3
0
    def test_difference(self):
        s1 = Sets(['A', 'B', 'C', 'D'])
        s2 = Sets(['A', 'B', 'C', 'D', 'E'])
        new_set = s1.difference(s2)
        self.assertCountEqual(new_set.set_struct.keys(), [])

        s1 = Sets(['A', 'B', 'C', 'D'])
        s2 = Sets(['A', 'B', 'C', 'D', 'E'])
        new_set = s2.difference(s1)
        self.assertCountEqual(new_set.set_struct.keys(), ['E'])

        s1 = Sets(['A', 'B', 'C'])
        s2 = Sets(['B', 'C', 'D'])
        new_set = s1.difference(s2)
        self.assertCountEqual(new_set.set_struct.keys(), ['A'])

        s1 = Sets(['A', 'B', 'C'])
        s2 = Sets(['D', 'E', 'F'])
        new_set = s1.difference(s2)
        self.assertCountEqual(new_set.set_struct.keys(), ['A', 'B', 'C'])