Exemplo n.º 1
0
    def test_put(self):
        s = PowerSet()

        s.put('One')
        self.assertEqual(s.get('One'), True)
        s.put('One')
        self.assertEqual(s.get('One'), True)
Exemplo n.º 2
0
    def test_remove(self):
        s = PowerSet()

        s.put('One')

        self.assertEqual(s.get('One'), True)

        s.remove('One')

        self.assertEqual(s.get('One'), False)
Exemplo n.º 3
0
    def test_intersection_non_empty(self):
        s = PowerSet()
        s2 = PowerSet()

        s.put('One')
        s.put('Two')
        s.put('Three')

        s2.put('One')
        s2.put('Five')
        s2.put('Six')

        result = s.intersection(s2)

        self.assertEqual(result.size(), 1)
Exemplo n.º 4
0
    def test_difference_empty(self):
        s = PowerSet()
        s2 = PowerSet()

        s.put('One')
        s.put('Two')
        s.put('Three')

        s2.put('One')
        s2.put('Two')
        s2.put('Three')

        result = s.difference(s2)

        self.assertEqual(result.size(), 0)
Exemplo n.º 5
0
    def test_union(self):
        s = PowerSet()
        s2 = PowerSet()

        s.put('One')
        s.put('Two')
        s.put('Three')

        s2.put('Four')
        s2.put('Five')
        s2.put('Six')

        result = s.union(s2)

        self.assertEqual(result.size(), 6)
Exemplo n.º 6
0
    def test_issubset(self):
        s = PowerSet()
        s2 = PowerSet()
        s3 = PowerSet()

        s.put('One')
        s.put('Two')
        s.put('Three')

        s2.put('One')
        s2.put('Two')

        s3.put('Four')
        s3.put('Five')

        self.assertEqual(s.issubset(s2), True)
        self.assertEqual(s.issubset(s3), False)
class TestPowerSet(unittest.TestCase):
    def setUp(self):
        self.set_1 = PowerSet()
        self.set_1.put("AA")
        self.set_1.put("Bc")
        self.set_1.put("dE")
        self.set_1.put("eD")

        self.set_2 = PowerSet()
        self.set_2.put("AA")
        self.set_2.put("BB")
        self.set_2.put("dE")
        self.set_2.put("DD")

    def test_put(self):
        self.set_1 = PowerSet()
        self.assertEqual(self.set_1.slots,
                         [None, None, None, None, None, None, None])
        self.set_1.put("AA")
        self.set_1.put("Bc")
        self.set_1.put("dE")
        self.set_1.put("eD")
        self.assertEqual(
            self.set_1.slots,
            [None, ['dE', 'eD'], None, None, ['AA', 'Bc'], None, None])
        self.set_1.put("AA")
        self.set_1.put("Bc")
        self.set_1.put("dE")
        self.set_1.put("eD")
        self.assertEqual(
            self.set_1.slots,
            [None, ['dE', 'eD'], None, None, ['AA', 'Bc'], None, None])

    def test_size(self):
        self.assertEqual(self.set_1.size(), 4)

    def test_remove(self):
        self.set_1.remove("Bc")
        self.assertEqual(self.set_1.slots,
                         [None, ['dE', 'eD'], None, None, ['AA'], None, None])

    def test_intersection(self):
        self.assertEqual(
            self.set_1.intersection(self.set_2).slots,
            [None, ['dE'], None, None, ['AA'], None, None])

        self.set_2 = PowerSet()
        self.set_2.put('EE')
        self.set_2.put('DD')
        self.assertEqual(
            self.set_1.intersection(self.set_2).slots,
            [None, None, None, None, None, None, None])

        self.set_2 = PowerSet()
        self.assertEqual(
            self.set_1.intersection(self.set_2).slots,
            [None, None, None, None, None, None, None])

    def test_union(self):
        self.assertEqual(
            self.set_1.union(self.set_2).slots,
            [None, ['dE', 'eD'], None, ['DD'], ['AA', 'Bc'], None, ['BB']])

        self.set_2 = PowerSet()
        self.assertEqual(
            self.set_1.union(self.set_2).slots,
            [None, ['dE', 'eD'], None, None, ['AA', 'Bc'], None, None])

        self.set_1 = PowerSet()

        self.set_2 = PowerSet()
        self.set_2.put("AA")
        self.set_2.put("Bc")
        self.set_2.put("dE")
        self.set_2.put("eD")
        self.assertEqual(
            self.set_1.union(self.set_2).slots,
            [None, ['dE', 'eD'], None, None, ['AA', 'Bc'], None, None])

    def test_difference(self):
        self.assertEqual(
            self.set_1.difference(self.set_2).slots,
            [None, ['eD'], None, None, ['Bc'], None, None])

    def test_issubset(self):
        self.assertEqual(self.set_1.issubset(self.set_2), False)

        self.set_3 = PowerSet()
        self.set_3.put("AA")
        self.set_3.put("dE")
        self.assertEqual(self.set_1.issubset(self.set_3), True)