comparison tests/test_split.py @ 51:c3b69728f291

finding indices now works
author Jeff Hammel <k0scist@gmail.com>
date Sun, 17 May 2015 08:33:23 -0700
parents 1284c99a94fa
children
comparison
equal deleted inserted replaced
50:1284c99a94fa 51:c3b69728f291
8 # imports 8 # imports
9 import unittest 9 import unittest
10 from textshaper import split 10 from textshaper import split
11 11
12 12
13
13 class SplitUnitTest(unittest.TestCase): 14 class SplitUnitTest(unittest.TestCase):
14 15
15 def test_findall(self): 16 def test_findall(self):
16 """test basic""" 17 """test finding all substrings"""
17 18
18 # 012345678901 19 # 012345678901
19 string = 'a cat, a bat' 20 string = 'a cat, a bat'
20 21
21 retval = split.findall(string, 'a') 22 retval = split.findall(string, 'a')
22 self.assertEqual(retval, [0,3,7,10]) 23 self.assertEqual(retval, [0,3,7,10])
23 24
24 self.assertEqual(split.findall(string, 't'), 25 self.assertEqual(split.findall(string, 't'),
25 [4, 11]) 26 [4, 11])
26 27
28 def test_indices(self):
29 """test finding ordered indices"""
30 string = 'a cat, a bat'
31 indices = split.indices(string, ('a', 't'))
32 self.assertEqual(indices,
33 [(0, 'a'),
34 (3, 'a'),
35 (4, 't'),
36 (7, 'a'),
37 (10, 'a'),
38 (11, 't')])
39
27 40
28 if __name__ == '__main__': 41 if __name__ == '__main__':
29 unittest.main() 42 unittest.main()
30 43