mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-04 00:18:02 +00:00
@@ -76,9 +76,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"class CompressString(object):\n",
|
"class CompressString(object):\n",
|
||||||
@@ -107,24 +105,22 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# %load test_compress.py\n",
|
"# %load test_compress.py\n",
|
||||||
"from nose.tools import assert_equal\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestCompress(object):\n",
|
"class TestCompress(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_compress(self, func):\n",
|
" def test_compress(self, func):\n",
|
||||||
" assert_equal(func(None), None)\n",
|
" self.assertEqual(func(None), None)\n",
|
||||||
" assert_equal(func(''), '')\n",
|
" self.assertEqual(func(''), '')\n",
|
||||||
" assert_equal(func('AABBCC'), 'AABBCC')\n",
|
" self.assertEqual(func('AABBCC'), 'AABBCC')\n",
|
||||||
" assert_equal(func('AAABCCDDDDE'), 'A3BC2D4E')\n",
|
" self.assertEqual(func('AAABCCDDDDE'), 'A3BC2D4E')\n",
|
||||||
" assert_equal(func('BAAACCDDDD'), 'BA3C2D4')\n",
|
" self.assertEqual(func('BAAACCDDDD'), 'BA3C2D4')\n",
|
||||||
" assert_equal(func('AAABAACCDDDD'), 'A3BA2C2D4')\n",
|
" self.assertEqual(func('AAABAACCDDDD'), 'A3BA2C2D4')\n",
|
||||||
" print('Success: test_compress')\n",
|
" print('Success: test_compress')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -164,9 +160,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.0"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
"nbformat_minor": 0
|
"nbformat_minor": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,9 +92,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 1,
|
"execution_count": 1,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"class CompressString(object):\n",
|
"class CompressString(object):\n",
|
||||||
@@ -129,9 +127,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 2,
|
"execution_count": 2,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -143,18 +139,18 @@
|
|||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"%%writefile test_compress.py\n",
|
"%%writefile test_compress.py\n",
|
||||||
"from nose.tools import assert_equal\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestCompress(object):\n",
|
"class TestCompress(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_compress(self, func):\n",
|
" def test_compress(self, func):\n",
|
||||||
" assert_equal(func(None), None)\n",
|
" self.assertEqual(func(None), None)\n",
|
||||||
" assert_equal(func(''), '')\n",
|
" self.assertEqual(func(''), '')\n",
|
||||||
" assert_equal(func('AABBCC'), 'AABBCC')\n",
|
" self.assertEqual(func('AABBCC'), 'AABBCC')\n",
|
||||||
" assert_equal(func('AAABCCDDDDE'), 'A3BC2D4E')\n",
|
" self.assertEqual(func('AAABCCDDDDE'), 'A3BC2D4E')\n",
|
||||||
" assert_equal(func('BAAACCDDDD'), 'BA3C2D4')\n",
|
" self.assertEqual(func('BAAACCDDDD'), 'BA3C2D4')\n",
|
||||||
" assert_equal(func('AAABAACCDDDD'), 'A3BA2C2D4')\n",
|
" self.assertEqual(func('AAABAACCDDDD'), 'A3BA2C2D4')\n",
|
||||||
" print('Success: test_compress')\n",
|
" print('Success: test_compress')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -171,9 +167,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": 3,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -204,9 +198,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.0"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"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):
|
def test_compress(self, func):
|
||||||
assert_equal(func(None), None)
|
self.assertEqual(func(None), None)
|
||||||
assert_equal(func(''), '')
|
self.assertEqual(func(''), '')
|
||||||
assert_equal(func('ABC'), 'ABC')
|
self.assertEqual(func('AABBCC'), 'AABBCC')
|
||||||
assert_equal(func('AABBCC'), 'AABBCC')
|
self.assertEqual(func('AAABCCDDDDE'), 'A3BC2D4E')
|
||||||
assert_equal(func('AAABCCDDDDE'), 'A3BC2D4E')
|
self.assertEqual(func('BAAACCDDDD'), 'BA3C2D4')
|
||||||
assert_equal(func('BAAACCDDDD'), 'BA3C2D4')
|
self.assertEqual(func('AAABAACCDDDD'), 'A3BA2C2D4')
|
||||||
assert_equal(func('AAABAACCDDDD'), 'A3BA2C2D4')
|
|
||||||
print('Success: test_compress')
|
print('Success: test_compress')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -76,9 +76,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"def compress_string(string):\n",
|
"def compress_string(string):\n",
|
||||||
@@ -105,22 +103,24 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# %load test_compress.py\n",
|
"# %load test_compress.py\n",
|
||||||
"from nose.tools import assert_equal\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestCompress(object):\n",
|
"class TestCompress(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_compress(self, func):\n",
|
" def test_compress(self, func):\n",
|
||||||
" assert_equal(func(None), None)\n",
|
" self.assertEqual(func(None), None)\n",
|
||||||
" assert_equal(func(''), '')\n",
|
" self.assertEqual(func(''), '')\n",
|
||||||
" assert_equal(func('AABBCC'), 'AABBCC')\n",
|
" self.assertEqual(func('AABBCC'), 'AABBCC')\n",
|
||||||
" assert_equal(func('AAABCCDDDD'), 'A3BCCD4')\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",
|
" print('Success: test_compress')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -159,9 +159,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.0"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
"nbformat_minor": 0
|
"nbformat_minor": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"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",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": 1,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"def compress_string(string):\n",
|
"def compress_string(string):\n",
|
||||||
@@ -200,10 +198,8 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": 2,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": true
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"def split_to_blocks(string):\n",
|
"def split_to_blocks(string):\n",
|
||||||
@@ -239,24 +235,33 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": 3,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
"outputs": [
|
||||||
},
|
{
|
||||||
"outputs": [],
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"Overwriting test_compress.py\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"%%writefile test_compress.py\n",
|
"%%writefile test_compress.py\n",
|
||||||
"from nose.tools import assert_equal\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestCompress(object):\n",
|
"class TestCompress(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_compress(self, func):\n",
|
" def test_compress(self, func):\n",
|
||||||
" assert_equal(func(None), None)\n",
|
" self.assertEqual(func(None), None)\n",
|
||||||
" assert_equal(func(''), '')\n",
|
" self.assertEqual(func(''), '')\n",
|
||||||
" assert_equal(func('AABBCC'), 'AABBCC')\n",
|
" self.assertEqual(func('AABBCC'), 'AABBCC')\n",
|
||||||
" assert_equal(func('AAABCCDDDD'), 'A3BCCD4')\n",
|
" self.assertEqual(func('AAABCCDDDD'), 'A3BCCD4')\n",
|
||||||
" assert_equal(func('aaBCCEFFFFKKMMMMMMP taaammanlaarrrr seeeeeeeeek tooo'), 'aaBCCEF4KKM6P ta3mmanlaar4 se9k to3')\n",
|
" self.assertEqual(\n",
|
||||||
|
" func('aaBCCEFFFFKKMMMMMMP taaammanlaarrrr seeeeeeeeek tooo'),\n",
|
||||||
|
" 'aaBCCEF4KKM6P ta3mmanlaar4 se9k to3',\n",
|
||||||
|
" )\n",
|
||||||
" print('Success: test_compress')\n",
|
" print('Success: test_compress')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -271,11 +276,17 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": 4,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
"outputs": [
|
||||||
},
|
{
|
||||||
"outputs": [],
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"Success: test_compress\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"%run -i test_compress.py"
|
"%run -i test_compress.py"
|
||||||
]
|
]
|
||||||
@@ -297,9 +308,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.0"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"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):
|
def test_compress(self, func):
|
||||||
assert_equal(func(None), None)
|
self.assertEqual(func(None), None)
|
||||||
assert_equal(func(''), '')
|
self.assertEqual(func(''), '')
|
||||||
assert_equal(func('AABBCC'), 'AABBCC')
|
self.assertEqual(func('AABBCC'), 'AABBCC')
|
||||||
assert_equal(func('AAABCCDDDD'), 'A3BCCD4')
|
self.assertEqual(func('AAABCCDDDD'), 'A3BCCD4')
|
||||||
assert_equal(func('aaBCCEFFFFKKMMMMMMP taaammanlaarrrr seeeeeeeeek tooo'), 'aaBCCEF4KKM6P ta3mmanlaar4 se9k to3')
|
self.assertEqual(
|
||||||
|
func('aaBCCEFFFFKKMMMMMMP taaammanlaarrrr seeeeeeeeek tooo'),
|
||||||
|
'aaBCCEF4KKM6P ta3mmanlaar4 se9k to3',
|
||||||
|
)
|
||||||
print('Success: test_compress')
|
print('Success: test_compress')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -94,9 +94,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"class Solution(object):\n",
|
"class Solution(object):\n",
|
||||||
@@ -123,21 +121,19 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# %load test_fizz_buzz.py\n",
|
"# %load test_fizz_buzz.py\n",
|
||||||
"from nose.tools import assert_equal, assert_raises\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestFizzBuzz(object):\n",
|
"class TestFizzBuzz(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_fizz_buzz(self):\n",
|
" def test_fizz_buzz(self):\n",
|
||||||
" solution = Solution()\n",
|
" solution = Solution()\n",
|
||||||
" assert_raises(TypeError, solution.fizz_buzz, None)\n",
|
" self.assertRaises(TypeError, solution.fizz_buzz, None)\n",
|
||||||
" assert_raises(ValueError, solution.fizz_buzz, 0)\n",
|
" self.assertRaises(ValueError, solution.fizz_buzz, 0)\n",
|
||||||
" expected = [\n",
|
" expected = [\n",
|
||||||
" '1',\n",
|
" '1',\n",
|
||||||
" '2',\n",
|
" '2',\n",
|
||||||
@@ -155,7 +151,7 @@
|
|||||||
" '14',\n",
|
" '14',\n",
|
||||||
" 'FizzBuzz'\n",
|
" 'FizzBuzz'\n",
|
||||||
" ]\n",
|
" ]\n",
|
||||||
" assert_equal(solution.fizz_buzz(15), expected)\n",
|
" self.assertEqual(solution.fizz_buzz(15), expected)\n",
|
||||||
" print('Success: test_fizz_buzz')\n",
|
" print('Success: test_fizz_buzz')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -194,9 +190,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.4.3"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
"nbformat_minor": 0
|
"nbformat_minor": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,9 +105,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 1,
|
"execution_count": 1,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"class Solution(object):\n",
|
"class Solution(object):\n",
|
||||||
@@ -140,9 +138,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 2,
|
"execution_count": 2,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -154,15 +150,15 @@
|
|||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"%%writefile test_fizz_buzz.py\n",
|
"%%writefile test_fizz_buzz.py\n",
|
||||||
"from nose.tools import assert_equal, assert_raises\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestFizzBuzz(object):\n",
|
"class TestFizzBuzz(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_fizz_buzz(self):\n",
|
" def test_fizz_buzz(self):\n",
|
||||||
" solution = Solution()\n",
|
" solution = Solution()\n",
|
||||||
" assert_raises(TypeError, solution.fizz_buzz, None)\n",
|
" self.assertRaises(TypeError, solution.fizz_buzz, None)\n",
|
||||||
" assert_raises(ValueError, solution.fizz_buzz, 0)\n",
|
" self.assertRaises(ValueError, solution.fizz_buzz, 0)\n",
|
||||||
" expected = [\n",
|
" expected = [\n",
|
||||||
" '1',\n",
|
" '1',\n",
|
||||||
" '2',\n",
|
" '2',\n",
|
||||||
@@ -180,7 +176,7 @@
|
|||||||
" '14',\n",
|
" '14',\n",
|
||||||
" 'FizzBuzz'\n",
|
" 'FizzBuzz'\n",
|
||||||
" ]\n",
|
" ]\n",
|
||||||
" assert_equal(solution.fizz_buzz(15), expected)\n",
|
" self.assertEqual(solution.fizz_buzz(15), expected)\n",
|
||||||
" print('Success: test_fizz_buzz')\n",
|
" print('Success: test_fizz_buzz')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -196,9 +192,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": 3,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -211,6 +205,13 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"%run -i test_fizz_buzz.py"
|
"%run -i test_fizz_buzz.py"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
@@ -229,9 +230,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.4.3"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"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):
|
def test_fizz_buzz(self):
|
||||||
solution = Solution()
|
solution = Solution()
|
||||||
assert_raises(TypeError, solution.fizz_buzz, None)
|
self.assertRaises(TypeError, solution.fizz_buzz, None)
|
||||||
assert_raises(ValueError, solution.fizz_buzz, 0)
|
self.assertRaises(ValueError, solution.fizz_buzz, 0)
|
||||||
expected = [
|
expected = [
|
||||||
'1',
|
'1',
|
||||||
'2',
|
'2',
|
||||||
@@ -24,7 +24,7 @@ class TestFizzBuzz(object):
|
|||||||
'14',
|
'14',
|
||||||
'FizzBuzz'
|
'FizzBuzz'
|
||||||
]
|
]
|
||||||
assert_equal(solution.fizz_buzz(15), expected)
|
self.assertEqual(solution.fizz_buzz(15), expected)
|
||||||
print('Success: test_fizz_buzz')
|
print('Success: test_fizz_buzz')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -79,9 +79,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"class Item(object):\n",
|
"class Item(object):\n",
|
||||||
@@ -133,16 +131,14 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# %load test_hash_map.py\n",
|
"# %load test_hash_map.py\n",
|
||||||
"from nose.tools import assert_equal, assert_raises\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestHashMap(object):\n",
|
"class TestHashMap(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" # TODO: It would be better if we had unit tests for each\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",
|
" # method in addition to the following end-to-end test\n",
|
||||||
@@ -150,31 +146,31 @@
|
|||||||
" hash_table = HashTable(10)\n",
|
" hash_table = HashTable(10)\n",
|
||||||
"\n",
|
"\n",
|
||||||
" print(\"Test: get on an empty hash table index\")\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",
|
"\n",
|
||||||
" print(\"Test: set on an empty hash table index\")\n",
|
" print(\"Test: set on an empty hash table index\")\n",
|
||||||
" hash_table.set(0, 'foo')\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",
|
" hash_table.set(1, 'bar')\n",
|
||||||
" assert_equal(hash_table.get(1), 'bar')\n",
|
" self.assertEqual(hash_table.get(1), 'bar')\n",
|
||||||
"\n",
|
"\n",
|
||||||
" print(\"Test: set on a non empty hash table index\")\n",
|
" print(\"Test: set on a non empty hash table index\")\n",
|
||||||
" hash_table.set(10, 'foo2')\n",
|
" hash_table.set(10, 'foo2')\n",
|
||||||
" assert_equal(hash_table.get(0), 'foo')\n",
|
" self.assertEqual(hash_table.get(0), 'foo')\n",
|
||||||
" assert_equal(hash_table.get(10), 'foo2')\n",
|
" self.assertEqual(hash_table.get(10), 'foo2')\n",
|
||||||
"\n",
|
"\n",
|
||||||
" print(\"Test: set on a key that already exists\")\n",
|
" print(\"Test: set on a key that already exists\")\n",
|
||||||
" hash_table.set(10, 'foo3')\n",
|
" hash_table.set(10, 'foo3')\n",
|
||||||
" assert_equal(hash_table.get(0), 'foo')\n",
|
" self.assertEqual(hash_table.get(0), 'foo')\n",
|
||||||
" assert_equal(hash_table.get(10), 'foo3')\n",
|
" self.assertEqual(hash_table.get(10), 'foo3')\n",
|
||||||
"\n",
|
"\n",
|
||||||
" print(\"Test: remove on a key that already exists\")\n",
|
" print(\"Test: remove on a key that already exists\")\n",
|
||||||
" hash_table.remove(10)\n",
|
" hash_table.remove(10)\n",
|
||||||
" assert_equal(hash_table.get(0), 'foo')\n",
|
" self.assertEqual(hash_table.get(0), 'foo')\n",
|
||||||
" assert_raises(KeyError, hash_table.get, 10)\n",
|
" self.assertRaises(KeyError, hash_table.get, 10)\n",
|
||||||
"\n",
|
"\n",
|
||||||
" print(\"Test: remove on a key that doesn't exist\")\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",
|
"\n",
|
||||||
" print('Success: test_end_to_end')\n",
|
" print('Success: test_end_to_end')\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -214,9 +210,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.0"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
"nbformat_minor": 0
|
"nbformat_minor": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,9 +114,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 1,
|
"execution_count": 1,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"class Item(object):\n",
|
"class Item(object):\n",
|
||||||
@@ -169,9 +167,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 2,
|
"execution_count": 2,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -183,10 +179,10 @@
|
|||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"%%writefile test_hash_map.py\n",
|
"%%writefile test_hash_map.py\n",
|
||||||
"from nose.tools import assert_equal, assert_raises\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestHashMap(object):\n",
|
"class TestHashMap(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" # TODO: It would be better if we had unit tests for each\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",
|
" # method in addition to the following end-to-end test\n",
|
||||||
@@ -194,31 +190,31 @@
|
|||||||
" hash_table = HashTable(10)\n",
|
" hash_table = HashTable(10)\n",
|
||||||
"\n",
|
"\n",
|
||||||
" print(\"Test: get on an empty hash table index\")\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",
|
"\n",
|
||||||
" print(\"Test: set on an empty hash table index\")\n",
|
" print(\"Test: set on an empty hash table index\")\n",
|
||||||
" hash_table.set(0, 'foo')\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",
|
" hash_table.set(1, 'bar')\n",
|
||||||
" assert_equal(hash_table.get(1), 'bar')\n",
|
" self.assertEqual(hash_table.get(1), 'bar')\n",
|
||||||
"\n",
|
"\n",
|
||||||
" print(\"Test: set on a non empty hash table index\")\n",
|
" print(\"Test: set on a non empty hash table index\")\n",
|
||||||
" hash_table.set(10, 'foo2')\n",
|
" hash_table.set(10, 'foo2')\n",
|
||||||
" assert_equal(hash_table.get(0), 'foo')\n",
|
" self.assertEqual(hash_table.get(0), 'foo')\n",
|
||||||
" assert_equal(hash_table.get(10), 'foo2')\n",
|
" self.assertEqual(hash_table.get(10), 'foo2')\n",
|
||||||
"\n",
|
"\n",
|
||||||
" print(\"Test: set on a key that already exists\")\n",
|
" print(\"Test: set on a key that already exists\")\n",
|
||||||
" hash_table.set(10, 'foo3')\n",
|
" hash_table.set(10, 'foo3')\n",
|
||||||
" assert_equal(hash_table.get(0), 'foo')\n",
|
" self.assertEqual(hash_table.get(0), 'foo')\n",
|
||||||
" assert_equal(hash_table.get(10), 'foo3')\n",
|
" self.assertEqual(hash_table.get(10), 'foo3')\n",
|
||||||
"\n",
|
"\n",
|
||||||
" print(\"Test: remove on a key that already exists\")\n",
|
" print(\"Test: remove on a key that already exists\")\n",
|
||||||
" hash_table.remove(10)\n",
|
" hash_table.remove(10)\n",
|
||||||
" assert_equal(hash_table.get(0), 'foo')\n",
|
" self.assertEqual(hash_table.get(0), 'foo')\n",
|
||||||
" assert_raises(KeyError, hash_table.get, 10)\n",
|
" self.assertRaises(KeyError, hash_table.get, 10)\n",
|
||||||
"\n",
|
"\n",
|
||||||
" print(\"Test: remove on a key that doesn't exist\")\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",
|
"\n",
|
||||||
" print('Success: test_end_to_end')\n",
|
" print('Success: test_end_to_end')\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -235,9 +231,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": 3,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -256,6 +250,13 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"run -i test_hash_map.py"
|
"run -i test_hash_map.py"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
@@ -274,9 +275,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.0"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"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
|
# TODO: It would be better if we had unit tests for each
|
||||||
# method in addition to the following end-to-end test
|
# method in addition to the following end-to-end test
|
||||||
@@ -9,31 +9,31 @@ class TestHashMap(object):
|
|||||||
hash_table = HashTable(10)
|
hash_table = HashTable(10)
|
||||||
|
|
||||||
print("Test: get on an empty hash table index")
|
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")
|
print("Test: set on an empty hash table index")
|
||||||
hash_table.set(0, 'foo')
|
hash_table.set(0, 'foo')
|
||||||
assert_equal(hash_table.get(0), 'foo')
|
self.assertEqual(hash_table.get(0), 'foo')
|
||||||
hash_table.set(1, 'bar')
|
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")
|
print("Test: set on a non empty hash table index")
|
||||||
hash_table.set(10, 'foo2')
|
hash_table.set(10, 'foo2')
|
||||||
assert_equal(hash_table.get(0), 'foo')
|
self.assertEqual(hash_table.get(0), 'foo')
|
||||||
assert_equal(hash_table.get(10), 'foo2')
|
self.assertEqual(hash_table.get(10), 'foo2')
|
||||||
|
|
||||||
print("Test: set on a key that already exists")
|
print("Test: set on a key that already exists")
|
||||||
hash_table.set(10, 'foo3')
|
hash_table.set(10, 'foo3')
|
||||||
assert_equal(hash_table.get(0), 'foo')
|
self.assertEqual(hash_table.get(0), 'foo')
|
||||||
assert_equal(hash_table.get(10), 'foo3')
|
self.assertEqual(hash_table.get(10), 'foo3')
|
||||||
|
|
||||||
print("Test: remove on a key that already exists")
|
print("Test: remove on a key that already exists")
|
||||||
hash_table.remove(10)
|
hash_table.remove(10)
|
||||||
assert_equal(hash_table.get(0), 'foo')
|
self.assertEqual(hash_table.get(0), 'foo')
|
||||||
assert_raises(KeyError, hash_table.get, 10)
|
self.assertRaises(KeyError, hash_table.get, 10)
|
||||||
|
|
||||||
print("Test: remove on a key that doesn't exist")
|
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')
|
print('Success: test_end_to_end')
|
||||||
|
|
||||||
|
|||||||
@@ -79,9 +79,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"class Permutations(object):\n",
|
"class Permutations(object):\n",
|
||||||
@@ -110,23 +108,22 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# %load test_permutation_solution.py\n",
|
"# %load test_permutation_solution.py\n",
|
||||||
"from nose.tools import assert_equal\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestPermutation(object):\n",
|
"class TestPermutation(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_permutation(self, func):\n",
|
" def test_permutation(self, func):\n",
|
||||||
" assert_equal(func(None, 'foo'), False)\n",
|
" self.assertEqual(func(None, 'foo'), False)\n",
|
||||||
" assert_equal(func('', 'foo'), False)\n",
|
" self.assertEqual(func('', 'foo'), False)\n",
|
||||||
" assert_equal(func('Nib', 'bin'), False)\n",
|
" self.assertEqual(func('Nib', 'bin'), False)\n",
|
||||||
" assert_equal(func('act', 'cat'), True)\n",
|
" self.assertEqual(func('act', 'cat'), True)\n",
|
||||||
" assert_equal(func('a ct', 'ca t'), True)\n",
|
" self.assertEqual(func('a ct', 'ca t'), True)\n",
|
||||||
|
" self.assertEqual(func('dog', 'doggo'), False)\n",
|
||||||
" print('Success: test_permutation')\n",
|
" print('Success: test_permutation')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -173,9 +170,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.0"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
"nbformat_minor": 0
|
"nbformat_minor": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,9 +91,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 1,
|
"execution_count": 1,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"class Permutations(object):\n",
|
"class Permutations(object):\n",
|
||||||
@@ -142,9 +140,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 2,
|
"execution_count": 2,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"from collections import defaultdict\n",
|
"from collections import defaultdict\n",
|
||||||
@@ -176,9 +172,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": 3,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -190,18 +184,18 @@
|
|||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"%%writefile test_permutation_solution.py\n",
|
"%%writefile test_permutation_solution.py\n",
|
||||||
"from nose.tools import assert_equal\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestPermutation(object):\n",
|
"class TestPermutation(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_permutation(self, func):\n",
|
" def test_permutation(self, func):\n",
|
||||||
" assert_equal(func(None, 'foo'), False)\n",
|
" self.assertEqual(func(None, 'foo'), False)\n",
|
||||||
" assert_equal(func('', 'foo'), False)\n",
|
" self.assertEqual(func('', 'foo'), False)\n",
|
||||||
" assert_equal(func('Nib', 'bin'), False)\n",
|
" self.assertEqual(func('Nib', 'bin'), False)\n",
|
||||||
" assert_equal(func('act', 'cat'), True)\n",
|
" self.assertEqual(func('act', 'cat'), True)\n",
|
||||||
" assert_equal(func('a ct', 'ca t'), True)\n",
|
" self.assertEqual(func('a ct', 'ca t'), True)\n",
|
||||||
" assert_equal(func('dog', 'doggo'), False)\n",
|
" self.assertEqual(func('dog', 'doggo'), False)\n",
|
||||||
" print('Success: test_permutation')\n",
|
" print('Success: test_permutation')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -225,9 +219,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 4,
|
"execution_count": 4,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -259,9 +251,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.0"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"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):
|
def test_permutation(self, func):
|
||||||
assert_equal(func(None, 'foo'), False)
|
self.assertEqual(func(None, 'foo'), False)
|
||||||
assert_equal(func('', 'foo'), False)
|
self.assertEqual(func('', 'foo'), False)
|
||||||
assert_equal(func('Nib', 'bin'), False)
|
self.assertEqual(func('Nib', 'bin'), False)
|
||||||
assert_equal(func('act', 'cat'), True)
|
self.assertEqual(func('act', 'cat'), True)
|
||||||
assert_equal(func('a ct', 'ca t'), True)
|
self.assertEqual(func('a ct', 'ca t'), True)
|
||||||
assert_equal(func('dog', 'doggo'), False)
|
self.assertEqual(func('dog', 'doggo'), False)
|
||||||
print('Success: test_permutation')
|
print('Success: test_permutation')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -137,20 +137,18 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# %load test_priority_queue.py\n",
|
"# %load test_priority_queue.py\n",
|
||||||
"from nose.tools import assert_equal\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestPriorityQueue(object):\n",
|
"class TestPriorityQueue(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_priority_queue(self):\n",
|
" def test_priority_queue(self):\n",
|
||||||
" priority_queue = PriorityQueue()\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('a', 20))\n",
|
||||||
" priority_queue.insert(PriorityQueueNode('b', 5))\n",
|
" priority_queue.insert(PriorityQueueNode('b', 5))\n",
|
||||||
" priority_queue.insert(PriorityQueueNode('c', 15))\n",
|
" priority_queue.insert(PriorityQueueNode('c', 15))\n",
|
||||||
@@ -162,7 +160,7 @@
|
|||||||
" mins = []\n",
|
" mins = []\n",
|
||||||
" while priority_queue.array:\n",
|
" while priority_queue.array:\n",
|
||||||
" mins.append(priority_queue.extract_min().key)\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",
|
" print('Success: test_min_heap')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -201,9 +199,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.0"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
"nbformat_minor": 0
|
"nbformat_minor": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,9 +108,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 1,
|
"execution_count": 1,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -168,9 +166,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 2,
|
"execution_count": 2,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": true
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%run priority_queue.py"
|
"%run priority_queue.py"
|
||||||
@@ -186,9 +182,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": 3,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -200,14 +194,14 @@
|
|||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"%%writefile test_priority_queue.py\n",
|
"%%writefile test_priority_queue.py\n",
|
||||||
"from nose.tools import assert_equal\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestPriorityQueue(object):\n",
|
"class TestPriorityQueue(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_priority_queue(self):\n",
|
" def test_priority_queue(self):\n",
|
||||||
" priority_queue = PriorityQueue()\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('a', 20))\n",
|
||||||
" priority_queue.insert(PriorityQueueNode('b', 5))\n",
|
" priority_queue.insert(PriorityQueueNode('b', 5))\n",
|
||||||
" priority_queue.insert(PriorityQueueNode('c', 15))\n",
|
" priority_queue.insert(PriorityQueueNode('c', 15))\n",
|
||||||
@@ -219,7 +213,7 @@
|
|||||||
" mins = []\n",
|
" mins = []\n",
|
||||||
" while priority_queue.array:\n",
|
" while priority_queue.array:\n",
|
||||||
" mins.append(priority_queue.extract_min().key)\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",
|
" print('Success: test_min_heap')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -235,9 +229,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 4,
|
"execution_count": 4,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -268,9 +260,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.0"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"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):
|
def test_priority_queue(self):
|
||||||
priority_queue = PriorityQueue()
|
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('a', 20))
|
||||||
priority_queue.insert(PriorityQueueNode('b', 5))
|
priority_queue.insert(PriorityQueueNode('b', 5))
|
||||||
priority_queue.insert(PriorityQueueNode('c', 15))
|
priority_queue.insert(PriorityQueueNode('c', 15))
|
||||||
@@ -17,7 +17,7 @@ class TestPriorityQueue(object):
|
|||||||
mins = []
|
mins = []
|
||||||
while priority_queue.array:
|
while priority_queue.array:
|
||||||
mins.append(priority_queue.extract_min().key)
|
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')
|
print('Success: test_min_heap')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -73,9 +73,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"class ReverseString(object):\n",
|
"class ReverseString(object):\n",
|
||||||
@@ -104,21 +102,19 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# %load test_reverse_string.py\n",
|
"# %load test_reverse_string.py\n",
|
||||||
"from nose.tools import assert_equal\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestReverse(object):\n",
|
"class TestReverse(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_reverse(self, func):\n",
|
" def test_reverse(self, func):\n",
|
||||||
" assert_equal(func(None), None)\n",
|
" self.assertEqual(func(None), None)\n",
|
||||||
" assert_equal(func(['']), [''])\n",
|
" self.assertEqual(func(['']), [''])\n",
|
||||||
" assert_equal(func(\n",
|
" self.assertEqual(func(\n",
|
||||||
" ['f', 'o', 'o', ' ', 'b', 'a', 'r']),\n",
|
" ['f', 'o', 'o', ' ', 'b', 'a', 'r']),\n",
|
||||||
" ['r', 'a', 'b', ' ', 'o', 'o', 'f'])\n",
|
" ['r', 'a', 'b', ' ', 'o', 'o', 'f'])\n",
|
||||||
" print('Success: test_reverse')\n",
|
" print('Success: test_reverse')\n",
|
||||||
@@ -126,7 +122,7 @@
|
|||||||
" def test_reverse_inplace(self, func):\n",
|
" def test_reverse_inplace(self, func):\n",
|
||||||
" target_list = ['f', 'o', 'o', ' ', 'b', 'a', 'r']\n",
|
" target_list = ['f', 'o', 'o', ' ', 'b', 'a', 'r']\n",
|
||||||
" func(target_list)\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",
|
" print('Success: test_reverse_inplace')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -167,9 +163,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.0"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
"nbformat_minor": 0
|
"nbformat_minor": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,9 +86,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 1,
|
"execution_count": 1,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"from __future__ import division\n",
|
"from __future__ import division\n",
|
||||||
@@ -117,9 +115,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 2,
|
"execution_count": 2,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"class ReverseStringAlt(object):\n",
|
"class ReverseStringAlt(object):\n",
|
||||||
@@ -145,9 +141,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": 3,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -159,15 +153,15 @@
|
|||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"%%writefile test_reverse_string.py\n",
|
"%%writefile test_reverse_string.py\n",
|
||||||
"from nose.tools import assert_equal\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestReverse(object):\n",
|
"class TestReverse(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_reverse(self, func):\n",
|
" def test_reverse(self, func):\n",
|
||||||
" assert_equal(func(None), None)\n",
|
" self.assertEqual(func(None), None)\n",
|
||||||
" assert_equal(func(['']), [''])\n",
|
" self.assertEqual(func(['']), [''])\n",
|
||||||
" assert_equal(func(\n",
|
" self.assertEqual(func(\n",
|
||||||
" ['f', 'o', 'o', ' ', 'b', 'a', 'r']),\n",
|
" ['f', 'o', 'o', ' ', 'b', 'a', 'r']),\n",
|
||||||
" ['r', 'a', 'b', ' ', 'o', 'o', 'f'])\n",
|
" ['r', 'a', 'b', ' ', 'o', 'o', 'f'])\n",
|
||||||
" print('Success: test_reverse')\n",
|
" print('Success: test_reverse')\n",
|
||||||
@@ -175,7 +169,7 @@
|
|||||||
" def test_reverse_inplace(self, func):\n",
|
" def test_reverse_inplace(self, func):\n",
|
||||||
" target_list = ['f', 'o', 'o', ' ', 'b', 'a', 'r']\n",
|
" target_list = ['f', 'o', 'o', ' ', 'b', 'a', 'r']\n",
|
||||||
" func(target_list)\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",
|
" print('Success: test_reverse_inplace')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -193,9 +187,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 4,
|
"execution_count": 4,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -245,9 +237,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# %load reverse_string.cpp\n",
|
"# %load reverse_string.cpp\n",
|
||||||
@@ -306,9 +296,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.4.3"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"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):
|
def test_reverse(self, func):
|
||||||
assert_equal(func(None), None)
|
self.assertEqual(func(None), None)
|
||||||
assert_equal(func(['']), [''])
|
self.assertEqual(func(['']), [''])
|
||||||
assert_equal(func(
|
self.assertEqual(func(
|
||||||
['f', 'o', 'o', ' ', 'b', 'a', 'r']),
|
['f', 'o', 'o', ' ', 'b', 'a', 'r']),
|
||||||
['r', 'a', 'b', ' ', 'o', 'o', 'f'])
|
['r', 'a', 'b', ' ', 'o', 'o', 'f'])
|
||||||
print('Success: test_reverse')
|
print('Success: test_reverse')
|
||||||
@@ -14,7 +14,7 @@ class TestReverse(object):
|
|||||||
def test_reverse_inplace(self, func):
|
def test_reverse_inplace(self, func):
|
||||||
target_list = ['f', 'o', 'o', ' ', 'b', 'a', 'r']
|
target_list = ['f', 'o', 'o', ' ', 'b', 'a', 'r']
|
||||||
func(target_list)
|
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')
|
print('Success: test_reverse_inplace')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -77,9 +77,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"class Rotation(object):\n",
|
"class Rotation(object):\n",
|
||||||
@@ -113,24 +111,22 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# %load test_rotation.py\n",
|
"# %load test_rotation.py\n",
|
||||||
"from nose.tools import assert_equal\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestRotation(object):\n",
|
"class TestRotation(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_rotation(self):\n",
|
" def test_rotation(self):\n",
|
||||||
" rotation = Rotation()\n",
|
" rotation = Rotation()\n",
|
||||||
" assert_equal(rotation.is_rotation('o', 'oo'), False)\n",
|
" self.assertEqual(rotation.is_rotation('o', 'oo'), False)\n",
|
||||||
" assert_equal(rotation.is_rotation(None, 'foo'), False)\n",
|
" self.assertEqual(rotation.is_rotation(None, 'foo'), False)\n",
|
||||||
" assert_equal(rotation.is_rotation('', 'foo'), False)\n",
|
" self.assertEqual(rotation.is_rotation('', 'foo'), False)\n",
|
||||||
" assert_equal(rotation.is_rotation('', ''), True)\n",
|
" self.assertEqual(rotation.is_rotation('', ''), True)\n",
|
||||||
" assert_equal(rotation.is_rotation('foobarbaz', 'barbazfoo'), True)\n",
|
" self.assertEqual(rotation.is_rotation('foobarbaz', 'barbazfoo'), True)\n",
|
||||||
" print('Success: test_rotation')\n",
|
" print('Success: test_rotation')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -169,9 +165,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.0"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
"nbformat_minor": 0
|
"nbformat_minor": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,9 +87,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 1,
|
"execution_count": 1,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"class Rotation(object):\n",
|
"class Rotation(object):\n",
|
||||||
@@ -115,9 +113,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 2,
|
"execution_count": 2,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -129,18 +125,18 @@
|
|||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"%%writefile test_rotation.py\n",
|
"%%writefile test_rotation.py\n",
|
||||||
"from nose.tools import assert_equal\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestRotation(object):\n",
|
"class TestRotation(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_rotation(self):\n",
|
" def test_rotation(self):\n",
|
||||||
" rotation = Rotation()\n",
|
" rotation = Rotation()\n",
|
||||||
" assert_equal(rotation.is_rotation('o', 'oo'), False)\n",
|
" self.assertEqual(rotation.is_rotation('o', 'oo'), False)\n",
|
||||||
" assert_equal(rotation.is_rotation(None, 'foo'), False)\n",
|
" self.assertEqual(rotation.is_rotation(None, 'foo'), False)\n",
|
||||||
" assert_equal(rotation.is_rotation('', 'foo'), False)\n",
|
" self.assertEqual(rotation.is_rotation('', 'foo'), False)\n",
|
||||||
" assert_equal(rotation.is_rotation('', ''), True)\n",
|
" self.assertEqual(rotation.is_rotation('', ''), True)\n",
|
||||||
" assert_equal(rotation.is_rotation('foobarbaz', 'barbazfoo'), True)\n",
|
" self.assertEqual(rotation.is_rotation('foobarbaz', 'barbazfoo'), True)\n",
|
||||||
" print('Success: test_rotation')\n",
|
" print('Success: test_rotation')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -156,9 +152,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": 3,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -189,9 +183,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.0"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"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):
|
def test_rotation(self):
|
||||||
rotation = Rotation()
|
rotation = Rotation()
|
||||||
assert_equal(rotation.is_rotation('o', 'oo'), False)
|
self.assertEqual(rotation.is_rotation('o', 'oo'), False)
|
||||||
assert_equal(rotation.is_rotation(None, 'foo'), False)
|
self.assertEqual(rotation.is_rotation(None, 'foo'), False)
|
||||||
assert_equal(rotation.is_rotation('', 'foo'), False)
|
self.assertEqual(rotation.is_rotation('', 'foo'), False)
|
||||||
assert_equal(rotation.is_rotation('', ''), True)
|
self.assertEqual(rotation.is_rotation('', ''), True)
|
||||||
assert_equal(rotation.is_rotation('foobarbaz', 'barbazfoo'), True)
|
self.assertEqual(rotation.is_rotation('foobarbaz', 'barbazfoo'), True)
|
||||||
print('Success: test_rotation')
|
print('Success: test_rotation')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -77,9 +77,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"class Solution(object):\n",
|
"class Solution(object):\n",
|
||||||
@@ -106,28 +104,26 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# %load test_str_diff.py\n",
|
"# %load test_str_diff.py\n",
|
||||||
"from nose.tools import assert_equal, assert_raises\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestFindDiff(object):\n",
|
"class TestFindDiff(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_find_diff(self):\n",
|
" def test_find_diff(self):\n",
|
||||||
" solution = Solution()\n",
|
" solution = Solution()\n",
|
||||||
" assert_raises(TypeError, solution.find_diff, None)\n",
|
" self.assertRaises(TypeError, solution.find_diff, None)\n",
|
||||||
" assert_equal(solution.find_diff('ab', 'aab'), 'a')\n",
|
" self.assertEqual(solution.find_diff('ab', 'aab'), 'a')\n",
|
||||||
" assert_equal(solution.find_diff('aab', 'ab'), 'a')\n",
|
" self.assertEqual(solution.find_diff('aab', 'ab'), 'a')\n",
|
||||||
" assert_equal(solution.find_diff('abcd', 'abcde'), 'e')\n",
|
" self.assertEqual(solution.find_diff('abcd', 'abcde'), 'e')\n",
|
||||||
" assert_equal(solution.find_diff('aaabbcdd', 'abdbacade'), 'e')\n",
|
" self.assertEqual(solution.find_diff('aaabbcdd', 'abdbacade'), 'e')\n",
|
||||||
" assert_equal(solution.find_diff_xor('ab', 'aab'), 'a')\n",
|
" self.assertEqual(solution.find_diff_xor('ab', 'aab'), 'a')\n",
|
||||||
" assert_equal(solution.find_diff_xor('aab', 'ab'), 'a')\n",
|
" self.assertEqual(solution.find_diff_xor('aab', 'ab'), 'a')\n",
|
||||||
" assert_equal(solution.find_diff_xor('abcd', 'abcde'), 'e')\n",
|
" self.assertEqual(solution.find_diff_xor('abcd', 'abcde'), 'e')\n",
|
||||||
" assert_equal(solution.find_diff_xor('aaabbcdd', 'abdbacade'), 'e')\n",
|
" self.assertEqual(solution.find_diff_xor('aaabbcdd', 'abdbacade'), 'e')\n",
|
||||||
" print('Success: test_find_diff')\n",
|
" print('Success: test_find_diff')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -166,9 +162,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.0"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
"nbformat_minor": 0
|
"nbformat_minor": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,9 +93,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 1,
|
"execution_count": 1,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"class Solution(object):\n",
|
"class Solution(object):\n",
|
||||||
@@ -140,9 +138,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 2,
|
"execution_count": 2,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -154,22 +150,22 @@
|
|||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"%%writefile test_str_diff.py\n",
|
"%%writefile test_str_diff.py\n",
|
||||||
"from nose.tools import assert_equal, assert_raises\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestFindDiff(object):\n",
|
"class TestFindDiff(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_find_diff(self):\n",
|
" def test_find_diff(self):\n",
|
||||||
" solution = Solution()\n",
|
" solution = Solution()\n",
|
||||||
" assert_raises(TypeError, solution.find_diff, None)\n",
|
" self.assertRaises(TypeError, solution.find_diff, None)\n",
|
||||||
" assert_equal(solution.find_diff('ab', 'aab'), 'a')\n",
|
" self.assertEqual(solution.find_diff('ab', 'aab'), 'a')\n",
|
||||||
" assert_equal(solution.find_diff('aab', 'ab'), 'a')\n",
|
" self.assertEqual(solution.find_diff('aab', 'ab'), 'a')\n",
|
||||||
" assert_equal(solution.find_diff('abcd', 'abcde'), 'e')\n",
|
" self.assertEqual(solution.find_diff('abcd', 'abcde'), 'e')\n",
|
||||||
" assert_equal(solution.find_diff('aaabbcdd', 'abdbacade'), 'e')\n",
|
" self.assertEqual(solution.find_diff('aaabbcdd', 'abdbacade'), 'e')\n",
|
||||||
" assert_equal(solution.find_diff_xor('ab', 'aab'), 'a')\n",
|
" self.assertEqual(solution.find_diff_xor('ab', 'aab'), 'a')\n",
|
||||||
" assert_equal(solution.find_diff_xor('aab', 'ab'), 'a')\n",
|
" self.assertEqual(solution.find_diff_xor('aab', 'ab'), 'a')\n",
|
||||||
" assert_equal(solution.find_diff_xor('abcd', 'abcde'), 'e')\n",
|
" self.assertEqual(solution.find_diff_xor('abcd', 'abcde'), 'e')\n",
|
||||||
" assert_equal(solution.find_diff_xor('aaabbcdd', 'abdbacade'), 'e')\n",
|
" self.assertEqual(solution.find_diff_xor('aaabbcdd', 'abdbacade'), 'e')\n",
|
||||||
" print('Success: test_find_diff')\n",
|
" print('Success: test_find_diff')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -185,9 +181,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": 3,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -218,9 +212,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.0"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"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):
|
def test_find_diff(self):
|
||||||
solution = Solution()
|
solution = Solution()
|
||||||
assert_raises(TypeError, solution.find_diff, None)
|
self.assertRaises(TypeError, solution.find_diff, None)
|
||||||
assert_equal(solution.find_diff('ab', 'aab'), 'a')
|
self.assertEqual(solution.find_diff('ab', 'aab'), 'a')
|
||||||
assert_equal(solution.find_diff('aab', 'ab'), 'a')
|
self.assertEqual(solution.find_diff('aab', 'ab'), 'a')
|
||||||
assert_equal(solution.find_diff('abcd', 'abcde'), 'e')
|
self.assertEqual(solution.find_diff('abcd', 'abcde'), 'e')
|
||||||
assert_equal(solution.find_diff('aaabbcdd', 'abdbacade'), 'e')
|
self.assertEqual(solution.find_diff('aaabbcdd', 'abdbacade'), 'e')
|
||||||
assert_equal(solution.find_diff_xor('ab', 'aab'), 'a')
|
self.assertEqual(solution.find_diff_xor('ab', 'aab'), 'a')
|
||||||
assert_equal(solution.find_diff_xor('aab', 'ab'), 'a')
|
self.assertEqual(solution.find_diff_xor('aab', 'ab'), 'a')
|
||||||
assert_equal(solution.find_diff_xor('abcd', 'abcde'), 'e')
|
self.assertEqual(solution.find_diff_xor('abcd', 'abcde'), 'e')
|
||||||
assert_equal(solution.find_diff_xor('aaabbcdd', 'abdbacade'), 'e')
|
self.assertEqual(solution.find_diff_xor('aaabbcdd', 'abdbacade'), 'e')
|
||||||
print('Success: test_find_diff')
|
print('Success: test_find_diff')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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):
|
def test_two_sum(self):
|
||||||
solution = Solution()
|
solution = Solution()
|
||||||
assert_raises(TypeError, solution.two_sum, None, None)
|
self.assertRaises(TypeError, solution.two_sum, None, None)
|
||||||
assert_raises(ValueError, solution.two_sum, [], 0)
|
self.assertRaises(ValueError, solution.two_sum, [], 0)
|
||||||
target = 7
|
target = 7
|
||||||
nums = [1, 3, 2, -7, 5]
|
nums = [1, 3, 2, -7, 5]
|
||||||
expected = [2, 4]
|
expected = [2, 4]
|
||||||
assert_equal(solution.two_sum(nums, target), expected)
|
self.assertEqual(solution.two_sum(nums, target), expected)
|
||||||
print('Success: test_two_sum')
|
print('Success: test_two_sum')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -80,9 +80,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"class Solution(object):\n",
|
"class Solution(object):\n",
|
||||||
@@ -109,25 +107,23 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# %load test_two_sum.py\n",
|
"# %load test_two_sum.py\n",
|
||||||
"from nose.tools import assert_equal, assert_raises\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestTwoSum(object):\n",
|
"class TestTwoSum(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_two_sum(self):\n",
|
" def test_two_sum(self):\n",
|
||||||
" solution = Solution()\n",
|
" solution = Solution()\n",
|
||||||
" assert_raises(TypeError, solution.two_sum, None, None)\n",
|
" self.assertRaises(TypeError, solution.two_sum, None, None)\n",
|
||||||
" assert_raises(ValueError, solution.two_sum, [], 0)\n",
|
" self.assertRaises(ValueError, solution.two_sum, [], 0)\n",
|
||||||
" target = 7\n",
|
" target = 7\n",
|
||||||
" nums = [1, 3, 2, -7, 5]\n",
|
" nums = [1, 3, 2, -7, 5]\n",
|
||||||
" expected = [2, 4]\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",
|
" print('Success: test_two_sum')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -166,9 +162,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.0"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
"nbformat_minor": 0
|
"nbformat_minor": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,9 +156,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 1,
|
"execution_count": 1,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"class Solution(object):\n",
|
"class Solution(object):\n",
|
||||||
@@ -188,9 +186,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 2,
|
"execution_count": 2,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -202,19 +198,19 @@
|
|||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"%%writefile test_two_sum.py\n",
|
"%%writefile test_two_sum.py\n",
|
||||||
"from nose.tools import assert_equal, assert_raises\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestTwoSum(object):\n",
|
"class TestTwoSum(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_two_sum(self):\n",
|
" def test_two_sum(self):\n",
|
||||||
" solution = Solution()\n",
|
" solution = Solution()\n",
|
||||||
" assert_raises(TypeError, solution.two_sum, None, None)\n",
|
" self.assertRaises(TypeError, solution.two_sum, None, None)\n",
|
||||||
" assert_raises(ValueError, solution.two_sum, [], 0)\n",
|
" self.assertRaises(ValueError, solution.two_sum, [], 0)\n",
|
||||||
" target = 7\n",
|
" target = 7\n",
|
||||||
" nums = [1, 3, 2, -7, 5]\n",
|
" nums = [1, 3, 2, -7, 5]\n",
|
||||||
" expected = [2, 4]\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",
|
" print('Success: test_two_sum')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -230,9 +226,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": 3,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -263,9 +257,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.0"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"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):
|
def test_unique_chars(self, func):
|
||||||
assert_equal(func(None), False)
|
self.assertEqual(func(None), False)
|
||||||
assert_equal(func(''), True)
|
self.assertEqual(func(''), True)
|
||||||
assert_equal(func('foo'), False)
|
self.assertEqual(func('foo'), False)
|
||||||
assert_equal(func('bar'), True)
|
self.assertEqual(func('bar'), True)
|
||||||
print('Success: test_unique_chars')
|
print('Success: test_unique_chars')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -76,9 +76,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"class UniqueChars(object):\n",
|
"class UniqueChars(object):\n",
|
||||||
@@ -105,22 +103,20 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# %load test_unique_chars.py\n",
|
"# %load test_unique_chars.py\n",
|
||||||
"from nose.tools import assert_equal\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestUniqueChars(object):\n",
|
"class TestUniqueChars(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_unique_chars(self, func):\n",
|
" def test_unique_chars(self, func):\n",
|
||||||
" assert_equal(func(None), False)\n",
|
" self.assertEqual(func(None), False)\n",
|
||||||
" assert_equal(func(''), True)\n",
|
" self.assertEqual(func(''), True)\n",
|
||||||
" assert_equal(func('foo'), False)\n",
|
" self.assertEqual(func('foo'), False)\n",
|
||||||
" assert_equal(func('bar'), True)\n",
|
" self.assertEqual(func('bar'), True)\n",
|
||||||
" print('Success: test_unique_chars')\n",
|
" print('Success: test_unique_chars')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -169,9 +165,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.0"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
"nbformat_minor": 0
|
"nbformat_minor": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,9 +88,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 1,
|
"execution_count": 1,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"class UniqueCharsSet(object):\n",
|
"class UniqueCharsSet(object):\n",
|
||||||
@@ -135,9 +133,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 2,
|
"execution_count": 2,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"class UniqueChars(object):\n",
|
"class UniqueChars(object):\n",
|
||||||
@@ -183,9 +179,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": 3,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"class UniqueCharsInPlace(object):\n",
|
"class UniqueCharsInPlace(object):\n",
|
||||||
@@ -209,9 +203,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 4,
|
"execution_count": 4,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -223,16 +215,16 @@
|
|||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"%%writefile test_unique_chars.py\n",
|
"%%writefile test_unique_chars.py\n",
|
||||||
"from nose.tools import assert_equal\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestUniqueChars(object):\n",
|
"class TestUniqueChars(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_unique_chars(self, func):\n",
|
" def test_unique_chars(self, func):\n",
|
||||||
" assert_equal(func(None), False)\n",
|
" self.assertEqual(func(None), False)\n",
|
||||||
" assert_equal(func(''), True)\n",
|
" self.assertEqual(func(''), True)\n",
|
||||||
" assert_equal(func('foo'), False)\n",
|
" self.assertEqual(func('foo'), False)\n",
|
||||||
" assert_equal(func('bar'), True)\n",
|
" self.assertEqual(func('bar'), True)\n",
|
||||||
" print('Success: test_unique_chars')\n",
|
" print('Success: test_unique_chars')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -258,9 +250,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 5,
|
"execution_count": 5,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -293,9 +283,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.0"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
"nbformat_minor": 0
|
"nbformat_minor": 1
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user