Example #1
0
 def setUp(self):
     self.trie = CharTrie()
     #some dummy values
     self.trie.add("a")
     self.trie.add("b", "c")
Example #2
0
class TestCharTrieBasicFunctions(unittest.TestCase):
    def setUp(self):
        self.trie = CharTrie()
        #some dummy values
        self.trie.add("a")
        self.trie.add("b", "c")

    def test_add(self):
        self.trie.add("justkey")
        self.trie.add("key", "val")
        self.trie.add("key2", "val2")

    def test_get(self):
        s = self.trie.get("a")
        self.assertTrue(self.trie.get("a") == None)
        self.assertTrue(self.trie.get("Z") == None)
        self.trie.add("ZZ")
        self.assertTrue(self.trie.get("Z") == None)
        self.assertTrue(self.trie.get("b") == 'c')

    def test_autocomp(self):
        self.assertTrue(self.trie.autocomp("b") == 'b:c,')
Example #3
0
 def setUp(self):
   self.trie = CharTrie()
   #some dummy values
   self.trie.add("a")
   self.trie.add("b","c")
Example #4
0
    t = Timer("speed_get(data_get,c_val)",
              "from __main__ import speed_get,data_get,c_val")
    print format_res(t.repeat(REPEAT, number=1))

    print "Autocomp %d keys" % len(data_autocmp)
    t = Timer("speed_autocmp(data_autocmp,c_val)",
              "from __main__ import speed_autocmp,data_autocmp,c_val")
    print format_res(t.repeat(REPEAT, number=1))


if __name__ == '__main__':
    print "Perparing data"
    data_add = [
        hashlib.md5(str(i)).hexdigest() * randint(1, 5) for i in range(100000)
    ]
    data_add_val = [(data_add[i],
                     hashlib.md5(str(i)).hexdigest() * randint(1, 5))
                    for i in range(100000)]
    data_get = [d for d in data_add[0:80001]]+\
    [d[randint(1,3):randint(4,8)] for d in data_add[80000:-1]]
    data_autocmp = [d[0:randint(3,8)] for d in data_add[0:80001]]+\
        [d[randint(1,3):randint(4,8)] for d in data_add[80000:-1]]

    o = open('/tmp/a', 'w')
    o.write("\n".join([k + ":" + v for k, v in data_add_val]))
    c_add = CharTrie()
    c_val = CharTrie()
    #speed_insert_val(data_add_val,c_val)
    #c_val.get("a")
    speedtest()
Example #5
0
class TestCharTrieBasicFunctions(unittest.TestCase):

    def setUp(self):
      self.trie = CharTrie()
      #some dummy values
      self.trie.add("a")
      self.trie.add("b","c")
    def test_add(self):
      self.trie.add("justkey")                                                                                                                                          
      self.trie.add("key","val")                                                                                                                                                          
      self.trie.add("key2","val2")                                                                                                                                                          
      
    def test_get(self):
      s = self.trie.get("a")
      self.assertTrue(self.trie.get("a") == None)
      self.assertTrue(self.trie.get("Z") == None)
      self.trie.add("ZZ")
      self.assertTrue(self.trie.get("Z") == None)
      self.assertTrue(self.trie.get("b") == 'c')

    def test_autocomp(self):
      self.assertTrue(self.trie.autocomp("b") == 'b:c,')