Exemplo 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
Exemplo 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)
Exemplo 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)
Exemplo n.º 4
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)
Exemplo n.º 5
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)
Exemplo n.º 6
0
    def test_difference(self):
        ps1 = self.seed_power_set('abcdef', 100, 2)
        ps2 = self.seed_power_set('ghjkl', 100, 2)

        ps = ps1.difference(ps2)
        for val in ps.get_val():
            self.assertEqual(ps1.get(val), True)
            self.assertEqual(ps2.get(val), False)

        ps1 = PowerSet()
        ps2 = self.seed_power_set('ghjkl', 100, 2)
        ps = ps1.difference(ps2)
        self.assertEqual(ps.size(), 0)

        ps1 = self.seed_power_set('ghjkl', 100, 2)
        ps2 = copy.deepcopy(ps1)
        ps = ps1.difference(ps2)
        self.assertEqual(ps.size(), 0)
Exemplo n.º 7
0
    def test_union(self):
        ps1 = self.seed_power_set('abcdef', 100, 2)
        ps2 = self.seed_power_set('ghjkl', 100, 2)

        ps = ps1.union(ps2)
        # print('\n1=', ps1.get_val())
        # print('\n2=', ps2.get_val())
        # print('\n=', ps.get_val())
        for val in ps1.get_val():
            self.assertEqual(ps.get(val), True)
        for val in ps2.get_val():
            self.assertEqual(ps.get(val), True)

        ps1 = self.seed_power_set('abcdef', 100, 2)
        ps2 = PowerSet()
        ps = ps1.union(ps2)
        self.assertEqual(ps1.size(), ps.size())
Exemplo n.º 8
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)
Exemplo n.º 9
0
 def test_powerSetPut(self):
     ps = PowerSet()
     ps.put(1)
     self.assertEqual(ps.size(), 1)
     ps.put(1)
     self.assertEqual(ps.size(), 1)
Exemplo n.º 10
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)
Exemplo n.º 11
0
 def test_powerSetRemoveFromEmptySet(self):
     ps = PowerSet()
     ps.remove(11)
     self.assertEqual(ps.size(), 0)
Exemplo n.º 12
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)
Exemplo n.º 13
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)
Exemplo n.º 14
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)
Exemplo n.º 15
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)
Exemplo n.º 16
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')
Exemplo n.º 17
0
    def test_hash_fun(self):
        ps = PowerSet()

        self.assertEqual(ps.hash_fun('fsdfhxvn980cvnxcbfvjksd'), 12791)
        self.assertEqual(ps.hash_fun('fsdfhxvnxmcvnxcbfvjksd'), 6881)
        self.assertEqual(ps.hash_fun('yery54n77ji'), 5482)
        self.assertEqual(ps.hash_fun('ert43564645'), 2463)
        self.assertEqual(ps.hash_fun('rtbktut'), 18451)
        self.assertEqual(ps.hash_fun('ывспмкенкнк'), 1642)
        self.assertEqual(ps.hash_fun('fsdfhxvnxmcv08905xcbfvjksd'), 17554)
        self.assertEqual(ps.hash_fun('вкс3еме45н5  564  '), 2603)
        self.assertEqual(ps.hash_fun('fsdfhxыапукetxmcvnxcbfvjksd'), 951)
        self.assertEqual(ps.hash_fun('fsdfhxvnxmcvnxc5435sd'), 10532)
        self.assertEqual(ps.hash_fun('fsdfhxvnxm5443nxcbfvjksd'), 7611)
Exemplo n.º 18
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)
Exemplo n.º 19
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)
Exemplo n.º 20
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)
Exemplo n.º 21
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)
Exemplo n.º 22
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)