Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: net/tools/dafsa/make_dafsa_unittest.py

Issue 2649033004: [3 of 4] Speedup GetRegistryLengthImpl() by seeding the DAFSA in reverse
Patch Set: Language. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 6
7 import collections
8 import random
7 import sys 9 import sys
8 import unittest 10 import unittest
9 import make_dafsa 11 import make_dafsa
10 12
11 13
12 class ParseGperfTest(unittest.TestCase): 14 class ParseGperfTest(unittest.TestCase):
13 def testMalformedKey(self): 15 def testMalformedKey(self):
14 """Tests exception is thrown at bad format.""" 16 """Tests exception is thrown at bad format."""
15 infile1 = [ '%%', '', '%%' ] 17 infile1 = [ '%%', '', '%%' ]
16 self.assertRaises(make_dafsa.InputError, make_dafsa.parse_gperf, infile1) 18 self.assertRaises(make_dafsa.InputError, make_dafsa.parse_gperf, infile1)
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 def testSingleNode(self): 131 def testSingleNode(self):
130 """Tests a single node is expanded to a list with the label string.""" 132 """Tests a single node is expanded to a list with the label string."""
131 133
132 # 'ab' -> [ 'ab' ] 134 # 'ab' -> [ 'ab' ]
133 135
134 node1 = ( 'ab', [ None ] ) 136 node1 = ( 'ab', [ None ] )
135 words = [ 'ab' ] 137 words = [ 'ab' ]
136 self.assertEqual(make_dafsa.to_words(node1), words) 138 self.assertEqual(make_dafsa.to_words(node1), words)
137 139
138 def testChain(self): 140 def testChain(self):
139 """Tests a sequence of nodes are preoperly expanded.""" 141 """Tests a sequence of nodes are properly expanded."""
140 142
141 # 'ab' -> 'cd' => [ 'abcd' ] 143 # 'ab' -> 'cd' => [ 'abcd' ]
142 144
143 node2 = ( 'cd', [ None ] ) 145 node2 = ( 'cd', [ None ] )
144 node1 = ( 'ab', [ node2 ] ) 146 node1 = ( 'ab', [ node2 ] )
145 words = [ 'abcd' ] 147 words = [ 'abcd' ]
146 self.assertEqual(make_dafsa.to_words(node1), words) 148 self.assertEqual(make_dafsa.to_words(node1), words)
147 149
148 def testInnerTerminator(self): 150 def testInnerTerminator(self):
149 """Tests a sequence with an inner terminator is expanded to two strings.""" 151 """Tests a sequence with an inner terminator is expanded to two strings."""
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 infile = [ '%%', 'aa, 1', 'bbb, 2', 'baa, 1', '%%' ] 752 infile = [ '%%', 'aa, 1', 'bbb, 2', 'baa, 1', '%%' ]
751 bytes = [ 0x02, 0x83, 0xE2, 0x02, 0x83, 0x61, 0x61, 0x81, 0x62, 0x62, 753 bytes = [ 0x02, 0x83, 0xE2, 0x02, 0x83, 0x61, 0x61, 0x81, 0x62, 0x62,
752 0x82 ] 754 0x82 ]
753 outfile = make_dafsa.to_cxx(bytes) 755 outfile = make_dafsa.to_cxx(bytes)
754 self.assertEqual(make_dafsa.words_to_cxx(make_dafsa.parse_gperf(infile)), 756 self.assertEqual(make_dafsa.words_to_cxx(make_dafsa.parse_gperf(infile)),
755 outfile) 757 outfile)
756 758
757 759
758 if __name__ == '__main__': 760 if __name__ == '__main__':
759 unittest.main() 761 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698