Skip to content

Instantly share code, notes, and snippets.

@nafu
Last active December 13, 2015 21:38
Show Gist options
  • Save nafu/4978540 to your computer and use it in GitHub Desktop.
Save nafu/4978540 to your computer and use it in GitHub Desktop.
def chop(target, search_array):
if target in search_array:
return search_array.index(target)
else:
return -1
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