Question: So Im supposed to write Python code that implements the Horspool matching algorithm for finding a pattern in a text. We are supposed to add
So if done correctly and you run def testHorspool() it will print that it passes each test. Please show the output to confirm all 6 tests pass. Test 1,3, and 3a already pass so I think it is a minor problem that Im overlooking. Thanks RE EB Walcher Mediafools JES Functions Window Layout Help def HorspoolMatching (pattern, text): m len (pattern) n len (text) if m >n: return -1 table= [] for k in range (256): table.append (m) for k in range (m- 1): table [ord (pattern [k])) = m- k- 1 table tuple (table) k=m-1 counter=0 result=[] #to return the final output as firstMatch-0 to check if pattern occurs for the first time while kn: 41 j=m-1; flag=0 to check if comparison happens inside while loop or not while jm 0 and text(i]pattern(31: j 1: i :counter+ 1:flag 1 1 and firstMatch 0: rosult.append (i+1) firstMatch 1 Ichanges the Elag after the first mat k table [ord(text [k]) if flag"#0 and j!--1: when condition fails in line 46 itself but should be included in count counter 1 if len (result) 0: result.append (-1) result.append (counter) return result " def testcaseH (testNumber, string, text, expectedResult) actualResult = Horspoo!Matching (string, text) " if actualResultexpectedResult: print "Test", test Number, "passed." else: print "Test",testNumber, "tailed. Expected", expectedResult, "but found", actualResult
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
