Skip to content

Instantly share code, notes, and snippets.

@namongk
Forked from minsu/Sublist check
Created May 26, 2014 08:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save namongk/d172f5d24ae03280af21 to your computer and use it in GitHub Desktop.
Save namongk/d172f5d24ae03280af21 to your computer and use it in GitHub Desktop.
import unittest
import functools
def check(sub, sup):
try:
if len(sub) == 1 and sup.index(sub[0]) >= 0:
return True
return check(sub[1:], sup[sup.index(sub[0]) + 1:])
except:
return False
class CheckTest(unittest.TestCase):
def setUp(self):
self.sup = [1, 2, 3, [4, 5]]
self.check = functools.partial(check, sup=self.sup)
def test1(self):
self.assertTrue(self.check([1]))
def test2(self):
self.assertTrue(self.check([1, 2]))
def test3(self):
self.assertTrue(self.check([2, 3]))
def test4(self):
self.assertTrue(self.check([1, [4, 5]]))
def test5(self):
self.assertFalse(self.check([2, 1]))
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment