Advertisement
Guest User

BadBadCode

a guest
Apr 23rd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. import timeit
  2.  
  3.  
  4. def string_match(a, b):
  5.     return sum(a==b for a,b in zip(zip(a,a[1:]),zip(b,b[1:])))
  6.  
  7. def test(func):
  8.     assert(func('xxcaazz', 'xxbaaz') == 3)
  9.     assert(func('abc', 'abc') == 2)
  10.     assert(func('abc', 'axc') == 0)
  11.     assert(func('hello', 'he') == 1)
  12.     assert(func('he', 'hello') == 1)
  13.     assert(func('h', 'hello')  == 0)
  14.     assert(func('', 'hello') == 0)
  15.     assert(func('aabbccdd', 'abbbxxd') == 1)
  16.     assert(func('aaxxaaxx', 'iaxxai') == 3)
  17.     assert(func('iaxxai', 'aaxxaaxx') == 3)
  18.  
  19. def time_test():
  20.     return test(string_match)
  21.  
  22. print timeit.timeit(time_test, number=10000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement