def test_signModification_1(self): x = hamDb.explicitUnsignCast(5) x = hamDb.explicitSignCast(x) self.assertEqual(x, 5) tgtHash = -6076574518398440533 for hashVal in [data[1] for data in TEST_DATA]: x = hamDb.explicitUnsignCast(hashVal) x = hamDb.explicitSignCast(x) self.assertEqual(hashVal, x)
def test_signModification_2(self): for val in TEST_DATA_FLAT: tgtHash = b2i(val) x = hamDb.explicitUnsignCast(tgtHash) self.assertEqual(x, b2u(val)) x = hamDb.explicitSignCast(x) self.assertEqual(x, tgtHash)
def do_test_queries(self): print("Doing test queries") for x in range(TEST_QUERIES): fk_hash = random.getrandbits(64) fk_hash = hamDb.explicitSignCast(fk_hash) self.tree.getWithinDistance(fk_hash, SEARCH_DIST) print("Test queries complete")
def test_signModification_1(self): self.log.info("test_signModification_1") for val in TEST_DATA_Narrow: tgtHash = b2i(val) x = hamDb.explicitUnsignCast(tgtHash) self.assertEqual(x, b2u(val)) x = hamDb.explicitSignCast(x) self.assertEqual(x, tgtHash)
def test_signModification_3(self): random.seed(500000) for x in range(50000): val = "".join([random.choice(("1", "0")) for z in range(64)]) tgtHash = b2i(val) x = hamDb.explicitUnsignCast(tgtHash) self.assertEqual(x, b2u(val)) x = hamDb.explicitSignCast(x) self.assertEqual(x, tgtHash)
def buildOntoTree(self, tree): # Fix the random ordering so profile results # are sensible random.seed(65413654911) print("Building test-tree with %s nodes" % TREE_ENTRIES) for x in range(TREE_ENTRIES): fk_hash = random.getrandbits(64) fk_hash = hamDb.explicitSignCast(fk_hash) tree.insert(fk_hash, x) if x % 10000 == 0: print("Inserted %s items, %s%% complete" % (x, (x / TREE_ENTRIES * 100))) print("Tree built")
# from cbktree import BkHammingTree, explicitSignCast import unittest import logging import scanner.logSetup as logSetup from bitstring import Bits import pyximport print("Have Cython") pyximport.install() import Tests.baseDbBkTree import deduplicator.cyHamDb as hamDb int_bits = lambda b: hamDb.explicitSignCast(int(b, 2)) TEST_DATA = { # Format: id -> bitstring 1: int_bits('1011010010010110110111111000001000001000100011110001010110111011'), 2: int_bits('1011010010010110110111111000001000000001100011110001010110111011'), 3: int_bits('1101011110100100001011001101001110010011100010011101001000110101'), } SEARCH_DIST = 2 # 2 out of 64 bits class TestBkTreeIssue2(unittest.TestCase): def __init__(self, *args, **kwargs): logSetup.initLogging()
# from cbktree import BkHammingTree, explicitSignCast import pyximport print("Have Cython") pyximport.install() import deduplicator.cyHamDb as hamDb int_bits = lambda b: hamDb.explicitSignCast(int(b, 2)) TEST_DATA = { # Format: id -> bitstring 1: int_bits( '1011010010010110110111111000001000001000100011110001010110111011'), 2: int_bits( '1011010010010110110111111000001000000001100011110001010110111011'), 3: int_bits( '1101011110100100001011001101001110010011100010011101001000110101'), } SEARCH_DIST = 2 # 2 out of 64 bits import unittest import scanner.logSetup as logSetup from bitstring import Bits import pyximport print("Have Cython")
def random_q(self): fk_hash = random.getrandbits(64) fk_hash = hamDb.explicitSignCast(fk_hash) self.tree.getWithinDistance(fk_hash, SEARCH_DIST)