Skip to content

Commit

Permalink
Add README.md and fix a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
wkingfly committed Aug 7, 2014
1 parent 212a2b3 commit a0ddaf7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
10 changes: 4 additions & 6 deletions kmp/kmp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import pdb

class strFind:
def __init__(self, child, matrix):
self.child = list(child)
Expand Down Expand Up @@ -42,8 +40,6 @@ def find(self):
if i == self.child[j]:
equals += 1
j += 1
if equals == 6:
pdb.set_trace()
if equals == len(self.child):
return True
else:
Expand All @@ -52,5 +48,7 @@ def find(self):
else:
move_num = 1
self.matrix = self.matrix[move_num:len(self.matrix)]
self.find()
return False
if len(self.matrix) < len(self.child):
return False

return self.find()
4 changes: 2 additions & 2 deletions test/test_kmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class Test_strFind(unittest.TestCase):

def setUp(self):
matrix = 'iacdabcabcdabcabcix'
matrix = 'acdabcabcdabcabcx'
child = 'abcabcx'
self.sF = kmp.strFind(child, matrix)
def tearDown(self):
Expand All @@ -18,7 +18,7 @@ def test_part_match(self):
self.assertEqual(self.sF.part_list, l)

def test_find(self):
self.assertFalse(self.sF.find())
self.assertTrue(self.sF.find())


if __name__ == '__main__':
Expand Down

0 comments on commit a0ddaf7

Please sign in to comment.