Ejemplo n.º 1
0
 def seed_power_set(self, str, size, len=10):
     '''
     str = string. may be use 'string.ascii_uppercase + string.digits'
     '''
     ps = PowerSet()
     for _ in range(size + 1):
         ps.put(''.join(random.choices(str, k=len)))
     return ps
Ejemplo n.º 2
0
    def test_powerSetDiffirenceHundredsElements(self):
        ps = PowerSet()
        ps1 = PowerSet()

        for i in range(1, 101):
            ps.put(i)

        for i in range(50, 151):
            ps1.put(i)

        psDiffirence = ps.difference(ps1)
        self.assertEqual(psDiffirence.size(), 49)
Ejemplo n.º 3
0
    def test_powerSetIntersectionHundredsElements(self):
        ps = PowerSet()
        ps1 = PowerSet()

        for i in range(1, 101):
            ps.put(i)

        for i in range(50, 151):
            ps1.put(i)

        psIntersection = ps.intersection(ps1)
        self.assertEqual(psIntersection.size(), 51)
Ejemplo n.º 4
0
    def test_powerSetDifferenceManyElements(self):
        ps = PowerSet()
        for i in range(1, 10001):
            ps.put(i)

        ps1 = PowerSet()
        for i in range(9900, 20001):
            ps1.put(i)

        start_time = time.time()
        psDiffirence = ps.difference(ps1)
        self.assertEqual(psDiffirence.size(), 9899)
        print('time to processing', time.time() - start_time)
Ejemplo n.º 5
0
    def test_powerSetIntersectionManyElements(self):
        ps = PowerSet()
        ps1 = PowerSet()
        for i in range(1, 10001):
            ps.put(i)

        for i in range(9900, 20001):
            ps1.put(i)

        start_time = time.time()
        psIntersection = ps.intersection(ps1)
        self.assertEqual(psIntersection.size(), 101)
        print('time to processing', time.time() - start_time)
Ejemplo n.º 6
0
    def test_get(self):
        ps = PowerSet()

        self.assertEqual(ps.get('abc'), False)

        ps.put('abc')
        ps.put('def')
        ps.put('ghx')
        ps.put('cvb')

        self.assertEqual(ps.get('abc'), True)
        self.assertEqual(ps.get('abc1'), False)
        self.assertEqual(ps.get('def'), True)
        self.assertEqual(ps.get('ghx'), True)
        self.assertEqual(ps.get('cvb'), True)
Ejemplo n.º 7
0
    def test_powerSetIntersectionEmpty(self):
        ps = PowerSet()
        ps1 = PowerSet()
        ps1.put(-5)
        ps1.put(9)
        ps1.put(1)
        ps1.put(11)
        ps1.put(131)
        psIntersection = ps.intersection(ps1)
        self.assertEqual(psIntersection.size(), 0)

        ps1 = PowerSet()
        psIntersection = ps.intersection(ps1)
        self.assertEqual(psIntersection.size(), 0)
Ejemplo n.º 8
0
    def test_issubset(self):
        ps1 = PowerSet()
        ps1.put('abc')
        ps1.put('def')
        ps1.put('ghx')
        ps1.put('cvb')

        ps2 = PowerSet()
        self.assertEqual(ps1.issubset(ps2), True)

        ps2.put('abc')
        self.assertEqual(ps1.issubset(ps2), True)

        ps2 = copy.deepcopy(ps1)
        self.assertEqual(ps1.issubset(ps2), True)

        ps2.put('ppp')
        self.assertEqual(ps1.issubset(ps2), False)
Ejemplo n.º 9
0
 def test_powerSetRemove(self):
     ps = PowerSet()
     ps.put(1)
     ps.put(-5)
     ps.put(13)
     ps.put(0)
     ps.put(4)
     self.assertEqual(ps.size(), 5)
     ps.remove(-5)
     self.assertEqual(ps.size(), 4)
     ps.remove(-5)
     self.assertEqual(ps.size(), 4)
Ejemplo n.º 10
0
 def test_powerSetPutRemove(self):
     ps = PowerSet()
     ps.put(1)
     self.assertEqual(ps.size(), 1)
     ps.put(-11)
     self.assertEqual(ps.size(), 2)
     ps.remove(18)
     self.assertEqual(ps.size(), 2)
     ps.put(12)
     ps.put(-4)
     self.assertEqual(ps.size(), 4)
     ps.remove(12)
     self.assertEqual(ps.size(), 3)
Ejemplo n.º 11
0
    def test_remove(self):
        ps = PowerSet()
        ps.put('abc')
        ps.put('def')
        ps.put('ghx')
        ps.put('cvb')

        self.assertEqual(ps.get('abc'), True)
        self.assertEqual(ps.get('def'), True)
        self.assertEqual(ps.get('ghx'), True)
        self.assertEqual(ps.get('cvb'), True)

        self.assertEqual(ps.remove('abc'), True)
        self.assertEqual(ps.get('abc'), False)
        self.assertEqual(ps.size(), 3)

        self.assertEqual(ps.remove('abc1'), False)
        self.assertEqual(ps.size(), 3)

        self.assertEqual(ps.remove('abc'), False)
        self.assertEqual(ps.size(), 3)

        self.assertEqual(ps.remove('def'), True)
        self.assertEqual(ps.get('def'), False)
        self.assertEqual(ps.size(), 2)

        self.assertEqual(ps.remove('ghx'), True)
        self.assertEqual(ps.get('ghx'), False)
        self.assertEqual(ps.size(), 1)

        self.assertEqual(ps.remove('cvb'), True)
        self.assertEqual(ps.get('cvb'), False)
        self.assertEqual(ps.size(), 0)

        self.assertEqual(ps.remove('111111'), False)
        self.assertEqual(ps.size(), 0)

        ps.put('cvb')
        self.assertEqual(ps.remove('cvb'), True)
        self.assertEqual(ps.get('cvb'), False)
        self.assertEqual(ps.size(), 0)
Ejemplo n.º 12
0
    def test_powerSetIntersection(self):
        ps = PowerSet()
        ps.put(1)
        ps.put(-5)
        ps.put(13)
        ps.put(0)
        ps.put(4)
        ps.put(9)
        ps.put(92)
        ps.put(131)
        ps.put(11)
        ps.put(18)

        ps1 = PowerSet()
        ps1.put(-5)
        ps1.put(9)
        ps1.put(1)
        ps1.put(11)
        ps1.put(131)
        psIntersection = ps.intersection(ps1)
        self.assertEqual(psIntersection.size(), 5)

        ps1 = PowerSet()
        ps1.put(-5)
        psIntersection = ps.intersection(ps1)
        self.assertEqual(psIntersection.size(), 1)

        ps1 = PowerSet()
        ps1.put(999)
        ps1.put(1000)
        ps1.put(111)
        ps1.put(22222)
        psIntersection = ps.intersection(ps1)
        self.assertEqual(psIntersection.size(), 0)

        ps1 = PowerSet()
        psIntersection = ps.intersection(ps1)
        self.assertEqual(psIntersection.size(), 0)
Ejemplo n.º 13
0
    def test_powerSetIssubsetNotAll1(self):
        ps = PowerSet()
        ps.put(1)
        ps.put(-5)
        ps.put(13)
        ps.put(0)
        ps.put(4)
        ps.put(9)
        ps.put(92)
        ps.put(131)
        ps.put(11)
        ps.put(18)
        ps.put(28)
        ps.put(-11)
        ps.put(999)

        ps1 = PowerSet()
        ps1.put(1)
        ps1.put(-5)
        ps1.put(13)
        ps1.put(0)
        ps1.put(4)
        ps1.put(9)
        ps1.put(92)
        ps1.put(131)
        ps1.put(11)
        ps1.put(18)
        ps1.put(55)
        ps1.put(888)

        psIssubset = ps.issubset(ps1)
        self.assertEqual(psIssubset, False)
Ejemplo n.º 14
0
 def test_powerSetPut(self):
     ps = PowerSet()
     ps.put(1)
     self.assertEqual(ps.size(), 1)
     ps.put(1)
     self.assertEqual(ps.size(), 1)
Ejemplo n.º 15
0
    def test_powerSetIssubsetAll(self):
        ps = PowerSet()
        ps.put(1)
        ps.put(-5)
        ps.put(13)
        ps.put(0)
        ps.put(4)
        ps.put(9)
        ps.put(92)
        ps.put(131)
        ps.put(11)
        ps.put(18)

        ps1 = PowerSet()
        ps1.put(1)
        ps1.put(-5)
        ps1.put(13)
        ps1.put(0)
        ps1.put(4)
        ps1.put(9)
        ps1.put(92)
        ps1.put(131)
        ps1.put(11)
        ps1.put(18)

        psIssubset = ps.issubset(ps1)
        self.assertEqual(psIssubset, True)
Ejemplo n.º 16
0
    def test_powerSetDiffirence(self):
        ps = PowerSet()
        ps.put(1)
        ps.put(-5)
        ps.put(13)
        ps.put(0)
        ps.put(4)
        ps.put(9)
        ps.put(92)
        ps.put(131)
        ps.put(11)
        ps.put(18)

        ps1 = PowerSet()
        ps1.put(1)
        ps1.put(-5)
        ps1.put(13)
        ps1.put(0)
        ps1.put(4)
        ps1.put(9)
        ps1.put(92)
        ps1.put(131)
        ps1.put(11)
        ps1.put(18)
        psDiffirence = ps.difference(ps1)
        self.assertEqual(psDiffirence.size(), 0)

        ps1 = PowerSet()
        ps1.put(1)
        ps1.put(-5)
        ps1.put(13)
        ps1.put(0)
        ps1.put(4)
        ps1.put(9)
        ps1.put(92)
        ps1.put(131)
        ps1.put(11)
        psDiffirence = ps.difference(ps1)
        self.assertEqual(psDiffirence.size(), 1)
Ejemplo n.º 17
0
    def test_powerSetUnion(self):
        ps = PowerSet()
        ps.put(1)
        ps.put(-5)
        ps.put(13)
        ps.put(0)
        ps.put(4)
        ps.put(9)
        ps.put(92)
        ps.put(131)
        ps.put(11)
        ps.put(18)

        ps1 = PowerSet()
        ps1.put(99)
        ps1.put(18)
        ps1.put(35)
        psUnion = ps.union(ps1)
        self.assertEqual(psUnion.size(), 12)

        ps1 = PowerSet()
        psUnion = ps.union(ps1)
        self.assertEqual(psUnion.size(), 10)

        ps = PowerSet()
        ps1.put(1)
        ps1.put(-5)
        ps1.put(13)
        ps1.put(0)
        ps1.put(4)
        ps1.put(9)
        ps1.put(92)
        ps1.put(131)
        ps1.put(11)
        ps1.put(18)
        psUnion = ps.union(ps1)
        self.assertEqual(psUnion.size(), 10)
Ejemplo n.º 18
0
    def test_put(self):
        ps = PowerSet()

        ps.put('abc')
        self.assertEqual(ps.size(), 1)

        ps.put('def')
        self.assertEqual(ps.size(), 2)

        ps.put('abc')
        self.assertEqual(ps.size(), 2)

        ps.put('abc')
        self.assertEqual(ps.size(), 2)

        ps.put('abc')
        self.assertEqual(ps.size(), 2)

        ps.put('naeekbnhha')
        self.assertEqual(ps.size(), 3)
        ps.put('fkmmeilabl')  # slot is buzy
        self.assertEqual(ps.size(), 4)

        ps.put('pqbpdmhdkc')
        self.assertEqual(ps.size(), 5)
        ps.put('fnlmmnckdl')  # slot is buzy
        self.assertEqual(ps.size(), 6)

        # print('\n', ps.get_slots())
        slots = ps.get_slots()
        self.assertEqual(slots[13262], 'naeekbnhha')
        self.assertEqual(slots[13295], 'fkmmeilabl')
        self.assertEqual(slots[14490], 'pqbpdmhdkc')
        self.assertEqual(slots[14523], 'fnlmmnckdl')