Ejemplo n.º 1
0
 def test_13(self):
     """StrTree: test_13(): keywords (all)."""
     myV = set((
             'asm', 'do', 'if', 'return', 'typedef',
             'auto', 'double', 'inline', 'short', 'typeid',
             'bool', 'dynamic_cast', 'int', 'signed', 'typename',
             'break', 'else', 'long', 'sizeof', 'union',
             'case', 'enum', 'mutable', 'static', 'unsigned',
             'catch', 'explicit', 'namespace', 'static_cast', 'using',
             'char', 'export', 'new', 'struct', 'virtual',
             'class', 'extern', 'operator', 'switch', 'void',
             'const', 'false', 'private', 'template', 'volatile',
             'const_cast', 'float', 'protected', 'this', 'wchar_t',
             'continue', 'for', 'public', 'throw', 'while',
             'default', 'friend', 'register', 'true',
             'delete', 'goto', 'reinterpret_cast', 'try',
             ))
     mySt = StrTree.StrTree(myV)
     #print()
     #print mySt.values()
     #print str(mySt)
     self.assertEqual(2, mySt.has('do'))
     self.assertEqual(2, mySt.has('dou'))
     self.assertEqual(2, mySt.has('doub'))
     self.assertEqual(2, mySt.has('doubl'))
     self.assertEqual(6, mySt.has('double'))
     self.assertEquals(myV, set(mySt.values()))
Ejemplo n.º 2
0
 def test_10(self):
     """StrTree: test_10(): preprocessing operators."""
     myV = set((
             '{', '}', '[', ']', '#', '##', '(', ')',
             '<:', ':>', '<%', '%>', '%:', '%:%:', ';', ':', '...',
             'new', 'delete', '?', '::', '.', '.*',
             '+', '-', '*', '/', '%', '^', '&', '|', '~',
             '!', '=', '<', '>', '+=', '-=', '*=', '/=', '%=',
             '^=', '&=', '|=', '<<', '>>', '>>=', '<<=', '==', '!=',
             '<=', '>=', '&&', '||', '++', '--', ',', '->*', '->',
             'and', 'and_eq', 'bitand', 'bitor', 'compl', 'not', 'not_eq',
             'or', 'or_eq', 'xor', 'xor_eq',
             ))
     mySt = StrTree.StrTree(myV)
     #print()
     #print mySt.values()
     #print str(mySt)
     self.assertEqual(1, mySt.has('#'))
     self.assertEqual(2, mySt.has('##'))
     self.assertEqual(2, mySt.has('###'))
     self.assertEqual(2, mySt.has('####'))
     self.assertEqual(3, mySt.has('and'))
     self.assertEqual(3, mySt.has('and_'))
     self.assertEqual(3, mySt.has('and_e'))
     self.assertEqual(6, mySt.has('and_eq'))
     self.assertEquals(myV, set(mySt.values()))
Ejemplo n.º 3
0
 def test_12(self):
     """StrTree: test_12(): keywords (a few)."""
     myV = set((
             'asm',
             'auto',
             'bool', 
             'break',
             'case',
             'catch',
             'char',
             'class',
             'const',
             'const_cast',
             'continue',
             'default',
             'delete',
             'do',
             'double',
             ))
     mySt = StrTree.StrTree(myV)
     #print()
     #print mySt.values()
     #print str(mySt)
     self.assertEqual(2, mySt.has('do'))
     self.assertEqual(2, mySt.has('dou'))
     self.assertEqual(2, mySt.has('doub'))
     self.assertEqual(2, mySt.has('doubl'))
     self.assertEqual(6, mySt.has('double'))
     self.assertEquals(myV, set(mySt.values()))
Ejemplo n.º 4
0
 def test_01(self):
     """StrTree: test_01(): simple test."""
     myV = set(('#', '###',))
     mySt = StrTree.StrTree(myV)
     #print mySt.values()
     #print str(mySt)
     self.assertEqual(1, mySt.has('#'))
     self.assertEqual(1, mySt.has('##'))
     self.assertEqual(3, mySt.has('###'))
     self.assertEqual(3, mySt.has('####'))
     self.assertEqual(3, mySt.has('#####'))
     self.assertEquals(myV, set(mySt.values()))
Ejemplo n.º 5
0
    def test_11(self):
        """StrTree: test_11(): keywords (three)."""
        myV = set((
                'const',
                'const_cast',
                'continue',
                ))
        mySt = StrTree.StrTree(myV)
        #print()
        #print mySt.values()
        #print str(mySt)
        self.assertEqual(5, mySt.has('const'))
        self.assertEqual(5, mySt.has('const_'))
        self.assertEqual(5, mySt.has('const_c'))
        self.assertEqual(5, mySt.has('const_ca'))
        self.assertEqual(5, mySt.has('const_cas'))
        self.assertEqual(10, mySt.has('const_cast'))
        # Not deterministic under Python3
#         print()
#         print(str(mySt))
#         self.assertEquals("""False 0
# "c"
#  False 1
#  "o"
#   False 2
#   "n"
#    False 3
#    "s"
#     False 4
#     "t"
#      True 5
#      "_"
#       False 6
#       "c"
#        False 7
#        "a"
#         False 8
#         "s"
#          False 9
#          "t"
#           True 10
#    "t"
#     False 4
#     "i"
#      False 5
#      "n"
#       False 6
#       "u"
#        False 7
#        "e"
#         True 8""", str(mySt))
        self.assertEquals(myV, set(mySt.values()))
Ejemplo n.º 6
0
 def test_02(self):
     """StrTree: test_02(): empty."""
     myV = set()
     mySt = StrTree.StrTree(myV)
     #print mySt.values()
     #print str(mySt)
     self.assertEqual(0, mySt.has(''))
     self.assertEqual(0, mySt.has('#'))
     self.assertEqual(0, mySt.has('##'))
     self.assertEqual(0, mySt.has('###'))
     self.assertEqual(0, mySt.has('####'))
     self.assertEqual(0, mySt.has('#####'))
     self.assertEquals(myV, set(mySt.values()))
Ejemplo n.º 7
0
 def test_01(self):
     """TestStrTreeHas: test_01(): has() with offset."""
     mySt = StrTree.StrTree(['#', '##', '###'])
     #print mySt.values()
     #print str(mySt)
     self.assertEqual(1, mySt.has('#'))
     self.assertEqual(0, mySt.has(' #'))
     self.assertEqual(2, mySt.has(' #', 1))
     self.assertEqual(0, mySt.has('  #'))
     self.assertEqual(0, mySt.has('   #'))
     self.assertEqual(4, mySt.has('123#', 3))
     self.assertEqual(5, mySt.has('123##', 3))
     self.assertEqual(6, mySt.has('123###', 3))
     self.assertEqual(6, mySt.has('123####', 3))
     self.assertEqual(6, mySt.has('123#####', 3))
Ejemplo n.º 8
0
    def test_str(self):
        myV = set((
            '#',
            '###',
        ))
        mySt = StrTree.StrTree(myV)
        # print()
        # print(str(mySt))
        exp = """False 0
"#"
 True 1
 "#"
  False 2
  "#"
   True 3"""
        self.assertEqual(exp, str(mySt))
Ejemplo n.º 9
0
 def test_00(self):
     """TestStrTreePerf: test_00(): keyword performance."""
     myV = set((
             'asm', 'do', 'if', 'return', 'typedef',
             'auto', 'double', 'inline', 'short', 'typeid',
             'bool', 'dynamic_cast', 'int', 'signed', 'typename',
             'break', 'else', 'long', 'sizeof', 'union',
             'case', 'enum', 'mutable', 'static', 'unsigned',
             'catch', 'explicit', 'namespace', 'static_cast', 'using',
             'char', 'export', 'new', 'struct', 'virtual',
             'class', 'extern', 'operator', 'switch', 'void',
             'const', 'false', 'private', 'template', 'volatile',
             'const_cast', 'float', 'protected', 'this', 'wchar_t',
             'continue', 'for', 'public', 'throw', 'while',
             'default', 'friend', 'register', 'true',
             'delete', 'goto', 'reinterpret_cast', 'try',
             ))
     myVList = [
             'asm', 'do', 'if', 'return', 'typedef',
             'auto', 'double', 'inline', 'short', 'typeid',
             'bool', 'dynamic_cast', 'int', 'signed', 'typename',
             'break', 'else', 'long', 'sizeof', 'union',
             'case', 'enum', 'mutable', 'static', 'unsigned',
             'catch', 'explicit', 'namespace', 'static_cast', 'using',
             'char', 'export', 'new', 'struct', 'virtual',
             'class', 'extern', 'operator', 'switch', 'void',
             'const', 'false', 'private', 'template', 'volatile',
             'const_cast', 'float', 'protected', 'this', 'wchar_t',
             'continue', 'for', 'public', 'throw', 'while',
             'default', 'friend', 'register', 'true',
             'delete', 'goto', 'reinterpret_cast', 'try',
             ]
     mySt = StrTree.StrTree(myV)
     self.assertEquals(myV, set(mySt.values()))
     print()
     #print mySt.values()
     #print str(mySt)
     count = 10000
     print('Loop count: %d' % count)
     FW = 32
     cntrFound = 0
     cStart = time.clock()
     for i in range(count):
         if mySt.has('do'):
             cntrFound += 1
     #sys.stderr.write('has("do"):     %8d, Time: %8.3f (s)s ... ' % (count, time.clock() - cStart))
     print('%-*s Time: %8.3f (s)s ... ' % (FW, 'has("do")', time.clock() - cStart))
     self.assertEqual(count, cntrFound)
     cntrFound = 0
     cStart = time.clock()
     for i in range(count):
         if 'do' in myV:
             cntrFound += 1
     print('%-*s Time: %8.3f (s)s ... ' % (FW, '"do" in set:', time.clock() - cStart))
     self.assertEqual(count, cntrFound)
     cntrFound = 0
     cStart = time.clock()
     for i in range(count):
         if 'do' in myVList:
             cntrFound += 1
     print('%-*s Time: %8.3f (s)s ... ' % (FW, '"do" in list:', time.clock() - cStart))
     self.assertEqual(count, cntrFound)
     cntrFound = 0
     cStart = time.clock()
     for i in range(count):
         if mySt.has('double'):
             cntrFound += 1
     print('%-*s Time: %8.3f (s)s ... ' % (FW, 'has("double"):', time.clock() - cStart))
     self.assertEqual(count, cntrFound)
     cntrFound = 0
     cStart = time.clock()
     for i in range(count):
         if 'double' in myV:
             cntrFound += 1
     print('%-*s Time: %8.3f (s)s ... ' % (FW, '"double" in set:', time.clock() - cStart))
     self.assertEqual(count, cntrFound)
     cntrFound = 0
     cStart = time.clock()
     for i in range(count):
         if 'double' in myVList:
             cntrFound += 1
     print('%-*s Time: %8.3f (s)s ... ' % (FW, '"double" in list:', time.clock() - cStart))
     self.assertEqual(count, cntrFound)
     #'reinterpret_cast'
     self.assertEqual(count, cntrFound)
     cntrFound = 0
     cStart = time.clock()
     for i in range(count):
         if mySt.has('double'):
             cntrFound += 1
     print('%-*s Time: %8.3f (s)s ... ' % (FW, 'has("reinterpret_cast"):', time.clock() - cStart))
     self.assertEqual(count, cntrFound)
     cntrFound = 0
     cStart = time.clock()
     for i in range(count):
         if 'reinterpret_cast' in myV:
             cntrFound += 1
     print('%-*s Time: %8.3f (s)s ... ' % (FW, '"reinterpret_cast" in set:', time.clock() - cStart))
     self.assertEqual(count, cntrFound)
     cntrFound = 0
     cStart = time.clock()
     for i in range(count):
         if 'reinterpret_cast' in myVList:
             cntrFound += 1
     print('%-*s Time: %8.3f (s)s ... ' % (FW, '"reinterpret_cast" in list:', time.clock() - cStart))
     self.assertEqual(count, cntrFound)
     #'strubbish'
     self.assertEqual(count, cntrFound)
     cntrFound = 0
     cStart = time.clock()
     for i in range(count):
         if mySt.has('strubbish'):
             cntrFound += 1
     print('%-*s Time: %8.3f (s)s ... ' % (FW, 'has("strubbish"):', time.clock() - cStart))
     self.assertEqual(0, cntrFound)
     cntrFound = 0
     cStart = time.clock()
     for i in range(count):
         if 'strubbish' in myV:
             cntrFound += 1
     print('%-*s Time: %8.3f (s)s ... ' % (FW, '"strubbish" in set:', time.clock() - cStart))
     self.assertEqual(0, cntrFound)
     cntrFound = 0
     cStart = time.clock()
     for i in range(count):
         if 'strubbish' in myVList:
             cntrFound += 1
     print('%-*s Time: %8.3f (s)s ... ' % (FW, '"strubbish" in list:', time.clock() - cStart))
     self.assertEqual(0, cntrFound)