Skip to content

Instantly share code, notes, and snippets.

@nnabeyang
Last active December 11, 2015 09:59
Show Gist options
  • Select an option

  • Save nnabeyang/4583816 to your computer and use it in GitHub Desktop.

Select an option

Save nnabeyang/4583816 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python2.7
import unittest
from test import test_support
class TestClass(unittest.TestCase):
def test_answer_conserves_names(self):
self.assertEqual(len(getNames("nick.txt", True)),
len(getNames("answer.txt")))
def test_answer_nameList_is_uniq(self):
self.assertTrue(isUniq(getNames("answer.txt")))
def isUniq(l1):
l2 = []
for e in l1:
if e in l2:
return False
l2.append(e)
return True
def getNames(path, uniq=False):
names = []
with open(path) as f:
for line in f:
if uniq:
lst = line.rstrip().split("=")
for e in lst:
if not e in names: names.append(e)
else:
names += line.rstrip().split("=")
return names
if __name__ == '__main__':
test_support.run_unittest(TestClass)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment