mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
parent
9678c5ee69
commit
b598f474af
|
@ -76,9 +76,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class CompressString(object):\n",
|
||||
|
@ -107,24 +105,22 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# %load test_compress.py\n",
|
||||
"from nose.tools import assert_equal\n",
|
||||
"import unittest\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestCompress(object):\n",
|
||||
"class TestCompress(unittest.TestCase):\n",
|
||||
"\n",
|
||||
" def test_compress(self, func):\n",
|
||||
" assert_equal(func(None), None)\n",
|
||||
" assert_equal(func(''), '')\n",
|
||||
" assert_equal(func('AABBCC'), 'AABBCC')\n",
|
||||
" assert_equal(func('AAABCCDDDDE'), 'A3BC2D4E')\n",
|
||||
" assert_equal(func('BAAACCDDDD'), 'BA3C2D4')\n",
|
||||
" assert_equal(func('AAABAACCDDDD'), 'A3BA2C2D4')\n",
|
||||
" self.assertEqual(func(None), None)\n",
|
||||
" self.assertEqual(func(''), '')\n",
|
||||
" self.assertEqual(func('AABBCC'), 'AABBCC')\n",
|
||||
" self.assertEqual(func('AAABCCDDDDE'), 'A3BC2D4E')\n",
|
||||
" self.assertEqual(func('BAAACCDDDD'), 'BA3C2D4')\n",
|
||||
" self.assertEqual(func('AAABAACCDDDD'), 'A3BA2C2D4')\n",
|
||||
" print('Success: test_compress')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
@ -164,9 +160,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
|
||||
}
|
||||
|
|
|
@ -92,9 +92,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class CompressString(object):\n",
|
||||
|
@ -129,9 +127,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
|
@ -143,18 +139,18 @@
|
|||
],
|
||||
"source": [
|
||||
"%%writefile test_compress.py\n",
|
||||
"from nose.tools import assert_equal\n",
|
||||
"import unittest\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestCompress(object):\n",
|
||||
"class TestCompress(unittest.TestCase):\n",
|
||||
"\n",
|
||||
" def test_compress(self, func):\n",
|
||||
" assert_equal(func(None), None)\n",
|
||||
" assert_equal(func(''), '')\n",
|
||||
" assert_equal(func('AABBCC'), 'AABBCC')\n",
|
||||
" assert_equal(func('AAABCCDDDDE'), 'A3BC2D4E')\n",
|
||||
" assert_equal(func('BAAACCDDDD'), 'BA3C2D4')\n",
|
||||
" assert_equal(func('AAABAACCDDDD'), 'A3BA2C2D4')\n",
|
||||
" self.assertEqual(func(None), None)\n",
|
||||
" self.assertEqual(func(''), '')\n",
|
||||
" self.assertEqual(func('AABBCC'), 'AABBCC')\n",
|
||||
" self.assertEqual(func('AAABCCDDDDE'), 'A3BC2D4E')\n",
|
||||
" self.assertEqual(func('BAAACCDDDD'), 'BA3C2D4')\n",
|
||||
" self.assertEqual(func('AAABAACCDDDD'), 'A3BA2C2D4')\n",
|
||||
" print('Success: test_compress')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
@ -171,9 +167,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
|
@ -204,9 +198,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
|
||||
}
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
from nose.tools import assert_equal
|
||||
import unittest
|
||||
|
||||
|
||||
class TestCompress(object):
|
||||
class TestCompress(unittest.TestCase):
|
||||
|
||||
def test_compress(self, func):
|
||||
assert_equal(func(None), None)
|
||||
assert_equal(func(''), '')
|
||||
assert_equal(func('ABC'), 'ABC')
|
||||
assert_equal(func('AABBCC'), 'AABBCC')
|
||||
assert_equal(func('AAABCCDDDDE'), 'A3BC2D4E')
|
||||
assert_equal(func('BAAACCDDDD'), 'BA3C2D4')
|
||||
assert_equal(func('AAABAACCDDDD'), 'A3BA2C2D4')
|
||||
self.assertEqual(func(None), None)
|
||||
self.assertEqual(func(''), '')
|
||||
self.assertEqual(func('AABBCC'), 'AABBCC')
|
||||
self.assertEqual(func('AAABCCDDDDE'), 'A3BC2D4E')
|
||||
self.assertEqual(func('BAAACCDDDD'), 'BA3C2D4')
|
||||
self.assertEqual(func('AAABAACCDDDD'), 'A3BA2C2D4')
|
||||
print('Success: test_compress')
|
||||
|
||||
|
||||
|
|
|
@ -76,9 +76,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def compress_string(string):\n",
|
||||
|
@ -105,22 +103,24 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# %load test_compress.py\n",
|
||||
"from nose.tools import assert_equal\n",
|
||||
"import unittest\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestCompress(object):\n",
|
||||
"class TestCompress(unittest.TestCase):\n",
|
||||
"\n",
|
||||
" def test_compress(self, func):\n",
|
||||
" assert_equal(func(None), None)\n",
|
||||
" assert_equal(func(''), '')\n",
|
||||
" assert_equal(func('AABBCC'), 'AABBCC')\n",
|
||||
" assert_equal(func('AAABCCDDDD'), 'A3BCCD4')\n",
|
||||
" self.assertEqual(func(None), None)\n",
|
||||
" self.assertEqual(func(''), '')\n",
|
||||
" self.assertEqual(func('AABBCC'), 'AABBCC')\n",
|
||||
" self.assertEqual(func('AAABCCDDDD'), 'A3BCCD4')\n",
|
||||
" self.assertEqual(\n",
|
||||
" func('aaBCCEFFFFKKMMMMMMP taaammanlaarrrr seeeeeeeeek tooo'),\n",
|
||||
" 'aaBCCEF4KKM6P ta3mmanlaar4 se9k to3',\n",
|
||||
" )\n",
|
||||
" print('Success: test_compress')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
@ -159,9 +159,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
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"This notebook was prepared by [hashhar](https://github.com/hashhar), second solution added by [janhak] (https://github.com/janhak). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
|
||||
"This notebook was prepared by [hashhar](https://github.com/hashhar), second solution added by [janhak](https://github.com/janhak). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -103,10 +103,8 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def compress_string(string):\n",
|
||||
|
@ -200,10 +198,8 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def split_to_blocks(string):\n",
|
||||
|
@ -239,24 +235,33 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Overwriting test_compress.py\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"%%writefile test_compress.py\n",
|
||||
"from nose.tools import assert_equal\n",
|
||||
"import unittest\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestCompress(object):\n",
|
||||
"class TestCompress(unittest.TestCase):\n",
|
||||
"\n",
|
||||
" def test_compress(self, func):\n",
|
||||
" assert_equal(func(None), None)\n",
|
||||
" assert_equal(func(''), '')\n",
|
||||
" assert_equal(func('AABBCC'), 'AABBCC')\n",
|
||||
" assert_equal(func('AAABCCDDDD'), 'A3BCCD4')\n",
|
||||
" assert_equal(func('aaBCCEFFFFKKMMMMMMP taaammanlaarrrr seeeeeeeeek tooo'), 'aaBCCEF4KKM6P ta3mmanlaar4 se9k to3')\n",
|
||||
" self.assertEqual(func(None), None)\n",
|
||||
" self.assertEqual(func(''), '')\n",
|
||||
" self.assertEqual(func('AABBCC'), 'AABBCC')\n",
|
||||
" self.assertEqual(func('AAABCCDDDD'), 'A3BCCD4')\n",
|
||||
" self.assertEqual(\n",
|
||||
" func('aaBCCEFFFFKKMMMMMMP taaammanlaarrrr seeeeeeeeek tooo'),\n",
|
||||
" 'aaBCCEF4KKM6P ta3mmanlaar4 se9k to3',\n",
|
||||
" )\n",
|
||||
" print('Success: test_compress')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
@ -271,11 +276,17 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Success: test_compress\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"%run -i test_compress.py"
|
||||
]
|
||||
|
@ -297,9 +308,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
|
||||
}
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
from nose.tools import assert_equal
|
||||
import unittest
|
||||
|
||||
|
||||
class TestCompress(object):
|
||||
class TestCompress(unittest.TestCase):
|
||||
|
||||
def test_compress(self, func):
|
||||
assert_equal(func(None), None)
|
||||
assert_equal(func(''), '')
|
||||
assert_equal(func('AABBCC'), 'AABBCC')
|
||||
assert_equal(func('AAABCCDDDD'), 'A3BCCD4')
|
||||
assert_equal(func('aaBCCEFFFFKKMMMMMMP taaammanlaarrrr seeeeeeeeek tooo'), 'aaBCCEF4KKM6P ta3mmanlaar4 se9k to3')
|
||||
self.assertEqual(func(None), None)
|
||||
self.assertEqual(func(''), '')
|
||||
self.assertEqual(func('AABBCC'), 'AABBCC')
|
||||
self.assertEqual(func('AAABCCDDDD'), 'A3BCCD4')
|
||||
self.assertEqual(
|
||||
func('aaBCCEFFFFKKMMMMMMP taaammanlaarrrr seeeeeeeeek tooo'),
|
||||
'aaBCCEF4KKM6P ta3mmanlaar4 se9k to3',
|
||||
)
|
||||
print('Success: test_compress')
|
||||
|
||||
|
||||
|
@ -18,4 +21,4 @@ def main():
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
|
|
@ -94,9 +94,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class Solution(object):\n",
|
||||
|
@ -123,21 +121,19 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# %load test_fizz_buzz.py\n",
|
||||
"from nose.tools import assert_equal, assert_raises\n",
|
||||
"import unittest\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestFizzBuzz(object):\n",
|
||||
"class TestFizzBuzz(unittest.TestCase):\n",
|
||||
"\n",
|
||||
" def test_fizz_buzz(self):\n",
|
||||
" solution = Solution()\n",
|
||||
" assert_raises(TypeError, solution.fizz_buzz, None)\n",
|
||||
" assert_raises(ValueError, solution.fizz_buzz, 0)\n",
|
||||
" self.assertRaises(TypeError, solution.fizz_buzz, None)\n",
|
||||
" self.assertRaises(ValueError, solution.fizz_buzz, 0)\n",
|
||||
" expected = [\n",
|
||||
" '1',\n",
|
||||
" '2',\n",
|
||||
|
@ -155,7 +151,7 @@
|
|||
" '14',\n",
|
||||
" 'FizzBuzz'\n",
|
||||
" ]\n",
|
||||
" assert_equal(solution.fizz_buzz(15), expected)\n",
|
||||
" self.assertEqual(solution.fizz_buzz(15), expected)\n",
|
||||
" print('Success: test_fizz_buzz')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
@ -194,9 +190,9 @@
|
|||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.4.3"
|
||||
"version": "3.7.2"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 0
|
||||
"nbformat_minor": 1
|
||||
}
|
||||
|
|
|
@ -105,9 +105,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class Solution(object):\n",
|
||||
|
@ -140,9 +138,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
|
@ -154,15 +150,15 @@
|
|||
],
|
||||
"source": [
|
||||
"%%writefile test_fizz_buzz.py\n",
|
||||
"from nose.tools import assert_equal, assert_raises\n",
|
||||
"import unittest\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestFizzBuzz(object):\n",
|
||||
"class TestFizzBuzz(unittest.TestCase):\n",
|
||||
"\n",
|
||||
" def test_fizz_buzz(self):\n",
|
||||
" solution = Solution()\n",
|
||||
" assert_raises(TypeError, solution.fizz_buzz, None)\n",
|
||||
" assert_raises(ValueError, solution.fizz_buzz, 0)\n",
|
||||
" self.assertRaises(TypeError, solution.fizz_buzz, None)\n",
|
||||
" self.assertRaises(ValueError, solution.fizz_buzz, 0)\n",
|
||||
" expected = [\n",
|
||||
" '1',\n",
|
||||
" '2',\n",
|
||||
|
@ -180,7 +176,7 @@
|
|||
" '14',\n",
|
||||
" 'FizzBuzz'\n",
|
||||
" ]\n",
|
||||
" assert_equal(solution.fizz_buzz(15), expected)\n",
|
||||
" self.assertEqual(solution.fizz_buzz(15), expected)\n",
|
||||
" print('Success: test_fizz_buzz')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
@ -196,9 +192,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
|
@ -211,6 +205,13 @@
|
|||
"source": [
|
||||
"%run -i test_fizz_buzz.py"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
@ -229,9 +230,9 @@
|
|||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.4.3"
|
||||
"version": "3.7.2"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 0
|
||||
"nbformat_minor": 1
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
from nose.tools import assert_equal, assert_raises
|
||||
import unittest
|
||||
|
||||
|
||||
class TestFizzBuzz(object):
|
||||
class TestFizzBuzz(unittest.TestCase):
|
||||
|
||||
def test_fizz_buzz(self):
|
||||
solution = Solution()
|
||||
assert_raises(TypeError, solution.fizz_buzz, None)
|
||||
assert_raises(ValueError, solution.fizz_buzz, 0)
|
||||
self.assertRaises(TypeError, solution.fizz_buzz, None)
|
||||
self.assertRaises(ValueError, solution.fizz_buzz, 0)
|
||||
expected = [
|
||||
'1',
|
||||
'2',
|
||||
|
@ -24,7 +24,7 @@ class TestFizzBuzz(object):
|
|||
'14',
|
||||
'FizzBuzz'
|
||||
]
|
||||
assert_equal(solution.fizz_buzz(15), expected)
|
||||
self.assertEqual(solution.fizz_buzz(15), expected)
|
||||
print('Success: test_fizz_buzz')
|
||||
|
||||
|
||||
|
@ -34,4 +34,4 @@ def main():
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -79,9 +79,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class Permutations(object):\n",
|
||||
|
@ -110,23 +108,22 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# %load test_permutation_solution.py\n",
|
||||
"from nose.tools import assert_equal\n",
|
||||
"import unittest\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestPermutation(object):\n",
|
||||
"class TestPermutation(unittest.TestCase):\n",
|
||||
"\n",
|
||||
" def test_permutation(self, func):\n",
|
||||
" assert_equal(func(None, 'foo'), False)\n",
|
||||
" assert_equal(func('', 'foo'), False)\n",
|
||||
" assert_equal(func('Nib', 'bin'), False)\n",
|
||||
" assert_equal(func('act', 'cat'), True)\n",
|
||||
" assert_equal(func('a ct', 'ca t'), True)\n",
|
||||
" self.assertEqual(func(None, 'foo'), False)\n",
|
||||
" self.assertEqual(func('', 'foo'), False)\n",
|
||||
" self.assertEqual(func('Nib', 'bin'), False)\n",
|
||||
" self.assertEqual(func('act', 'cat'), True)\n",
|
||||
" self.assertEqual(func('a ct', 'ca t'), True)\n",
|
||||
" self.assertEqual(func('dog', 'doggo'), False)\n",
|
||||
" print('Success: test_permutation')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
@ -173,9 +170,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
|
||||
}
|
||||
|
|
|
@ -91,9 +91,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class Permutations(object):\n",
|
||||
|
@ -142,9 +140,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from collections import defaultdict\n",
|
||||
|
@ -176,9 +172,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
|
@ -190,18 +184,18 @@
|
|||
],
|
||||
"source": [
|
||||
"%%writefile test_permutation_solution.py\n",
|
||||
"from nose.tools import assert_equal\n",
|
||||
"import unittest\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestPermutation(object):\n",
|
||||
"class TestPermutation(unittest.TestCase):\n",
|
||||
"\n",
|
||||
" def test_permutation(self, func):\n",
|
||||
" assert_equal(func(None, 'foo'), False)\n",
|
||||
" assert_equal(func('', 'foo'), False)\n",
|
||||
" assert_equal(func('Nib', 'bin'), False)\n",
|
||||
" assert_equal(func('act', 'cat'), True)\n",
|
||||
" assert_equal(func('a ct', 'ca t'), True)\n",
|
||||
" assert_equal(func('dog', 'doggo'), False)\n",
|
||||
" self.assertEqual(func(None, 'foo'), False)\n",
|
||||
" self.assertEqual(func('', 'foo'), False)\n",
|
||||
" self.assertEqual(func('Nib', 'bin'), False)\n",
|
||||
" self.assertEqual(func('act', 'cat'), True)\n",
|
||||
" self.assertEqual(func('a ct', 'ca t'), True)\n",
|
||||
" self.assertEqual(func('dog', 'doggo'), False)\n",
|
||||
" print('Success: test_permutation')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
@ -225,9 +219,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
|
@ -259,9 +251,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
|
||||
}
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
from nose.tools import assert_equal
|
||||
import unittest
|
||||
|
||||
|
||||
class TestPermutation(object):
|
||||
class TestPermutation(unittest.TestCase):
|
||||
|
||||
def test_permutation(self, func):
|
||||
assert_equal(func(None, 'foo'), False)
|
||||
assert_equal(func('', 'foo'), False)
|
||||
assert_equal(func('Nib', 'bin'), False)
|
||||
assert_equal(func('act', 'cat'), True)
|
||||
assert_equal(func('a ct', 'ca t'), True)
|
||||
assert_equal(func('dog', 'doggo'), False)
|
||||
self.assertEqual(func(None, 'foo'), False)
|
||||
self.assertEqual(func('', 'foo'), False)
|
||||
self.assertEqual(func('Nib', 'bin'), False)
|
||||
self.assertEqual(func('act', 'cat'), True)
|
||||
self.assertEqual(func('a ct', 'ca t'), True)
|
||||
self.assertEqual(func('dog', 'doggo'), False)
|
||||
print('Success: test_permutation')
|
||||
|
||||
|
||||
|
@ -27,4 +27,4 @@ def main():
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
|
|
@ -38,4 +38,4 @@ class PriorityQueue(object):
|
|||
if node.obj is obj:
|
||||
node.key = new_key
|
||||
return node
|
||||
return None
|
||||
return None
|
||||
|
|
|
@ -137,20 +137,18 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# %load test_priority_queue.py\n",
|
||||
"from nose.tools import assert_equal\n",
|
||||
"import unittest\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestPriorityQueue(object):\n",
|
||||
"class TestPriorityQueue(unittest.TestCase):\n",
|
||||
"\n",
|
||||
" def test_priority_queue(self):\n",
|
||||
" priority_queue = PriorityQueue()\n",
|
||||
" assert_equal(priority_queue.extract_min(), None)\n",
|
||||
" self.assertEqual(priority_queue.extract_min(), None)\n",
|
||||
" priority_queue.insert(PriorityQueueNode('a', 20))\n",
|
||||
" priority_queue.insert(PriorityQueueNode('b', 5))\n",
|
||||
" priority_queue.insert(PriorityQueueNode('c', 15))\n",
|
||||
|
@ -162,7 +160,7 @@
|
|||
" mins = []\n",
|
||||
" while priority_queue.array:\n",
|
||||
" mins.append(priority_queue.extract_min().key)\n",
|
||||
" assert_equal(mins, [2, 5, 15, 19, 22, 40])\n",
|
||||
" self.assertEqual(mins, [2, 5, 15, 19, 22, 40])\n",
|
||||
" print('Success: test_min_heap')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
@ -201,9 +199,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
|
||||
}
|
||||
|
|
|
@ -108,9 +108,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
|
@ -168,9 +166,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%run priority_queue.py"
|
||||
|
@ -186,9 +182,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
|
@ -200,14 +194,14 @@
|
|||
],
|
||||
"source": [
|
||||
"%%writefile test_priority_queue.py\n",
|
||||
"from nose.tools import assert_equal\n",
|
||||
"import unittest\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestPriorityQueue(object):\n",
|
||||
"class TestPriorityQueue(unittest.TestCase):\n",
|
||||
"\n",
|
||||
" def test_priority_queue(self):\n",
|
||||
" priority_queue = PriorityQueue()\n",
|
||||
" assert_equal(priority_queue.extract_min(), None)\n",
|
||||
" self.assertEqual(priority_queue.extract_min(), None)\n",
|
||||
" priority_queue.insert(PriorityQueueNode('a', 20))\n",
|
||||
" priority_queue.insert(PriorityQueueNode('b', 5))\n",
|
||||
" priority_queue.insert(PriorityQueueNode('c', 15))\n",
|
||||
|
@ -219,7 +213,7 @@
|
|||
" mins = []\n",
|
||||
" while priority_queue.array:\n",
|
||||
" mins.append(priority_queue.extract_min().key)\n",
|
||||
" assert_equal(mins, [2, 5, 15, 19, 22, 40])\n",
|
||||
" self.assertEqual(mins, [2, 5, 15, 19, 22, 40])\n",
|
||||
" print('Success: test_min_heap')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
@ -235,9 +229,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
|
@ -268,9 +260,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
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
from nose.tools import assert_equal
|
||||
import unittest
|
||||
|
||||
|
||||
class TestPriorityQueue(object):
|
||||
class TestPriorityQueue(unittest.TestCase):
|
||||
|
||||
def test_priority_queue(self):
|
||||
priority_queue = PriorityQueue()
|
||||
assert_equal(priority_queue.extract_min(), None)
|
||||
self.assertEqual(priority_queue.extract_min(), None)
|
||||
priority_queue.insert(PriorityQueueNode('a', 20))
|
||||
priority_queue.insert(PriorityQueueNode('b', 5))
|
||||
priority_queue.insert(PriorityQueueNode('c', 15))
|
||||
|
@ -17,7 +17,7 @@ class TestPriorityQueue(object):
|
|||
mins = []
|
||||
while priority_queue.array:
|
||||
mins.append(priority_queue.extract_min().key)
|
||||
assert_equal(mins, [2, 5, 15, 19, 22, 40])
|
||||
self.assertEqual(mins, [2, 5, 15, 19, 22, 40])
|
||||
print('Success: test_min_heap')
|
||||
|
||||
|
||||
|
@ -27,4 +27,4 @@ def main():
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
|
|
@ -73,9 +73,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class ReverseString(object):\n",
|
||||
|
@ -104,21 +102,19 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# %load test_reverse_string.py\n",
|
||||
"from nose.tools import assert_equal\n",
|
||||
"import unittest\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestReverse(object):\n",
|
||||
"class TestReverse(unittest.TestCase):\n",
|
||||
"\n",
|
||||
" def test_reverse(self, func):\n",
|
||||
" assert_equal(func(None), None)\n",
|
||||
" assert_equal(func(['']), [''])\n",
|
||||
" assert_equal(func(\n",
|
||||
" self.assertEqual(func(None), None)\n",
|
||||
" self.assertEqual(func(['']), [''])\n",
|
||||
" self.assertEqual(func(\n",
|
||||
" ['f', 'o', 'o', ' ', 'b', 'a', 'r']),\n",
|
||||
" ['r', 'a', 'b', ' ', 'o', 'o', 'f'])\n",
|
||||
" print('Success: test_reverse')\n",
|
||||
|
@ -126,7 +122,7 @@
|
|||
" def test_reverse_inplace(self, func):\n",
|
||||
" target_list = ['f', 'o', 'o', ' ', 'b', 'a', 'r']\n",
|
||||
" func(target_list)\n",
|
||||
" assert_equal(target_list, ['r', 'a', 'b', ' ', 'o', 'o', 'f'])\n",
|
||||
" self.assertEqual(target_list, ['r', 'a', 'b', ' ', 'o', 'o', 'f'])\n",
|
||||
" print('Success: test_reverse_inplace')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
@ -167,9 +163,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
|
||||
}
|
||||
|
|
|
@ -86,9 +86,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from __future__ import division\n",
|
||||
|
@ -117,9 +115,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class ReverseStringAlt(object):\n",
|
||||
|
@ -145,9 +141,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
|
@ -159,15 +153,15 @@
|
|||
],
|
||||
"source": [
|
||||
"%%writefile test_reverse_string.py\n",
|
||||
"from nose.tools import assert_equal\n",
|
||||
"import unittest\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestReverse(object):\n",
|
||||
"class TestReverse(unittest.TestCase):\n",
|
||||
"\n",
|
||||
" def test_reverse(self, func):\n",
|
||||
" assert_equal(func(None), None)\n",
|
||||
" assert_equal(func(['']), [''])\n",
|
||||
" assert_equal(func(\n",
|
||||
" self.assertEqual(func(None), None)\n",
|
||||
" self.assertEqual(func(['']), [''])\n",
|
||||
" self.assertEqual(func(\n",
|
||||
" ['f', 'o', 'o', ' ', 'b', 'a', 'r']),\n",
|
||||
" ['r', 'a', 'b', ' ', 'o', 'o', 'f'])\n",
|
||||
" print('Success: test_reverse')\n",
|
||||
|
@ -175,7 +169,7 @@
|
|||
" def test_reverse_inplace(self, func):\n",
|
||||
" target_list = ['f', 'o', 'o', ' ', 'b', 'a', 'r']\n",
|
||||
" func(target_list)\n",
|
||||
" assert_equal(target_list, ['r', 'a', 'b', ' ', 'o', 'o', 'f'])\n",
|
||||
" self.assertEqual(target_list, ['r', 'a', 'b', ' ', 'o', 'o', 'f'])\n",
|
||||
" print('Success: test_reverse_inplace')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
@ -193,9 +187,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
|
@ -245,9 +237,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# %load reverse_string.cpp\n",
|
||||
|
@ -306,9 +296,9 @@
|
|||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.4.3"
|
||||
"version": "3.7.2"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 0
|
||||
"nbformat_minor": 1
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
from nose.tools import assert_equal
|
||||
import unittest
|
||||
|
||||
|
||||
class TestReverse(object):
|
||||
class TestReverse(unittest.TestCase):
|
||||
|
||||
def test_reverse(self, func):
|
||||
assert_equal(func(None), None)
|
||||
assert_equal(func(['']), [''])
|
||||
assert_equal(func(
|
||||
self.assertEqual(func(None), None)
|
||||
self.assertEqual(func(['']), [''])
|
||||
self.assertEqual(func(
|
||||
['f', 'o', 'o', ' ', 'b', 'a', 'r']),
|
||||
['r', 'a', 'b', ' ', 'o', 'o', 'f'])
|
||||
print('Success: test_reverse')
|
||||
|
@ -14,7 +14,7 @@ class TestReverse(object):
|
|||
def test_reverse_inplace(self, func):
|
||||
target_list = ['f', 'o', 'o', ' ', 'b', 'a', 'r']
|
||||
func(target_list)
|
||||
assert_equal(target_list, ['r', 'a', 'b', ' ', 'o', 'o', 'f'])
|
||||
self.assertEqual(target_list, ['r', 'a', 'b', ' ', 'o', 'o', 'f'])
|
||||
print('Success: test_reverse_inplace')
|
||||
|
||||
|
||||
|
@ -26,4 +26,4 @@ def main():
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
|
|
@ -77,9 +77,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class Rotation(object):\n",
|
||||
|
@ -113,24 +111,22 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# %load test_rotation.py\n",
|
||||
"from nose.tools import assert_equal\n",
|
||||
"import unittest\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestRotation(object):\n",
|
||||
"class TestRotation(unittest.TestCase):\n",
|
||||
"\n",
|
||||
" def test_rotation(self):\n",
|
||||
" rotation = Rotation()\n",
|
||||
" assert_equal(rotation.is_rotation('o', 'oo'), False)\n",
|
||||
" assert_equal(rotation.is_rotation(None, 'foo'), False)\n",
|
||||
" assert_equal(rotation.is_rotation('', 'foo'), False)\n",
|
||||
" assert_equal(rotation.is_rotation('', ''), True)\n",
|
||||
" assert_equal(rotation.is_rotation('foobarbaz', 'barbazfoo'), True)\n",
|
||||
" self.assertEqual(rotation.is_rotation('o', 'oo'), False)\n",
|
||||
" self.assertEqual(rotation.is_rotation(None, 'foo'), False)\n",
|
||||
" self.assertEqual(rotation.is_rotation('', 'foo'), False)\n",
|
||||
" self.assertEqual(rotation.is_rotation('', ''), True)\n",
|
||||
" self.assertEqual(rotation.is_rotation('foobarbaz', 'barbazfoo'), True)\n",
|
||||
" print('Success: test_rotation')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
@ -169,9 +165,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
|
||||
}
|
||||
|
|
|
@ -87,9 +87,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class Rotation(object):\n",
|
||||
|
@ -115,9 +113,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
|
@ -129,18 +125,18 @@
|
|||
],
|
||||
"source": [
|
||||
"%%writefile test_rotation.py\n",
|
||||
"from nose.tools import assert_equal\n",
|
||||
"import unittest\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestRotation(object):\n",
|
||||
"class TestRotation(unittest.TestCase):\n",
|
||||
"\n",
|
||||
" def test_rotation(self):\n",
|
||||
" rotation = Rotation()\n",
|
||||
" assert_equal(rotation.is_rotation('o', 'oo'), False)\n",
|
||||
" assert_equal(rotation.is_rotation(None, 'foo'), False)\n",
|
||||
" assert_equal(rotation.is_rotation('', 'foo'), False)\n",
|
||||
" assert_equal(rotation.is_rotation('', ''), True)\n",
|
||||
" assert_equal(rotation.is_rotation('foobarbaz', 'barbazfoo'), True)\n",
|
||||
" self.assertEqual(rotation.is_rotation('o', 'oo'), False)\n",
|
||||
" self.assertEqual(rotation.is_rotation(None, 'foo'), False)\n",
|
||||
" self.assertEqual(rotation.is_rotation('', 'foo'), False)\n",
|
||||
" self.assertEqual(rotation.is_rotation('', ''), True)\n",
|
||||
" self.assertEqual(rotation.is_rotation('foobarbaz', 'barbazfoo'), True)\n",
|
||||
" print('Success: test_rotation')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
@ -156,9 +152,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
|
@ -189,9 +183,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
|
||||
}
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
from nose.tools import assert_equal
|
||||
import unittest
|
||||
|
||||
|
||||
class TestRotation(object):
|
||||
class TestRotation(unittest.TestCase):
|
||||
|
||||
def test_rotation(self):
|
||||
rotation = Rotation()
|
||||
assert_equal(rotation.is_rotation('o', 'oo'), False)
|
||||
assert_equal(rotation.is_rotation(None, 'foo'), False)
|
||||
assert_equal(rotation.is_rotation('', 'foo'), False)
|
||||
assert_equal(rotation.is_rotation('', ''), True)
|
||||
assert_equal(rotation.is_rotation('foobarbaz', 'barbazfoo'), True)
|
||||
self.assertEqual(rotation.is_rotation('o', 'oo'), False)
|
||||
self.assertEqual(rotation.is_rotation(None, 'foo'), False)
|
||||
self.assertEqual(rotation.is_rotation('', 'foo'), False)
|
||||
self.assertEqual(rotation.is_rotation('', ''), True)
|
||||
self.assertEqual(rotation.is_rotation('foobarbaz', 'barbazfoo'), True)
|
||||
print('Success: test_rotation')
|
||||
|
||||
|
||||
|
@ -19,4 +19,4 @@ def main():
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
|
|
@ -77,9 +77,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class Solution(object):\n",
|
||||
|
@ -106,28 +104,26 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# %load test_str_diff.py\n",
|
||||
"from nose.tools import assert_equal, assert_raises\n",
|
||||
"import unittest\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestFindDiff(object):\n",
|
||||
"class TestFindDiff(unittest.TestCase):\n",
|
||||
"\n",
|
||||
" def test_find_diff(self):\n",
|
||||
" solution = Solution()\n",
|
||||
" assert_raises(TypeError, solution.find_diff, None)\n",
|
||||
" assert_equal(solution.find_diff('ab', 'aab'), 'a')\n",
|
||||
" assert_equal(solution.find_diff('aab', 'ab'), 'a')\n",
|
||||
" assert_equal(solution.find_diff('abcd', 'abcde'), 'e')\n",
|
||||
" assert_equal(solution.find_diff('aaabbcdd', 'abdbacade'), 'e')\n",
|
||||
" assert_equal(solution.find_diff_xor('ab', 'aab'), 'a')\n",
|
||||
" assert_equal(solution.find_diff_xor('aab', 'ab'), 'a')\n",
|
||||
" assert_equal(solution.find_diff_xor('abcd', 'abcde'), 'e')\n",
|
||||
" assert_equal(solution.find_diff_xor('aaabbcdd', 'abdbacade'), 'e')\n",
|
||||
" self.assertRaises(TypeError, solution.find_diff, None)\n",
|
||||
" self.assertEqual(solution.find_diff('ab', 'aab'), 'a')\n",
|
||||
" self.assertEqual(solution.find_diff('aab', 'ab'), 'a')\n",
|
||||
" self.assertEqual(solution.find_diff('abcd', 'abcde'), 'e')\n",
|
||||
" self.assertEqual(solution.find_diff('aaabbcdd', 'abdbacade'), 'e')\n",
|
||||
" self.assertEqual(solution.find_diff_xor('ab', 'aab'), 'a')\n",
|
||||
" self.assertEqual(solution.find_diff_xor('aab', 'ab'), 'a')\n",
|
||||
" self.assertEqual(solution.find_diff_xor('abcd', 'abcde'), 'e')\n",
|
||||
" self.assertEqual(solution.find_diff_xor('aaabbcdd', 'abdbacade'), 'e')\n",
|
||||
" print('Success: test_find_diff')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
@ -166,9 +162,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
|
||||
}
|
||||
|
|
|
@ -93,9 +93,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class Solution(object):\n",
|
||||
|
@ -140,9 +138,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
|
@ -154,22 +150,22 @@
|
|||
],
|
||||
"source": [
|
||||
"%%writefile test_str_diff.py\n",
|
||||
"from nose.tools import assert_equal, assert_raises\n",
|
||||
"import unittest\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestFindDiff(object):\n",
|
||||
"class TestFindDiff(unittest.TestCase):\n",
|
||||
"\n",
|
||||
" def test_find_diff(self):\n",
|
||||
" solution = Solution()\n",
|
||||
" assert_raises(TypeError, solution.find_diff, None)\n",
|
||||
" assert_equal(solution.find_diff('ab', 'aab'), 'a')\n",
|
||||
" assert_equal(solution.find_diff('aab', 'ab'), 'a')\n",
|
||||
" assert_equal(solution.find_diff('abcd', 'abcde'), 'e')\n",
|
||||
" assert_equal(solution.find_diff('aaabbcdd', 'abdbacade'), 'e')\n",
|
||||
" assert_equal(solution.find_diff_xor('ab', 'aab'), 'a')\n",
|
||||
" assert_equal(solution.find_diff_xor('aab', 'ab'), 'a')\n",
|
||||
" assert_equal(solution.find_diff_xor('abcd', 'abcde'), 'e')\n",
|
||||
" assert_equal(solution.find_diff_xor('aaabbcdd', 'abdbacade'), 'e')\n",
|
||||
" self.assertRaises(TypeError, solution.find_diff, None)\n",
|
||||
" self.assertEqual(solution.find_diff('ab', 'aab'), 'a')\n",
|
||||
" self.assertEqual(solution.find_diff('aab', 'ab'), 'a')\n",
|
||||
" self.assertEqual(solution.find_diff('abcd', 'abcde'), 'e')\n",
|
||||
" self.assertEqual(solution.find_diff('aaabbcdd', 'abdbacade'), 'e')\n",
|
||||
" self.assertEqual(solution.find_diff_xor('ab', 'aab'), 'a')\n",
|
||||
" self.assertEqual(solution.find_diff_xor('aab', 'ab'), 'a')\n",
|
||||
" self.assertEqual(solution.find_diff_xor('abcd', 'abcde'), 'e')\n",
|
||||
" self.assertEqual(solution.find_diff_xor('aaabbcdd', 'abdbacade'), 'e')\n",
|
||||
" print('Success: test_find_diff')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
@ -185,9 +181,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
|
@ -218,9 +212,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
|
||||
}
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
from nose.tools import assert_equal, assert_raises
|
||||
import unittest
|
||||
|
||||
|
||||
class TestFindDiff(object):
|
||||
class TestFindDiff(unittest.TestCase):
|
||||
|
||||
def test_find_diff(self):
|
||||
solution = Solution()
|
||||
assert_raises(TypeError, solution.find_diff, None)
|
||||
assert_equal(solution.find_diff('ab', 'aab'), 'a')
|
||||
assert_equal(solution.find_diff('aab', 'ab'), 'a')
|
||||
assert_equal(solution.find_diff('abcd', 'abcde'), 'e')
|
||||
assert_equal(solution.find_diff('aaabbcdd', 'abdbacade'), 'e')
|
||||
assert_equal(solution.find_diff_xor('ab', 'aab'), 'a')
|
||||
assert_equal(solution.find_diff_xor('aab', 'ab'), 'a')
|
||||
assert_equal(solution.find_diff_xor('abcd', 'abcde'), 'e')
|
||||
assert_equal(solution.find_diff_xor('aaabbcdd', 'abdbacade'), 'e')
|
||||
self.assertRaises(TypeError, solution.find_diff, None)
|
||||
self.assertEqual(solution.find_diff('ab', 'aab'), 'a')
|
||||
self.assertEqual(solution.find_diff('aab', 'ab'), 'a')
|
||||
self.assertEqual(solution.find_diff('abcd', 'abcde'), 'e')
|
||||
self.assertEqual(solution.find_diff('aaabbcdd', 'abdbacade'), 'e')
|
||||
self.assertEqual(solution.find_diff_xor('ab', 'aab'), 'a')
|
||||
self.assertEqual(solution.find_diff_xor('aab', 'ab'), 'a')
|
||||
self.assertEqual(solution.find_diff_xor('abcd', 'abcde'), 'e')
|
||||
self.assertEqual(solution.find_diff_xor('aaabbcdd', 'abdbacade'), 'e')
|
||||
print('Success: test_find_diff')
|
||||
|
||||
|
||||
|
@ -23,4 +23,4 @@ def main():
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
from nose.tools import assert_equal, assert_raises
|
||||
import unittest
|
||||
|
||||
|
||||
class TestTwoSum(object):
|
||||
class TestTwoSum(unittest.TestCase):
|
||||
|
||||
def test_two_sum(self):
|
||||
solution = Solution()
|
||||
assert_raises(TypeError, solution.two_sum, None, None)
|
||||
assert_raises(ValueError, solution.two_sum, [], 0)
|
||||
self.assertRaises(TypeError, solution.two_sum, None, None)
|
||||
self.assertRaises(ValueError, solution.two_sum, [], 0)
|
||||
target = 7
|
||||
nums = [1, 3, 2, -7, 5]
|
||||
expected = [2, 4]
|
||||
assert_equal(solution.two_sum(nums, target), expected)
|
||||
self.assertEqual(solution.two_sum(nums, target), expected)
|
||||
print('Success: test_two_sum')
|
||||
|
||||
|
||||
|
@ -20,4 +20,4 @@ def main():
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
|
|
@ -80,9 +80,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class Solution(object):\n",
|
||||
|
@ -109,25 +107,23 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# %load test_two_sum.py\n",
|
||||
"from nose.tools import assert_equal, assert_raises\n",
|
||||
"import unittest\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestTwoSum(object):\n",
|
||||
"class TestTwoSum(unittest.TestCase):\n",
|
||||
"\n",
|
||||
" def test_two_sum(self):\n",
|
||||
" solution = Solution()\n",
|
||||
" assert_raises(TypeError, solution.two_sum, None, None)\n",
|
||||
" assert_raises(ValueError, solution.two_sum, [], 0)\n",
|
||||
" self.assertRaises(TypeError, solution.two_sum, None, None)\n",
|
||||
" self.assertRaises(ValueError, solution.two_sum, [], 0)\n",
|
||||
" target = 7\n",
|
||||
" nums = [1, 3, 2, -7, 5]\n",
|
||||
" expected = [2, 4]\n",
|
||||
" assert_equal(solution.two_sum(nums, target), expected)\n",
|
||||
" self.assertEqual(solution.two_sum(nums, target), expected)\n",
|
||||
" print('Success: test_two_sum')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
@ -166,9 +162,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
|
||||
}
|
||||
|
|
|
@ -156,9 +156,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class Solution(object):\n",
|
||||
|
@ -188,9 +186,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
|
@ -202,19 +198,19 @@
|
|||
],
|
||||
"source": [
|
||||
"%%writefile test_two_sum.py\n",
|
||||
"from nose.tools import assert_equal, assert_raises\n",
|
||||
"import unittest\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestTwoSum(object):\n",
|
||||
"class TestTwoSum(unittest.TestCase):\n",
|
||||
"\n",
|
||||
" def test_two_sum(self):\n",
|
||||
" solution = Solution()\n",
|
||||
" assert_raises(TypeError, solution.two_sum, None, None)\n",
|
||||
" assert_raises(ValueError, solution.two_sum, [], 0)\n",
|
||||
" self.assertRaises(TypeError, solution.two_sum, None, None)\n",
|
||||
" self.assertRaises(ValueError, solution.two_sum, [], 0)\n",
|
||||
" target = 7\n",
|
||||
" nums = [1, 3, 2, -7, 5]\n",
|
||||
" expected = [2, 4]\n",
|
||||
" assert_equal(solution.two_sum(nums, target), expected)\n",
|
||||
" self.assertEqual(solution.two_sum(nums, target), expected)\n",
|
||||
" print('Success: test_two_sum')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
@ -230,9 +226,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
|
@ -263,9 +257,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
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
from nose.tools import assert_equal
|
||||
import unittest
|
||||
|
||||
|
||||
class TestUniqueChars(object):
|
||||
class TestUniqueChars(unittest.TestCase):
|
||||
|
||||
def test_unique_chars(self, func):
|
||||
assert_equal(func(None), False)
|
||||
assert_equal(func(''), True)
|
||||
assert_equal(func('foo'), False)
|
||||
assert_equal(func('bar'), True)
|
||||
self.assertEqual(func(None), False)
|
||||
self.assertEqual(func(''), True)
|
||||
self.assertEqual(func('foo'), False)
|
||||
self.assertEqual(func('bar'), True)
|
||||
print('Success: test_unique_chars')
|
||||
|
||||
|
||||
|
@ -27,4 +27,4 @@ def main():
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
|
|
@ -76,9 +76,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class UniqueChars(object):\n",
|
||||
|
@ -105,22 +103,20 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# %load test_unique_chars.py\n",
|
||||
"from nose.tools import assert_equal\n",
|
||||
"import unittest\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestUniqueChars(object):\n",
|
||||
"class TestUniqueChars(unittest.TestCase):\n",
|
||||
"\n",
|
||||
" def test_unique_chars(self, func):\n",
|
||||
" assert_equal(func(None), False)\n",
|
||||
" assert_equal(func(''), True)\n",
|
||||
" assert_equal(func('foo'), False)\n",
|
||||
" assert_equal(func('bar'), True)\n",
|
||||
" self.assertEqual(func(None), False)\n",
|
||||
" self.assertEqual(func(''), True)\n",
|
||||
" self.assertEqual(func('foo'), False)\n",
|
||||
" self.assertEqual(func('bar'), True)\n",
|
||||
" print('Success: test_unique_chars')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
@ -169,9 +165,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
|
||||
}
|
||||
|
|
|
@ -88,9 +88,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class UniqueCharsSet(object):\n",
|
||||
|
@ -135,9 +133,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class UniqueChars(object):\n",
|
||||
|
@ -183,9 +179,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class UniqueCharsInPlace(object):\n",
|
||||
|
@ -209,9 +203,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
|
@ -223,16 +215,16 @@
|
|||
],
|
||||
"source": [
|
||||
"%%writefile test_unique_chars.py\n",
|
||||
"from nose.tools import assert_equal\n",
|
||||
"import unittest\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestUniqueChars(object):\n",
|
||||
"class TestUniqueChars(unittest.TestCase):\n",
|
||||
"\n",
|
||||
" def test_unique_chars(self, func):\n",
|
||||
" assert_equal(func(None), False)\n",
|
||||
" assert_equal(func(''), True)\n",
|
||||
" assert_equal(func('foo'), False)\n",
|
||||
" assert_equal(func('bar'), True)\n",
|
||||
" self.assertEqual(func(None), False)\n",
|
||||
" self.assertEqual(func(''), True)\n",
|
||||
" self.assertEqual(func('foo'), False)\n",
|
||||
" self.assertEqual(func('bar'), True)\n",
|
||||
" print('Success: test_unique_chars')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
@ -258,9 +250,7 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
|
@ -293,9 +283,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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user