Beispiel #1
0
    def test_intersection(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')

        assert type(set_A.intersection(set_B)) == list  # should return a list
        assert len(
            set_A.intersection(set_B)) == 2  # Only two element are interscted
        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 elements in return list to be True
        intersection_result = set_A.intersection(set_B)
        assert 'Neymar' in intersection_result
        assert 'Mbappe' in intersection_result

        # Testing elements not in return list to be True
        assert 'Rashford' not in intersection_result
        assert 'Ronaldo' not in intersection_result
        assert 'Deybrune' not in intersection_result
        assert 'Messi' not in intersection_result
Beispiel #2
0
 def test_intersection(self):
     first_set = Sets([1, 2, 3, 6])
     second_set = Sets([1, 2, 3, 4, 5, 7])
     intersection_set = first_set.intersection(second_set)
     assert intersection_set.size == 3
     assert intersection_set.contains(1) == True
     assert intersection_set.contains(2) == True
     assert intersection_set.contains(3) == True
     assert intersection_set.contains(4) == False
     assert intersection_set.contains(5) == False
     assert intersection_set.contains(6) == False
     assert intersection_set.contains(7) == False
Beispiel #3
0
 def test_intersection(self):
     s1 = Sets(['A', 'B', 'C'])
     s2 = Sets(['A', 'B', 'D'])
     intersection_set = s1.intersection(s2)
     self.assertCountEqual(intersection_set.set_struct.keys(), ['A', 'B'])