Fix #13, PEP8-ify notebooks.

This commit is contained in:
Donne Martin 2015-07-11 15:34:14 -04:00
parent 27c4a4f97c
commit 374d67ff30
18 changed files with 117 additions and 80 deletions

View File

@ -121,10 +121,12 @@
" assert_equal(func('AAABCCDDDD'), 'A3B1C2D4')\n",
" print('Success: test_compress')\n",
"\n",
"\n",
"def main():\n",
" test = TestCompress()\n",
" test.test_compress(compress_string)\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]

View File

@ -170,10 +170,12 @@
" assert_equal(func('AAABCCDDDD'), 'A3B1C2D4')\n",
" print('Success: test_compress')\n",
"\n",
"\n",
"def main():\n",
" test = TestCompress()\n",
" test.test_compress(compress_string)\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]

View File

@ -10,9 +10,11 @@ class TestCompress(object):
assert_equal(func('AAABCCDDDD'), 'A3B1C2D4')
print('Success: test_compress')
def main():
test = TestCompress()
test.test_compress(compress_string)
if __name__ == '__main__':
main()

View File

@ -34,7 +34,6 @@
"source": [
"## Constraints\n",
"\n",
"* For simplicity, are the keys integers only?\n",
" * Yes\n",
"* For collision resolution, can we use linked lists?\n",
@ -87,6 +86,7 @@
" # TODO: Implement me\n",
" pass\n",
"\n",
"\n",
"class HashTable(object):\n",
"\n",
" def __init__(self, size):\n",
@ -174,10 +174,12 @@
"\n",
" print('Success: test_end_to_end')\n",
"\n",
"\n",
"def main():\n",
" test = TestHashMap()\n",
" test.test_end_to_end()\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]

View File

@ -33,7 +33,6 @@
"source": [
"## Constraints\n",
"\n",
"* For simplicity, are the keys integers only?\n",
" * Yes\n",
"* For collision resolution, can we use linked lists?\n",
@ -121,6 +120,7 @@
" self.key = key\n",
" self.value = value\n",
"\n",
"\n",
"class HashTable(object):\n",
"\n",
" def __init__(self, size):\n",
@ -215,10 +215,12 @@
"\n",
" print('Success: test_end_to_end')\n",
"\n",
"\n",
"def main():\n",
" test = TestHashMap()\n",
" test.test_end_to_end()\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]

View File

@ -37,9 +37,11 @@ class TestHashMap(object):
print('Success: test_end_to_end')
def main():
test = TestHashMap()
test.test_end_to_end()
if __name__ == '__main__':
main()

View File

@ -34,7 +34,6 @@
"source": [
"## Constraints\n",
"\n",
"* Can we assume the string is ASCII?\n",
" * Yes\n",
" * Note: Unicode strings could require special handling depending on your language\n",
@ -122,6 +121,7 @@
" assert_equal(func('a ct', 'ca t'), True)\n",
" print('Success: test_permutation')\n",
"\n",
"\n",
"def main():\n",
" test = TestPermutation()\n",
" test.test_permutation(permutations)\n",
@ -132,6 +132,7 @@
" # in the solutions file\n",
" pass\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]

View File

@ -35,7 +35,6 @@
"source": [
"## Constraints\n",
"\n",
"* Can we assume the string is ASCII?\n",
" * Yes\n",
" * Note: Unicode strings could require special handling depending on your language\n",
@ -147,6 +146,7 @@
" dict_chars[char] += 1\n",
" return dict_chars\n",
"\n",
"\n",
"def permutations_alt(str1, str2):\n",
" if len(str1) != len(str2):\n",
" return False\n",
@ -191,6 +191,7 @@
" assert_equal(func('a ct', 'ca t'), True)\n",
" print('Success: test_permutation')\n",
"\n",
"\n",
"def main():\n",
" test = TestPermutation()\n",
" test.test_permutation(permutations)\n",
@ -201,6 +202,7 @@
" # in the solutions file\n",
" pass\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]

View File

@ -10,6 +10,7 @@ class TestPermutation(object):
assert_equal(func('a ct', 'ca t'), True)
print('Success: test_permutation')
def main():
test = TestPermutation()
test.test_permutation(permutations)
@ -20,5 +21,6 @@ def main():
# in the solutions file
pass
if __name__ == '__main__':
main()

View File

@ -34,7 +34,6 @@
"source": [
"## Constraints\n",
"\n",
"* Can I assume the string is ASCII?\n",
" * Yes\n",
" * Note: Unicode strings could require special handling depending on your language\n",
@ -117,14 +116,17 @@
" def test_reverse(self):\n",
" assert_equal(list_of_chars(None), None)\n",
" assert_equal(list_of_chars(['']), [''])\n",
" assert_equal(list_of_chars(['f', 'o', 'o', ' ', 'b', 'a', 'r']), \n",
" assert_equal(list_of_chars(\n",
" ['f', 'o', 'o', ' ', 'b', 'a', 'r']),\n",
" ['r', 'a', 'b', ' ', 'o', 'o', 'f'])\n",
" print('Success: test_reverse')\n",
"\n",
"\n",
"def main():\n",
" test = TestReverse()\n",
" test.test_reverse()\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]

View File

@ -126,6 +126,7 @@
" return None\n",
" return string[::-1]\n",
"\n",
"\n",
"def reverse_string_alt2(string):\n",
" if string is None:\n",
" return None\n",
@ -164,14 +165,17 @@
" def test_reverse(self):\n",
" assert_equal(list_of_chars(None), None)\n",
" assert_equal(list_of_chars(['']), [''])\n",
" assert_equal(list_of_chars(['f', 'o', 'o', ' ', 'b', 'a', 'r']), \n",
" assert_equal(list_of_chars(\n",
" ['f', 'o', 'o', ' ', 'b', 'a', 'r']),\n",
" ['r', 'a', 'b', ' ', 'o', 'o', 'f'])\n",
" print('Success: test_reverse')\n",
"\n",
"\n",
"def main():\n",
" test = TestReverse()\n",
" test.test_reverse()\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]

View File

@ -6,13 +6,16 @@ class TestReverse(object):
def test_reverse(self):
assert_equal(list_of_chars(None), None)
assert_equal(list_of_chars(['']), [''])
assert_equal(list_of_chars(['f', 'o', 'o', ' ', 'b', 'a', 'r']),
assert_equal(list_of_chars(
['f', 'o', 'o', ' ', 'b', 'a', 'r']),
['r', 'a', 'b', ' ', 'o', 'o', 'f'])
print('Success: test_reverse')
def main():
test = TestReverse()
test.test_reverse()
if __name__ == '__main__':
main()

View File

@ -34,7 +34,6 @@
"source": [
"## Constraints\n",
"\n",
"* Can you assume the string is ASCII?\n",
" * Yes\n",
" * Note: Unicode strings could require special handling depending on your language\n",
@ -85,6 +84,7 @@
" # TODO: Implement me\n",
" pass\n",
"\n",
"\n",
"def is_rotation(s1, s2):\n",
" # TODO: Implement me\n",
" # Call is_substring only once\n",
@ -129,10 +129,12 @@
" assert_equal(is_rotation('foobarbaz', 'barbazfoo'), True)\n",
" print('Success: test_rotation')\n",
"\n",
"\n",
"def main():\n",
" test = TestRotation()\n",
" test.test_rotation()\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]

View File

@ -34,7 +34,6 @@
"source": [
"## Constraints\n",
"\n",
"* Can you assume the string is ASCII?\n",
" * Yes\n",
" * Note: Unicode strings could require special handling depending on your language\n",
@ -94,6 +93,7 @@
"def is_substring(s1, s2):\n",
" return s1 in s2\n",
"\n",
"\n",
"def is_rotation(s1, s2):\n",
" if s1 is None or s2 is None:\n",
" return False\n",
@ -140,10 +140,12 @@
" assert_equal(is_rotation('foobarbaz', 'barbazfoo'), True)\n",
" print('Success: test_rotation')\n",
"\n",
"\n",
"def main():\n",
" test = TestRotation()\n",
" test.test_rotation()\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]

View File

@ -11,9 +11,11 @@ class TestRotation(object):
assert_equal(is_rotation('foobarbaz', 'barbazfoo'), True)
print('Success: test_rotation')
def main():
test = TestRotation()
test.test_rotation()
if __name__ == '__main__':
main()

View File

@ -9,6 +9,7 @@ class TestUniqueChars(object):
assert_equal(func('bar'), True)
print('Success: test_unique_chars')
def main():
test = TestUniqueChars()
test.test_unique_chars(unique_chars)
@ -20,5 +21,6 @@ def main():
# in the solutions file
pass
if __name__ == '__main__':
main()

View File

@ -34,7 +34,6 @@
"source": [
"## Constraints\n",
"\n",
"* Can you assume the string is ASCII?\n",
" * Yes\n",
" * Note: Unicode strings could require special handling depending on your language\n",
@ -118,6 +117,7 @@
" assert_equal(func('bar'), True)\n",
" print('Success: test_unique_chars')\n",
"\n",
"\n",
"def main():\n",
" test = TestUniqueChars()\n",
" test.test_unique_chars(unique_chars)\n",
@ -129,6 +129,7 @@
" # in the solutions file\n",
" pass\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]

View File

@ -219,6 +219,7 @@
" assert_equal(func('bar'), True)\n",
" print('Success: test_unique_chars')\n",
"\n",
"\n",
"def main():\n",
" test = TestUniqueChars()\n",
" test.test_unique_chars(unique_chars)\n",
@ -230,6 +231,7 @@
" # in the solutions file\n",
" pass\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]
@ -258,21 +260,21 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 2",
"language": "python",
"name": "python3"
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.3"
"pygments_lexer": "ipython2",
"version": "2.7.10"
}
},
"nbformat": 4,