Last active
December 13, 2015 21:38
-
-
Save nafu/4978540 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def chop(target, search_array): | |
if target in search_array: | |
return search_array.index(target) | |
else: | |
return -1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from chop import chop | |
import unittest | |
class TestSequenceFunctions(unittest.TestCase): | |
def test_chop(self): | |
self.assertEqual(-1, chop(3, [])) | |
self.assertEqual(-1, chop(3, [1])) | |
self.assertEqual(0, chop(1, [1])) | |
# | |
self.assertEqual(0, chop(1, [1, 3, 5])) | |
self.assertEqual(1, chop(3, [1, 3, 5])) | |
self.assertEqual(2, chop(5, [1, 3, 5])) | |
self.assertEqual(-1, chop(0, [1, 3, 5])) | |
self.assertEqual(-1, chop(2, [1, 3, 5])) | |
self.assertEqual(-1, chop(4, [1, 3, 5])) | |
self.assertEqual(-1, chop(6, [1, 3, 5])) | |
# | |
self.assertEqual(0, chop(1, [1, 3, 5, 7])) | |
self.assertEqual(1, chop(3, [1, 3, 5, 7])) | |
self.assertEqual(2, chop(5, [1, 3, 5, 7])) | |
self.assertEqual(3, chop(7, [1, 3, 5, 7])) | |
self.assertEqual(-1, chop(0, [1, 3, 5, 7])) | |
self.assertEqual(-1, chop(2, [1, 3, 5, 7])) | |
self.assertEqual(-1, chop(4, [1, 3, 5, 7])) | |
self.assertEqual(-1, chop(6, [1, 3, 5, 7])) | |
self.assertEqual(-1, chop(8, [1, 3, 5, 7])) | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment