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

@@ -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",
@@ -82,13 +81,14 @@
"outputs": [],
"source": [
"class Item(object):\n",
" \n",
"\n",
" def __init__(self, key, value):\n",
" # TODO: Implement me\n",
" pass\n",
"\n",
"\n",
"class HashTable(object):\n",
" \n",
"\n",
" def __init__(self, size):\n",
" # TODO: Implement me\n",
" pass\n",
@@ -139,45 +139,47 @@
"\n",
"\n",
"class TestHashMap(object):\n",
" \n",
"\n",
" # TODO: It would be better if we had unit tests for each\n",
" # method in addition to the following end-to-end test\n",
" def test_end_to_end(self):\n",
" hash_table = HashTable(10)\n",
" \n",
"\n",
" print(\"Test: get on an empty hash table index\")\n",
" assert_equal(hash_table.get(0), None)\n",
" \n",
"\n",
" print(\"Test: set on an empty hash table index\")\n",
" hash_table.set(0, 'foo')\n",
" assert_equal(hash_table.get(0), 'foo')\n",
" hash_table.set(1, 'bar')\n",
" assert_equal(hash_table.get(1), 'bar')\n",
" \n",
"\n",
" print(\"Test: set on a non empty hash table index\")\n",
" hash_table.set(10, 'foo2')\n",
" assert_equal(hash_table.get(0), 'foo')\n",
" assert_equal(hash_table.get(10), 'foo2')\n",
" \n",
"\n",
" print(\"Test: set on a key that already exists\")\n",
" hash_table.set(10, 'foo3')\n",
" assert_equal(hash_table.get(0), 'foo')\n",
" assert_equal(hash_table.get(10), 'foo3')\n",
" \n",
"\n",
" print(\"Test: remove on a key that already exists\")\n",
" hash_table.remove(10)\n",
" assert_equal(hash_table.get(0), 'foo')\n",
" assert_equal(hash_table.get(10), None)\n",
" \n",
"\n",
" print(\"Test: remove on a key that doesn't exist\")\n",
" hash_table.remove(-1)\n",
" \n",
"\n",
" print('Success: test_end_to_end')\n",
"\n",
"\n",
"def main():\n",
" test = TestHashMap()\n",
" test.test_end_to_end()\n",
" \n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]