#273: Remove nose dependency for arrays_strings/ (#274)

This commit is contained in:
Donne Martin
2020-07-04 10:56:49 -04:00
committed by GitHub
parent 9678c5ee69
commit b598f474af
34 changed files with 399 additions and 481 deletions

View File

@@ -79,9 +79,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class Item(object):\n",
@@ -133,16 +131,14 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# %load test_hash_map.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestHashMap(object):\n",
"class TestHashMap(unittest.TestCase):\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",
@@ -150,31 +146,31 @@
" hash_table = HashTable(10)\n",
"\n",
" print(\"Test: get on an empty hash table index\")\n",
" assert_raises(KeyError, hash_table.get, 0)\n",
" self.assertRaises(KeyError, hash_table.get, 0)\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",
" self.assertEqual(hash_table.get(0), 'foo')\n",
" hash_table.set(1, 'bar')\n",
" assert_equal(hash_table.get(1), 'bar')\n",
" self.assertEqual(hash_table.get(1), 'bar')\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",
" self.assertEqual(hash_table.get(0), 'foo')\n",
" self.assertEqual(hash_table.get(10), 'foo2')\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",
" self.assertEqual(hash_table.get(0), 'foo')\n",
" self.assertEqual(hash_table.get(10), 'foo3')\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_raises(KeyError, hash_table.get, 10)\n",
" self.assertEqual(hash_table.get(0), 'foo')\n",
" self.assertRaises(KeyError, hash_table.get, 10)\n",
"\n",
" print(\"Test: remove on a key that doesn't exist\")\n",
" assert_raises(KeyError, hash_table.remove, -1)\n",
" self.assertRaises(KeyError, hash_table.remove, -1)\n",
"\n",
" print('Success: test_end_to_end')\n",
"\n",
@@ -214,9 +210,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.0"
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

View File

@@ -114,9 +114,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class Item(object):\n",
@@ -169,9 +167,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@@ -183,10 +179,10 @@
],
"source": [
"%%writefile test_hash_map.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestHashMap(object):\n",
"class TestHashMap(unittest.TestCase):\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",
@@ -194,31 +190,31 @@
" hash_table = HashTable(10)\n",
"\n",
" print(\"Test: get on an empty hash table index\")\n",
" assert_raises(KeyError, hash_table.get, 0)\n",
" self.assertRaises(KeyError, hash_table.get, 0)\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",
" self.assertEqual(hash_table.get(0), 'foo')\n",
" hash_table.set(1, 'bar')\n",
" assert_equal(hash_table.get(1), 'bar')\n",
" self.assertEqual(hash_table.get(1), 'bar')\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",
" self.assertEqual(hash_table.get(0), 'foo')\n",
" self.assertEqual(hash_table.get(10), 'foo2')\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",
" self.assertEqual(hash_table.get(0), 'foo')\n",
" self.assertEqual(hash_table.get(10), 'foo3')\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_raises(KeyError, hash_table.get, 10)\n",
" self.assertEqual(hash_table.get(0), 'foo')\n",
" self.assertRaises(KeyError, hash_table.get, 10)\n",
"\n",
" print(\"Test: remove on a key that doesn't exist\")\n",
" assert_raises(KeyError, hash_table.remove, -1)\n",
" self.assertRaises(KeyError, hash_table.remove, -1)\n",
"\n",
" print('Success: test_end_to_end')\n",
"\n",
@@ -235,9 +231,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@@ -256,6 +250,13 @@
"source": [
"run -i test_hash_map.py"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
@@ -274,9 +275,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.0"
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

View File

@@ -1,7 +1,7 @@
from nose.tools import assert_equal, assert_raises
import unittest
class TestHashMap(object):
class TestHashMap(unittest.TestCase):
# TODO: It would be better if we had unit tests for each
# method in addition to the following end-to-end test
@@ -9,31 +9,31 @@ class TestHashMap(object):
hash_table = HashTable(10)
print("Test: get on an empty hash table index")
assert_raises(KeyError, hash_table.get, 0)
self.assertRaises(KeyError, hash_table.get, 0)
print("Test: set on an empty hash table index")
hash_table.set(0, 'foo')
assert_equal(hash_table.get(0), 'foo')
self.assertEqual(hash_table.get(0), 'foo')
hash_table.set(1, 'bar')
assert_equal(hash_table.get(1), 'bar')
self.assertEqual(hash_table.get(1), 'bar')
print("Test: set on a non empty hash table index")
hash_table.set(10, 'foo2')
assert_equal(hash_table.get(0), 'foo')
assert_equal(hash_table.get(10), 'foo2')
self.assertEqual(hash_table.get(0), 'foo')
self.assertEqual(hash_table.get(10), 'foo2')
print("Test: set on a key that already exists")
hash_table.set(10, 'foo3')
assert_equal(hash_table.get(0), 'foo')
assert_equal(hash_table.get(10), 'foo3')
self.assertEqual(hash_table.get(0), 'foo')
self.assertEqual(hash_table.get(10), 'foo3')
print("Test: remove on a key that already exists")
hash_table.remove(10)
assert_equal(hash_table.get(0), 'foo')
assert_raises(KeyError, hash_table.get, 10)
self.assertEqual(hash_table.get(0), 'foo')
self.assertRaises(KeyError, hash_table.get, 10)
print("Test: remove on a key that doesn't exist")
assert_raises(KeyError, hash_table.remove, -1)
self.assertRaises(KeyError, hash_table.remove, -1)
print('Success: test_end_to_end')
@@ -44,4 +44,4 @@ def main():
if __name__ == '__main__':
main()
main()