t471.py 766 B

12345678910111213141516171819202122232425
  1. def helper(got,expect):
  2. if got == expect: print True
  3. else: print False, expect, got
  4. print "\nstr.count"
  5. helper('abcd abcba '.count('abc'),2)
  6. helper('abcd abcba '.count('z'),0)
  7. helper('abcd abcba '.count('abc',1),1)
  8. helper('abcd abcba '.count('abc',-1),0)
  9. helper('abcd abcba '.count('abc',5),1)
  10. helper('abcd abcba '.count('abc',-5),0)
  11. helper('abcd abcba '.count('abc',1,8),1)
  12. helper('abcd abcba '.count('abc',-6,-3),1)
  13. helper('abcd abcba '.count('abc',4,-1),1)
  14. helper('abcd abcba '.count('abc',-6,10),1)
  15. helper('abcd abcda '.count('ad',-6,-3),0)
  16. helper('abcd abcba '.count('a',-6,-6),0)
  17. helper('abcd abcba '.count('a',6,-7),0)
  18. helper('abcd abcba '.count('a',3,1),0)
  19. helper('abcd abcba '.count('a',-100,100),3)
  20. helper('abcd abcba '.count('a',100,-100),0)