#273: Remove nose dependency for recursion_dynamic/ (#280)

This commit is contained in:
Donne Martin 2020-07-13 21:26:50 -04:00 committed by GitHub
parent dce6b6aa67
commit 76cb6507fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
57 changed files with 548 additions and 751 deletions

View File

@ -76,9 +76,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class CoinChanger(object):\n",
@ -102,22 +100,20 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# %load test_coin_change.py\n",
"from nose.tools import assert_equal\n",
"import unittest\n",
"\n",
"\n",
"class Challenge(object):\n",
"class Challenge(unittest.TestCase):\n",
"\n",
" def test_coin_change(self):\n",
" coin_changer = CoinChanger()\n",
" assert_equal(coin_changer.make_change([1, 2], 0), 0)\n",
" assert_equal(coin_changer.make_change([1, 2, 3], 5), 5)\n",
" assert_equal(coin_changer.make_change([1, 5, 25, 50], 10), 3)\n",
" self.assertEqual(coin_changer.make_change([1, 2], 0), 0)\n",
" self.assertEqual(coin_changer.make_change([1, 2, 3], 5), 5)\n",
" self.assertEqual(coin_changer.make_change([1, 5, 25, 50], 10), 3)\n",
" print('Success: test_coin_change')\n",
"\n",
"\n",
@ -156,9 +152,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.0"
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

View File

@ -108,9 +108,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"class CoinChanger(object):\n",
@ -150,9 +148,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -164,16 +160,16 @@
],
"source": [
"%%writefile test_coin_change.py\n",
"from nose.tools import assert_equal\n",
"import unittest\n",
"\n",
"\n",
"class Challenge(object):\n",
"class Challenge(unittest.TestCase):\n",
"\n",
" def test_coin_change(self):\n",
" coin_changer = CoinChanger()\n",
" assert_equal(coin_changer.make_change([1, 2], 0), 0)\n",
" assert_equal(coin_changer.make_change([1, 2, 3], 5), 5)\n",
" assert_equal(coin_changer.make_change([1, 5, 25, 50], 10), 3)\n",
" self.assertEqual(coin_changer.make_change([1, 2], 0), 0)\n",
" self.assertEqual(coin_changer.make_change([1, 2, 3], 5), 5)\n",
" self.assertEqual(coin_changer.make_change([1, 5, 25, 50], 10), 3)\n",
" print('Success: test_coin_change')\n",
"\n",
"\n",
@ -189,9 +185,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -222,9 +216,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
}

View File

@ -1,13 +1,13 @@
from nose.tools import assert_equal
import unittest
class Challenge(object):
class Challenge(unittest.TestCase):
def test_coin_change(self):
coin_changer = CoinChanger()
assert_equal(coin_changer.make_change([1, 2], 0), 0)
assert_equal(coin_changer.make_change([1, 2, 3], 5), 5)
assert_equal(coin_changer.make_change([1, 5, 25, 50], 10), 3)
self.assertEqual(coin_changer.make_change([1, 2], 0), 0)
self.assertEqual(coin_changer.make_change([1, 2, 3], 5), 5)
self.assertEqual(coin_changer.make_change([1, 5, 25, 50], 10), 3)
print('Success: test_coin_change')
@ -17,4 +17,4 @@ def main():
if __name__ == '__main__':
main()
main()

View File

@ -76,9 +76,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class CoinChanger(object):\n",
@ -105,24 +103,22 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# %load test_coin_change_min.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestCoinChange(object):\n",
"class TestCoinChange(unittest.TestCase):\n",
"\n",
" def test_coin_change(self):\n",
" coin_changer = CoinChanger()\n",
" assert_raises(TypeError, coin_changer.make_change, None, None)\n",
" assert_equal(coin_changer.make_change([], 0), 0)\n",
" assert_equal(coin_changer.make_change([1, 2, 3], 5), 2)\n",
" assert_equal(coin_changer.make_change([3, 2, 1], 5), 2)\n",
" assert_equal(coin_changer.make_change([3, 2, 1], 8), 3)\n",
" self.assertRaises(TypeError, coin_changer.make_change, None, None)\n",
" self.assertEqual(coin_changer.make_change([], 0), 0)\n",
" self.assertEqual(coin_changer.make_change([1, 2, 3], 5), 2)\n",
" self.assertEqual(coin_changer.make_change([3, 2, 1], 5), 2)\n",
" self.assertEqual(coin_changer.make_change([3, 2, 1], 8), 3)\n",
" print('Success: test_coin_change')\n",
"\n",
"\n",
@ -161,9 +157,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.0"
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

View File

@ -116,9 +116,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
@ -160,9 +158,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -174,18 +170,18 @@
],
"source": [
"%%writefile test_coin_change_min.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestCoinChange(object):\n",
"class TestCoinChange(unittest.TestCase):\n",
"\n",
" def test_coin_change(self):\n",
" coin_changer = CoinChanger()\n",
" assert_raises(TypeError, coin_changer.make_change, None, None)\n",
" assert_equal(coin_changer.make_change([], 0), 0)\n",
" assert_equal(coin_changer.make_change([1, 2, 3], 5), 2)\n",
" assert_equal(coin_changer.make_change([3, 2, 1], 5), 2)\n",
" assert_equal(coin_changer.make_change([3, 2, 1], 8), 3)\n",
" self.assertRaises(TypeError, coin_changer.make_change, None, None)\n",
" self.assertEqual(coin_changer.make_change([], 0), 0)\n",
" self.assertEqual(coin_changer.make_change([1, 2, 3], 5), 2)\n",
" self.assertEqual(coin_changer.make_change([3, 2, 1], 5), 2)\n",
" self.assertEqual(coin_changer.make_change([3, 2, 1], 8), 3)\n",
" print('Success: test_coin_change')\n",
"\n",
"\n",
@ -201,9 +197,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -234,9 +228,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
}

View File

@ -1,15 +1,15 @@
from nose.tools import assert_equal, assert_raises
import unittest
class TestCoinChange(object):
class TestCoinChange(unittest.TestCase):
def test_coin_change(self):
coin_changer = CoinChanger()
assert_raises(TypeError, coin_changer.make_change, None, None)
assert_equal(coin_changer.make_change([], 0), 0)
assert_equal(coin_changer.make_change([1, 2, 3], 5), 2)
assert_equal(coin_changer.make_change([3, 2, 1], 5), 2)
assert_equal(coin_changer.make_change([3, 2, 1], 8), 3)
self.assertRaises(TypeError, coin_changer.make_change, None, None)
self.assertEqual(coin_changer.make_change([], 0), 0)
self.assertEqual(coin_changer.make_change([1, 2, 3], 5), 2)
self.assertEqual(coin_changer.make_change([3, 2, 1], 5), 2)
self.assertEqual(coin_changer.make_change([3, 2, 1], 8), 3)
print('Success: test_coin_change')
@ -19,4 +19,4 @@ def main():
if __name__ == '__main__':
main()
main()

View File

@ -73,9 +73,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"def change_ways(n, coins):\n",
@ -97,21 +95,19 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# %load test_coin_change_ways.py\n",
"from nose.tools import assert_equal\n",
"import unittest\n",
"\n",
"\n",
"class Challenge(object):\n",
"class Challenge(unittest.TestCase):\n",
"\n",
" def test_coin_change_ways(self,solution):\n",
" assert_equal(solution(0, [1, 2]), 0)\n",
" assert_equal(solution(100, [1, 2, 3]), 884)\n",
" assert_equal(solution(1000, range(1, 101)), \n",
" self.assertEqual(solution(0, [1, 2]), 0)\n",
" self.assertEqual(solution(100, [1, 2, 3]), 884)\n",
" self.assertEqual(solution(1000, range(1, 101)), \n",
" 15658181104580771094597751280645)\n",
" print('Success: test_coin_change_ways')\n",
"\n",
@ -151,9 +147,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.0"
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

View File

@ -68,9 +68,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"def change_ways(n, coins):\n",
@ -92,9 +90,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -106,15 +102,15 @@
],
"source": [
"%%writefile test_coin_change_ways.py\n",
"from nose.tools import assert_equal\n",
"import unittest\n",
"\n",
"\n",
"class Challenge(object):\n",
"class Challenge(unittest.TestCase):\n",
"\n",
" def test_coin_change_ways(self,solution):\n",
" assert_equal(solution(0, [1, 2]), 0)\n",
" assert_equal(solution(100, [1, 2, 3]), 884)\n",
" assert_equal(solution(1000, range(1, 101)), \n",
" self.assertEqual(solution(0, [1, 2]), 0)\n",
" self.assertEqual(solution(100, [1, 2, 3]), 884)\n",
" self.assertEqual(solution(1000, range(1, 101)), \n",
" 15658181104580771094597751280645)\n",
" print('Success: test_coin_change_ways')\n",
"\n",
@ -131,9 +127,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -164,9 +158,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.0"
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

View File

@ -1,12 +1,13 @@
from nose.tools import assert_equal
import unittest
class Challenge(object):
class Challenge(unittest.TestCase):
def test_coin_change_ways(self,solution):
assert_equal(solution(0, [1, 2]), 0)
assert_equal(solution(100, [1, 2, 3]), 884)
assert_equal(solution(1000, range(1, 101)), 15658181104580771094597751280645)
self.assertEqual(solution(0, [1, 2]), 0)
self.assertEqual(solution(100, [1, 2, 3]), 884)
self.assertEqual(solution(1000, range(1, 101)),
15658181104580771094597751280645)
print('Success: test_coin_change_ways')
@ -16,4 +17,4 @@ def main():
if __name__ == '__main__':
main()
main()

View File

@ -109,23 +109,21 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# %load test_fibonacci.py\n",
"from nose.tools import assert_equal\n",
"import unittest\n",
"\n",
"\n",
"class TestFib(object):\n",
"class TestFib(unittest.TestCase):\n",
"\n",
" def test_fib(self, func):\n",
" result = []\n",
" expected = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]\n",
" for i in range(len(expected)):\n",
" result.append(func(i))\n",
" assert_equal(result, expected)\n",
" self.assertEqual(result, expected)\n",
" print('Success: test_fib')\n",
"\n",
"\n",
@ -167,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
}

View File

@ -81,9 +81,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"class Math(object):\n",
@ -125,9 +123,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -139,17 +135,17 @@
],
"source": [
"%%writefile test_fibonacci.py\n",
"from nose.tools import assert_equal\n",
"import unittest\n",
"\n",
"\n",
"class TestFib(object):\n",
"class TestFib(unittest.TestCase):\n",
"\n",
" def test_fib(self, func):\n",
" result = []\n",
" expected = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]\n",
" for i in range(len(expected)):\n",
" result.append(func(i))\n",
" assert_equal(result, expected)\n",
" self.assertEqual(result, expected)\n",
" print('Success: test_fib')\n",
"\n",
"\n",
@ -168,9 +164,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -203,9 +197,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.0"
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

View File

@ -1,14 +1,14 @@
from nose.tools import assert_equal
import unittest
class TestFib(object):
class TestFib(unittest.TestCase):
def test_fib(self, func):
result = []
expected = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
for i in range(len(expected)):
result.append(func(i))
assert_equal(result, expected)
self.assertEqual(result, expected)
print('Success: test_fib')
@ -21,4 +21,4 @@ def main():
if __name__ == '__main__':
main()
main()

View File

@ -102,9 +102,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class Grid(object):\n",
@ -131,21 +129,19 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# %load test_grid_path.py\n",
"from nose.tools import assert_equal\n",
"import unittest\n",
"\n",
"\n",
"class TestGridPath(object):\n",
"class TestGridPath(unittest.TestCase):\n",
"\n",
" def test_grid_path(self):\n",
" grid = Grid()\n",
" assert_equal(grid.find_path(None), None)\n",
" assert_equal(grid.find_path([[]]), None)\n",
" self.assertEqual(grid.find_path(None), None)\n",
" self.assertEqual(grid.find_path([[]]), None)\n",
" max_rows = 8\n",
" max_cols = 4\n",
" matrix = [[1] * max_cols for _ in range(max_rows)]\n",
@ -162,10 +158,10 @@
" (2, 1), (3, 1), (4, 1),\n",
" (5, 1), (5, 2), (6, 2), \n",
" (7, 2), (7, 3)]\n",
" assert_equal(result, expected)\n",
" self.assertEqual(result, expected)\n",
" matrix[7][2] = 0\n",
" result = grid.find_path(matrix)\n",
" assert_equal(result, None)\n",
" self.assertEqual(result, None)\n",
" print('Success: test_grid_path')\n",
"\n",
"\n",
@ -204,9 +200,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.0"
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

View File

@ -135,9 +135,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class Grid(object):\n",
@ -177,9 +175,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -191,15 +187,15 @@
],
"source": [
"%%writefile test_grid_path.py\n",
"from nose.tools import assert_equal\n",
"import unittest\n",
"\n",
"\n",
"class TestGridPath(object):\n",
"class TestGridPath(unittest.TestCase):\n",
"\n",
" def test_grid_path(self):\n",
" grid = Grid()\n",
" assert_equal(grid.find_path(None), None)\n",
" assert_equal(grid.find_path([[]]), None)\n",
" self.assertEqual(grid.find_path(None), None)\n",
" self.assertEqual(grid.find_path([[]]), None)\n",
" max_rows = 8\n",
" max_cols = 4\n",
" matrix = [[1] * max_cols for _ in range(max_rows)]\n",
@ -216,10 +212,10 @@
" (2, 1), (3, 1), (4, 1),\n",
" (5, 1), (5, 2), (6, 2), \n",
" (7, 2), (7, 3)]\n",
" assert_equal(result, expected)\n",
" self.assertEqual(result, expected)\n",
" matrix[7][2] = 0\n",
" result = grid.find_path(matrix)\n",
" assert_equal(result, None)\n",
" self.assertEqual(result, None)\n",
" print('Success: test_grid_path')\n",
"\n",
"\n",
@ -235,9 +231,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -268,9 +262,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.0"
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

View File

@ -1,12 +1,12 @@
from nose.tools import assert_equal
import unittest
class TestGridPath(object):
class TestGridPath(unittest.TestCase):
def test_grid_path(self):
grid = Grid()
assert_equal(grid.find_path(None), None)
assert_equal(grid.find_path([[]]), None)
self.assertEqual(grid.find_path(None), None)
self.assertEqual(grid.find_path([[]]), None)
max_rows = 8
max_cols = 4
matrix = [[1] * max_cols for _ in range(max_rows)]
@ -23,10 +23,10 @@ class TestGridPath(object):
(2, 1), (3, 1), (4, 1),
(5, 1), (5, 2), (6, 2),
(7, 2), (7, 3)]
assert_equal(result, expected)
self.assertEqual(result, expected)
matrix[7][2] = 0
result = grid.find_path(matrix)
assert_equal(result, None)
self.assertEqual(result, None)
print('Success: test_grid_path')
@ -36,4 +36,4 @@ def main():
if __name__ == '__main__':
main()
main()

View File

@ -73,9 +73,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"%run ../../stacks_queues/stack/stack.py\n",
@ -85,9 +83,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class Hanoi(object):\n",
@ -111,16 +107,14 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# %load test_hanoi.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestHanoi(object):\n",
"class TestHanoi(unittest.TestCase):\n",
"\n",
" def test_hanoi(self):\n",
" hanoi = Hanoi()\n",
@ -130,23 +124,23 @@
" dest = Stack()\n",
"\n",
" print('Test: None towers')\n",
" assert_raises(TypeError, hanoi.move_disks, num_disks, None, None, None)\n",
" self.assertRaises(TypeError, hanoi.move_disks, num_disks, None, None, None)\n",
"\n",
" print('Test: 0 disks')\n",
" hanoi.move_disks(num_disks, src, dest, buff)\n",
" assert_equal(dest.pop(), None)\n",
" self.assertEqual(dest.pop(), None)\n",
"\n",
" print('Test: 1 disk')\n",
" src.push(5)\n",
" hanoi.move_disks(num_disks, src, dest, buff)\n",
" assert_equal(dest.pop(), 5)\n",
" self.assertEqual(dest.pop(), 5)\n",
"\n",
" print('Test: 2 or more disks')\n",
" for disk_index in range(num_disks, -1, -1):\n",
" src.push(disk_index)\n",
" hanoi.move_disks(num_disks, src, dest, buff)\n",
" for disk_index in range(0, num_disks):\n",
" assert_equal(dest.pop(), disk_index)\n",
" self.assertEqual(dest.pop(), disk_index)\n",
"\n",
" print('Success: test_hanoi')\n",
"\n",
@ -186,9 +180,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.0"
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

View File

@ -81,9 +81,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"%run ../../stacks_queues/stack/stack.py"
@ -92,9 +90,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class Hanoi(object):\n",
@ -123,9 +119,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -137,10 +131,10 @@
],
"source": [
"%%writefile test_hanoi.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestHanoi(object):\n",
"class TestHanoi(unittest.TestCase):\n",
"\n",
" def test_hanoi(self):\n",
" hanoi = Hanoi()\n",
@ -150,23 +144,23 @@
" dest = Stack()\n",
"\n",
" print('Test: None towers')\n",
" assert_raises(TypeError, hanoi.move_disks, num_disks, None, None, None)\n",
" self.assertRaises(TypeError, hanoi.move_disks, num_disks, None, None, None)\n",
"\n",
" print('Test: 0 disks')\n",
" hanoi.move_disks(num_disks, src, dest, buff)\n",
" assert_equal(dest.pop(), None)\n",
" self.assertEqual(dest.pop(), None)\n",
"\n",
" print('Test: 1 disk')\n",
" src.push(5)\n",
" hanoi.move_disks(num_disks, src, dest, buff)\n",
" assert_equal(dest.pop(), 5)\n",
" self.assertEqual(dest.pop(), 5)\n",
"\n",
" print('Test: 2 or more disks')\n",
" for disk_index in range(num_disks, -1, -1):\n",
" src.push(disk_index)\n",
" hanoi.move_disks(num_disks, src, dest, buff)\n",
" for disk_index in range(0, num_disks):\n",
" assert_equal(dest.pop(), disk_index)\n",
" self.assertEqual(dest.pop(), disk_index)\n",
"\n",
" print('Success: test_hanoi')\n",
"\n",
@ -183,9 +177,7 @@
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -220,9 +212,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
}

View File

@ -1,7 +1,7 @@
from nose.tools import assert_equal, assert_raises
import unittest
class TestHanoi(object):
class TestHanoi(unittest.TestCase):
def test_hanoi(self):
hanoi = Hanoi()
@ -11,23 +11,23 @@ class TestHanoi(object):
dest = Stack()
print('Test: None towers')
assert_raises(TypeError, hanoi.move_disks, num_disks, None, None, None)
self.assertRaises(TypeError, hanoi.move_disks, num_disks, None, None, None)
print('Test: 0 disks')
hanoi.move_disks(num_disks, src, dest, buff)
assert_equal(dest.pop(), None)
self.assertEqual(dest.pop(), None)
print('Test: 1 disk')
src.push(5)
hanoi.move_disks(num_disks, src, dest, buff)
assert_equal(dest.pop(), 5)
self.assertEqual(dest.pop(), 5)
print('Test: 2 or more disks')
for disk_index in range(num_disks, -1, -1):
src.push(disk_index)
hanoi.move_disks(num_disks, src, dest, buff)
for disk_index in range(0, num_disks):
assert_equal(dest.pop(), disk_index)
self.assertEqual(dest.pop(), disk_index)
print('Success: test_hanoi')
@ -38,4 +38,4 @@ def main():
if __name__ == '__main__':
main()
main()

View File

@ -145,15 +145,15 @@
"outputs": [],
"source": [
"# %load test_knapsack.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestKnapsack(object):\n",
"class TestKnapsack(unittest.TestCase):\n",
"\n",
" def test_knapsack_bottom_up(self):\n",
" knapsack = Knapsack()\n",
" assert_raises(TypeError, knapsack.fill_knapsack, None, None)\n",
" assert_equal(knapsack.fill_knapsack(0, 0), 0)\n",
" self.assertRaises(TypeError, knapsack.fill_knapsack, None, None)\n",
" self.assertEqual(knapsack.fill_knapsack(0, 0), 0)\n",
" items = []\n",
" items.append(Item(label='a', value=2, weight=2))\n",
" items.append(Item(label='b', value=4, weight=2))\n",
@ -162,18 +162,18 @@
" total_weight = 8\n",
" expected_value = 13\n",
" results = knapsack.fill_knapsack(items, total_weight)\n",
" assert_equal(results[0].label, 'd')\n",
" assert_equal(results[1].label, 'b')\n",
" self.assertEqual(results[0].label, 'd')\n",
" self.assertEqual(results[1].label, 'b')\n",
" total_value = 0\n",
" for item in results:\n",
" total_value += item.value\n",
" assert_equal(total_value, expected_value)\n",
" self.assertEqual(total_value, expected_value)\n",
" print('Success: test_knapsack_bottom_up')\n",
"\n",
" def test_knapsack_top_down(self):\n",
" knapsack = KnapsackTopDown()\n",
" assert_raises(TypeError, knapsack.fill_knapsack, None, None)\n",
" assert_equal(knapsack.fill_knapsack(0, 0), 0)\n",
" self.assertRaises(TypeError, knapsack.fill_knapsack, None, None)\n",
" self.assertEqual(knapsack.fill_knapsack(0, 0), 0)\n",
" items = []\n",
" items.append(Item(label='a', value=2, weight=2))\n",
" items.append(Item(label='b', value=4, weight=2))\n",
@ -181,7 +181,7 @@
" items.append(Item(label='d', value=9, weight=5))\n",
" total_weight = 8\n",
" expected_value = 13\n",
" assert_equal(knapsack.fill_knapsack(items, total_weight), expected_value)\n",
" self.assertEqual(knapsack.fill_knapsack(items, total_weight), expected_value)\n",
" print('Success: test_knapsack_top_down')\n",
"\n",
"def main():\n",
@ -220,7 +220,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
"version": "3.7.2"
}
},
"nbformat": 4,

View File

@ -132,9 +132,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"class Item(object):\n",
@ -158,9 +156,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class Knapsack(object):\n",
@ -208,9 +204,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class KnapsackTopDown(object):\n",
@ -255,9 +249,7 @@
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class Result(object):\n",
@ -328,9 +320,7 @@
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -342,15 +332,15 @@
],
"source": [
"%%writefile test_knapsack.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestKnapsack(object):\n",
"class TestKnapsack(unittest.TestCase):\n",
"\n",
" def test_knapsack_bottom_up(self):\n",
" knapsack = Knapsack()\n",
" assert_raises(TypeError, knapsack.fill_knapsack, None, None)\n",
" assert_equal(knapsack.fill_knapsack(0, 0), 0)\n",
" self.assertRaises(TypeError, knapsack.fill_knapsack, None, None)\n",
" self.assertEqual(knapsack.fill_knapsack(0, 0), 0)\n",
" items = []\n",
" items.append(Item(label='a', value=2, weight=2))\n",
" items.append(Item(label='b', value=4, weight=2))\n",
@ -359,18 +349,18 @@
" total_weight = 8\n",
" expected_value = 13\n",
" results = knapsack.fill_knapsack(items, total_weight)\n",
" assert_equal(results[0].label, 'd')\n",
" assert_equal(results[1].label, 'b')\n",
" self.assertEqual(results[0].label, 'd')\n",
" self.assertEqual(results[1].label, 'b')\n",
" total_value = 0\n",
" for item in results:\n",
" total_value += item.value\n",
" assert_equal(total_value, expected_value)\n",
" self.assertEqual(total_value, expected_value)\n",
" print('Success: test_knapsack_bottom_up')\n",
"\n",
" def test_knapsack_top_down(self):\n",
" knapsack = KnapsackTopDown()\n",
" assert_raises(TypeError, knapsack.fill_knapsack, None, None)\n",
" assert_equal(knapsack.fill_knapsack(0, 0), 0)\n",
" self.assertRaises(TypeError, knapsack.fill_knapsack, None, None)\n",
" self.assertEqual(knapsack.fill_knapsack(0, 0), 0)\n",
" items = []\n",
" items.append(Item(label='a', value=2, weight=2))\n",
" items.append(Item(label='b', value=4, weight=2))\n",
@ -378,7 +368,7 @@
" items.append(Item(label='d', value=9, weight=5))\n",
" total_weight = 8\n",
" expected_value = 13\n",
" assert_equal(knapsack.fill_knapsack(items, total_weight), expected_value)\n",
" self.assertEqual(knapsack.fill_knapsack(items, total_weight), expected_value)\n",
" print('Success: test_knapsack_top_down')\n",
"\n",
"def main():\n",
@ -394,9 +384,7 @@
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -428,9 +416,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
}

View File

@ -1,12 +1,12 @@
from nose.tools import assert_equal, assert_raises
import unittest
class TestKnapsack(object):
class TestKnapsack(unittest.TestCase):
def test_knapsack_bottom_up(self):
knapsack = Knapsack()
assert_raises(TypeError, knapsack.fill_knapsack, None, None)
assert_equal(knapsack.fill_knapsack(0, 0), 0)
self.assertRaises(TypeError, knapsack.fill_knapsack, None, None)
self.assertEqual(knapsack.fill_knapsack(0, 0), 0)
items = []
items.append(Item(label='a', value=2, weight=2))
items.append(Item(label='b', value=4, weight=2))
@ -15,18 +15,18 @@ class TestKnapsack(object):
total_weight = 8
expected_value = 13
results = knapsack.fill_knapsack(items, total_weight)
assert_equal(results[0].label, 'd')
assert_equal(results[1].label, 'b')
self.assertEqual(results[0].label, 'd')
self.assertEqual(results[1].label, 'b')
total_value = 0
for item in results:
total_value += item.value
assert_equal(total_value, expected_value)
self.assertEqual(total_value, expected_value)
print('Success: test_knapsack_bottom_up')
def test_knapsack_top_down(self):
knapsack = KnapsackTopDown()
assert_raises(TypeError, knapsack.fill_knapsack, None, None)
assert_equal(knapsack.fill_knapsack(0, 0), 0)
self.assertRaises(TypeError, knapsack.fill_knapsack, None, None)
self.assertEqual(knapsack.fill_knapsack(0, 0), 0)
items = []
items.append(Item(label='a', value=2, weight=2))
items.append(Item(label='b', value=4, weight=2))
@ -34,7 +34,7 @@ class TestKnapsack(object):
items.append(Item(label='d', value=9, weight=5))
total_weight = 8
expected_value = 13
assert_equal(knapsack.fill_knapsack(items, total_weight), expected_value)
self.assertEqual(knapsack.fill_knapsack(items, total_weight), expected_value)
print('Success: test_knapsack_top_down')
def main():
@ -44,4 +44,4 @@ def main():
if __name__ == '__main__':
main()
main()

View File

@ -111,9 +111,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class Knapsack(object):\n",
@ -140,21 +138,19 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# %load test_knapsack_unbounded.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestKnapsack(object):\n",
"class TestKnapsack(unittest.TestCase):\n",
"\n",
" def test_knapsack(self):\n",
" knapsack = Knapsack()\n",
" assert_raises(TypeError, knapsack.fill_knapsack, None, None)\n",
" assert_equal(knapsack.fill_knapsack(0, 0), 0)\n",
" self.assertRaises(TypeError, knapsack.fill_knapsack, None, None)\n",
" self.assertEqual(knapsack.fill_knapsack(0, 0), 0)\n",
" items = []\n",
" items.append(Item(label='a', value=1, weight=1))\n",
" items.append(Item(label='b', value=3, weight=2))\n",
@ -165,7 +161,7 @@
" total_weight = 7\n",
" expected_value = 11\n",
" results = knapsack.fill_knapsack(items, total_weight)\n",
" assert_equal(results, expected_value)\n",
" self.assertEqual(results, expected_value)\n",
" print('Success: test_knapsack')\n",
"\n",
"def main():\n",
@ -203,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
}

View File

@ -150,9 +150,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"class Item(object):\n",
@ -176,9 +174,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class Knapsack(object):\n",
@ -209,9 +205,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -223,15 +217,15 @@
],
"source": [
"%%writefile test_knapsack_unbounded.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestKnapsack(object):\n",
"class TestKnapsack(unittest.TestCase):\n",
"\n",
" def test_knapsack(self):\n",
" knapsack = Knapsack()\n",
" assert_raises(TypeError, knapsack.fill_knapsack, None, None)\n",
" assert_equal(knapsack.fill_knapsack(0, 0), 0)\n",
" self.assertRaises(TypeError, knapsack.fill_knapsack, None, None)\n",
" self.assertEqual(knapsack.fill_knapsack(0, 0), 0)\n",
" items = []\n",
" items.append(Item(label='a', value=1, weight=1))\n",
" items.append(Item(label='b', value=3, weight=2))\n",
@ -242,7 +236,7 @@
" total_weight = 7\n",
" expected_value = 11\n",
" results = knapsack.fill_knapsack(items, total_weight)\n",
" assert_equal(results, expected_value)\n",
" self.assertEqual(results, expected_value)\n",
" print('Success: test_knapsack')\n",
"\n",
"def main():\n",
@ -257,9 +251,7 @@
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -290,9 +282,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
}

View File

@ -1,12 +1,12 @@
from nose.tools import assert_equal, assert_raises
import unittest
class TestKnapsack(object):
class TestKnapsack(unittest.TestCase):
def test_knapsack(self):
knapsack = Knapsack()
assert_raises(TypeError, knapsack.fill_knapsack, None, None)
assert_equal(knapsack.fill_knapsack(0, 0), 0)
self.assertRaises(TypeError, knapsack.fill_knapsack, None, None)
self.assertEqual(knapsack.fill_knapsack(0, 0), 0)
items = []
items.append(Item(label='a', value=1, weight=1))
items.append(Item(label='b', value=3, weight=2))
@ -17,7 +17,7 @@ class TestKnapsack(object):
total_weight = 7
expected_value = 11
results = knapsack.fill_knapsack(items, total_weight)
assert_equal(results, expected_value)
self.assertEqual(results, expected_value)
print('Success: test_knapsack')
def main():
@ -26,4 +26,4 @@ def main():
if __name__ == '__main__':
main()
main()

View File

@ -83,9 +83,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class StringCompare(object):\n",
@ -112,25 +110,23 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# %load test_longest_common_subseq.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestLongestCommonSubseq(object):\n",
"class TestLongestCommonSubseq(unittest.TestCase):\n",
"\n",
" def test_longest_common_subseq(self):\n",
" str_comp = StringCompare()\n",
" assert_raises(TypeError, str_comp.longest_common_subseq, None, None)\n",
" assert_equal(str_comp.longest_common_subseq('', ''), '')\n",
" self.assertRaises(TypeError, str_comp.longest_common_subseq, None, None)\n",
" self.assertEqual(str_comp.longest_common_subseq('', ''), '')\n",
" str0 = 'ABCDEFGHIJ'\n",
" str1 = 'FOOBCDBCDE'\n",
" expected = 'BCDE'\n",
" assert_equal(str_comp.longest_common_subseq(str0, str1), expected)\n",
" self.assertEqual(str_comp.longest_common_subseq(str0, str1), expected)\n",
" print('Success: test_longest_common_subseq')\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
}

View File

@ -116,9 +116,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class StringCompare(object):\n",
@ -169,9 +167,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -183,19 +179,19 @@
],
"source": [
"%%writefile test_longest_common_subseq.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestLongestCommonSubseq(object):\n",
"class TestLongestCommonSubseq(unittest.TestCase):\n",
"\n",
" def test_longest_common_subseq(self):\n",
" str_comp = StringCompare()\n",
" assert_raises(TypeError, str_comp.longest_common_subseq, None, None)\n",
" assert_equal(str_comp.longest_common_subseq('', ''), '')\n",
" self.assertRaises(TypeError, str_comp.longest_common_subseq, None, None)\n",
" self.assertEqual(str_comp.longest_common_subseq('', ''), '')\n",
" str0 = 'ABCDEFGHIJ'\n",
" str1 = 'FOOBCDBCDE'\n",
" expected = 'BCDE'\n",
" assert_equal(str_comp.longest_common_subseq(str0, str1), expected)\n",
" self.assertEqual(str_comp.longest_common_subseq(str0, str1), expected)\n",
" print('Success: test_longest_common_subseq')\n",
"\n",
"\n",
@ -211,9 +207,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -244,9 +238,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
}

View File

@ -1,16 +1,16 @@
from nose.tools import assert_equal, assert_raises
import unittest
class TestLongestCommonSubseq(object):
class TestLongestCommonSubseq(unittest.TestCase):
def test_longest_common_subseq(self):
str_comp = StringCompare()
assert_raises(TypeError, str_comp.longest_common_subseq, None, None)
assert_equal(str_comp.longest_common_subseq('', ''), '')
self.assertRaises(TypeError, str_comp.longest_common_subseq, None, None)
self.assertEqual(str_comp.longest_common_subseq('', ''), '')
str0 = 'ABCDEFGHIJ'
str1 = 'FOOBCDBCDE'
expected = 'BCDE'
assert_equal(str_comp.longest_common_subseq(str0, str1), expected)
self.assertEqual(str_comp.longest_common_subseq(str0, str1), expected)
print('Success: test_longest_common_subseq')

View File

@ -76,9 +76,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class Subsequence(object):\n",
@ -105,24 +103,22 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# %load test_longest_increasing_subseq.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestLongestIncreasingSubseq(object):\n",
"class TestLongestIncreasingSubseq(unittest.TestCase):\n",
"\n",
" def test_longest_increasing_subseq(self):\n",
" subseq = Subsequence()\n",
" assert_raises(TypeError, subseq.longest_inc_subseq, None)\n",
" assert_equal(subseq.longest_inc_subseq([]), [])\n",
" self.assertRaises(TypeError, subseq.longest_inc_subseq, None)\n",
" self.assertEqual(subseq.longest_inc_subseq([]), [])\n",
" seq = [3, 4, -1, 0, 6, 2, 3]\n",
" expected = [-1, 0, 2, 3]\n",
" assert_equal(subseq.longest_inc_subseq(seq), expected)\n",
" self.assertEqual(subseq.longest_inc_subseq(seq), expected)\n",
" print('Success: test_longest_increasing_subseq')\n",
"\n",
"\n",
@ -161,9 +157,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.0"
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

View File

@ -105,9 +105,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"class Subsequence(object):\n",
@ -149,9 +147,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -163,18 +159,18 @@
],
"source": [
"%%writefile test_longest_increasing_subseq.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestLongestIncreasingSubseq(object):\n",
"class TestLongestIncreasingSubseq(unittest.TestCase):\n",
"\n",
" def test_longest_increasing_subseq(self):\n",
" subseq = Subsequence()\n",
" assert_raises(TypeError, subseq.longest_inc_subseq, None)\n",
" assert_equal(subseq.longest_inc_subseq([]), [])\n",
" self.assertRaises(TypeError, subseq.longest_inc_subseq, None)\n",
" self.assertEqual(subseq.longest_inc_subseq([]), [])\n",
" seq = [3, 4, -1, 0, 6, 2, 3]\n",
" expected = [-1, 0, 2, 3]\n",
" assert_equal(subseq.longest_inc_subseq(seq), expected)\n",
" self.assertEqual(subseq.longest_inc_subseq(seq), expected)\n",
" print('Success: test_longest_increasing_subseq')\n",
"\n",
"\n",
@ -190,9 +186,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -223,9 +217,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.0"
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

View File

@ -1,15 +1,15 @@
from nose.tools import assert_equal, assert_raises
import unittest
class TestLongestIncreasingSubseq(object):
class TestLongestIncreasingSubseq(unittest.TestCase):
def test_longest_increasing_subseq(self):
subseq = Subsequence()
assert_raises(TypeError, subseq.longest_inc_subseq, None)
assert_equal(subseq.longest_inc_subseq([]), [])
self.assertRaises(TypeError, subseq.longest_inc_subseq, None)
self.assertEqual(subseq.longest_inc_subseq([]), [])
seq = [3, 4, -1, 0, 6, 2, 3]
expected = [-1, 0, 2, 3]
assert_equal(subseq.longest_inc_subseq(seq), expected)
self.assertEqual(subseq.longest_inc_subseq(seq), expected)
print('Success: test_longest_increasing_subseq')
@ -19,4 +19,4 @@ def main():
if __name__ == '__main__':
main()
main()

View File

@ -79,9 +79,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class Solution(object):\n",
@ -108,23 +106,21 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# %load test_longest_substr.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestSolution(object):\n",
"class TestSolution(unittest.TestCase):\n",
"\n",
" def test_longest_substr(self):\n",
" solution = Solution()\n",
" assert_raises(TypeError, solution.longest_substr, None)\n",
" assert_equal(solution.longest_substr('', k=3), 0)\n",
" assert_equal(solution.longest_substr('abcabcdefgghiij', k=3), 6)\n",
" assert_equal(solution.longest_substr('abcabcdefgghighij', k=3), 7)\n",
" self.assertRaises(TypeError, solution.longest_substr, None)\n",
" self.assertEqual(solution.longest_substr('', k=3), 0)\n",
" self.assertEqual(solution.longest_substr('abcabcdefgghiij', k=3), 6)\n",
" self.assertEqual(solution.longest_substr('abcabcdefgghighij', k=3), 7)\n",
" print('Success: test_longest_substr')\n",
"\n",
"\n",
@ -163,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
}

View File

@ -92,9 +92,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class Solution(object):\n",
@ -127,9 +125,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -141,17 +137,17 @@
],
"source": [
"%%writefile test_longest_substr.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestSolution(object):\n",
"class TestSolution(unittest.TestCase):\n",
"\n",
" def test_longest_substr(self):\n",
" solution = Solution()\n",
" assert_raises(TypeError, solution.longest_substr, None)\n",
" assert_equal(solution.longest_substr('', k=3), 0)\n",
" assert_equal(solution.longest_substr('abcabcdefgghiij', k=3), 6)\n",
" assert_equal(solution.longest_substr('abcabcdefgghighij', k=3), 7)\n",
" self.assertRaises(TypeError, solution.longest_substr, None)\n",
" self.assertEqual(solution.longest_substr('', k=3), 0)\n",
" self.assertEqual(solution.longest_substr('abcabcdefgghiij', k=3), 6)\n",
" self.assertEqual(solution.longest_substr('abcabcdefgghighij', k=3), 7)\n",
" print('Success: test_longest_substr')\n",
"\n",
"\n",
@ -167,9 +163,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -200,9 +194,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.0"
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

View File

@ -1,14 +1,14 @@
from nose.tools import assert_equal, assert_raises
import unittest
class TestSolution(object):
class TestSolution(unittest.TestCase):
def test_longest_substr(self):
solution = Solution()
assert_raises(TypeError, solution.longest_substr, None)
assert_equal(solution.longest_substr('', k=3), 0)
assert_equal(solution.longest_substr('abcabcdefgghiij', k=3), 6)
assert_equal(solution.longest_substr('abcabcdefgghighij', k=3), 7)
self.assertRaises(TypeError, solution.longest_substr, None)
self.assertEqual(solution.longest_substr('', k=3), 0)
self.assertEqual(solution.longest_substr('abcabcdefgghiij', k=3), 6)
self.assertEqual(solution.longest_substr('abcabcdefgghighij', k=3), 7)
print('Success: test_longest_substr')
@ -18,4 +18,4 @@ def main():
if __name__ == '__main__':
main()
main()

View File

@ -83,9 +83,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class StringCompare(object):\n",
@ -112,25 +110,23 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# %load test_longest_common_substr.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestLongestCommonSubstr(object):\n",
"class TestLongestCommonSubstr(unittest.TestCase):\n",
"\n",
" def test_longest_common_substr(self):\n",
" str_comp = StringCompare()\n",
" assert_raises(TypeError, str_comp.longest_common_substr, None, None)\n",
" assert_equal(str_comp.longest_common_substr('', ''), '')\n",
" self.assertRaises(TypeError, str_comp.longest_common_substr, None, None)\n",
" self.assertEqual(str_comp.longest_common_substr('', ''), '')\n",
" str0 = 'ABCDEFGHIJ'\n",
" str1 = 'FOOBCDBCDE'\n",
" expected = 'BCDE'\n",
" assert_equal(str_comp.longest_common_substr(str0, str1), expected)\n",
" self.assertEqual(str_comp.longest_common_substr(str0, str1), expected)\n",
" print('Success: test_longest_common_substr')\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
}

View File

@ -116,9 +116,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class StringCompare(object):\n",
@ -169,9 +167,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -183,19 +179,19 @@
],
"source": [
"%%writefile test_longest_common_substr.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestLongestCommonSubstr(object):\n",
"class TestLongestCommonSubstr(unittest.TestCase):\n",
"\n",
" def test_longest_common_substr(self):\n",
" str_comp = StringCompare()\n",
" assert_raises(TypeError, str_comp.longest_common_substr, None, None)\n",
" assert_equal(str_comp.longest_common_substr('', ''), '')\n",
" self.assertRaises(TypeError, str_comp.longest_common_substr, None, None)\n",
" self.assertEqual(str_comp.longest_common_substr('', ''), '')\n",
" str0 = 'ABCDEFGHIJ'\n",
" str1 = 'FOOBCDBCDE'\n",
" expected = 'BCDE'\n",
" assert_equal(str_comp.longest_common_substr(str0, str1), expected)\n",
" self.assertEqual(str_comp.longest_common_substr(str0, str1), expected)\n",
" print('Success: test_longest_common_substr')\n",
"\n",
"\n",
@ -211,9 +207,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -244,9 +238,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.0"
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

View File

@ -1,16 +1,16 @@
from nose.tools import assert_equal, assert_raises
import unittest
class TestLongestCommonSubstr(object):
class TestLongestCommonSubstr(unittest.TestCase):
def test_longest_common_substr(self):
str_comp = StringCompare()
assert_raises(TypeError, str_comp.longest_common_substr, None, None)
assert_equal(str_comp.longest_common_substr('', ''), '')
self.assertRaises(TypeError, str_comp.longest_common_substr, None, None)
self.assertEqual(str_comp.longest_common_substr('', ''), '')
str0 = 'ABCDEFGHIJ'
str1 = 'FOOBCDBCDE'
expected = 'BCDE'
assert_equal(str_comp.longest_common_substr(str0, str1), expected)
self.assertEqual(str_comp.longest_common_substr(str0, str1), expected)
print('Success: test_longest_common_substr')
@ -20,4 +20,4 @@ def main():
if __name__ == '__main__':
main()
main()

View File

@ -100,9 +100,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class MagicIndex(object):\n",
@ -129,27 +127,25 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# %load test_find_magic_index.py\n",
"from nose.tools import assert_equal\n",
"import unittest\n",
"\n",
"\n",
"class TestFindMagicIndex(object):\n",
"class TestFindMagicIndex(unittest.TestCase):\n",
"\n",
" def test_find_magic_index(self):\n",
" magic_index = MagicIndex()\n",
" assert_equal(magic_index.find_magic_index(None), -1)\n",
" assert_equal(magic_index.find_magic_index([]), -1)\n",
" self.assertEqual(magic_index.find_magic_index(None), -1)\n",
" self.assertEqual(magic_index.find_magic_index([]), -1)\n",
" array = [-4, -2, 2, 6, 6, 6, 6, 10]\n",
" assert_equal(magic_index.find_magic_index(array), 2)\n",
" self.assertEqual(magic_index.find_magic_index(array), 2)\n",
" array = [-4, -2, 1, 6, 6, 6, 6, 10]\n",
" assert_equal(magic_index.find_magic_index(array), 6)\n",
" self.assertEqual(magic_index.find_magic_index(array), 6)\n",
" array = [-4, -2, 1, 6, 6, 6, 7, 10]\n",
" assert_equal(magic_index.find_magic_index(array), -1)\n",
" self.assertEqual(magic_index.find_magic_index(array), -1)\n",
" print('Success: test_find_magic')\n",
"\n",
"\n",
@ -188,9 +184,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.0"
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

View File

@ -129,9 +129,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"from __future__ import division\n",
@ -171,9 +169,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -185,21 +181,21 @@
],
"source": [
"%%writefile test_find_magic_index.py\n",
"from nose.tools import assert_equal\n",
"import unittest\n",
"\n",
"\n",
"class TestFindMagicIndex(object):\n",
"class TestFindMagicIndex(unittest.TestCase):\n",
"\n",
" def test_find_magic_index(self):\n",
" magic_index = MagicIndex()\n",
" assert_equal(magic_index.find_magic_index(None), -1)\n",
" assert_equal(magic_index.find_magic_index([]), -1)\n",
" self.assertEqual(magic_index.find_magic_index(None), -1)\n",
" self.assertEqual(magic_index.find_magic_index([]), -1)\n",
" array = [-4, -2, 2, 6, 6, 6, 6, 10]\n",
" assert_equal(magic_index.find_magic_index(array), 2)\n",
" self.assertEqual(magic_index.find_magic_index(array), 2)\n",
" array = [-4, -2, 1, 6, 6, 6, 6, 10]\n",
" assert_equal(magic_index.find_magic_index(array), 6)\n",
" self.assertEqual(magic_index.find_magic_index(array), 6)\n",
" array = [-4, -2, 1, 6, 6, 6, 7, 10]\n",
" assert_equal(magic_index.find_magic_index(array), -1)\n",
" self.assertEqual(magic_index.find_magic_index(array), -1)\n",
" print('Success: test_find_magic')\n",
"\n",
"\n",
@ -215,9 +211,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -248,9 +242,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
}

View File

@ -1,18 +1,18 @@
from nose.tools import assert_equal
import unittest
class TestFindMagicIndex(object):
class TestFindMagicIndex(unittest.TestCase):
def test_find_magic_index(self):
magic_index = MagicIndex()
assert_equal(magic_index.find_magic_index(None), -1)
assert_equal(magic_index.find_magic_index([]), -1)
self.assertEqual(magic_index.find_magic_index(None), -1)
self.assertEqual(magic_index.find_magic_index([]), -1)
array = [-4, -2, 2, 6, 6, 6, 6, 10]
assert_equal(magic_index.find_magic_index(array), 2)
self.assertEqual(magic_index.find_magic_index(array), 2)
array = [-4, -2, 1, 6, 6, 6, 6, 10]
assert_equal(magic_index.find_magic_index(array), 6)
self.assertEqual(magic_index.find_magic_index(array), 6)
array = [-4, -2, 1, 6, 6, 6, 7, 10]
assert_equal(magic_index.find_magic_index(array), -1)
self.assertEqual(magic_index.find_magic_index(array), -1)
print('Success: test_find_magic')
@ -22,4 +22,4 @@ def main():
if __name__ == '__main__':
main()
main()

View File

@ -87,9 +87,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class MatrixMultiplicationCost(object):\n",
@ -116,27 +114,25 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# %load test_find_min_cost.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestMatrixMultiplicationCost(object):\n",
"class TestMatrixMultiplicationCost(unittest.TestCase):\n",
"\n",
" def test_find_min_cost(self):\n",
" matrix_mult_cost = MatrixMultiplicationCost()\n",
" assert_raises(TypeError, matrix_mult_cost.find_min_cost, None)\n",
" assert_equal(matrix_mult_cost.find_min_cost([]), 0)\n",
" self.assertRaises(TypeError, matrix_mult_cost.find_min_cost, None)\n",
" self.assertEqual(matrix_mult_cost.find_min_cost([]), 0)\n",
" matrices = [Matrix(2, 3),\n",
" Matrix(3, 6),\n",
" Matrix(6, 4),\n",
" Matrix(4, 5)]\n",
" expected_cost = 124\n",
" assert_equal(matrix_mult_cost.find_min_cost(matrices), expected_cost)\n",
" self.assertEqual(matrix_mult_cost.find_min_cost(matrices), expected_cost)\n",
" print('Success: test_find_min_cost')\n",
"\n",
"\n",
@ -175,9 +171,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.0"
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

View File

@ -174,9 +174,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"class Matrix(object):\n",
@ -189,9 +187,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
@ -231,9 +227,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -245,21 +239,21 @@
],
"source": [
"%%writefile test_find_min_cost.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestMatrixMultiplicationCost(object):\n",
"class TestMatrixMultiplicationCost(unittest.TestCase):\n",
"\n",
" def test_find_min_cost(self):\n",
" matrix_mult_cost = MatrixMultiplicationCost()\n",
" assert_raises(TypeError, matrix_mult_cost.find_min_cost, None)\n",
" assert_equal(matrix_mult_cost.find_min_cost([]), 0)\n",
" self.assertRaises(TypeError, matrix_mult_cost.find_min_cost, None)\n",
" self.assertEqual(matrix_mult_cost.find_min_cost([]), 0)\n",
" matrices = [Matrix(2, 3),\n",
" Matrix(3, 6),\n",
" Matrix(6, 4),\n",
" Matrix(4, 5)]\n",
" expected_cost = 124\n",
" assert_equal(matrix_mult_cost.find_min_cost(matrices), expected_cost)\n",
" self.assertEqual(matrix_mult_cost.find_min_cost(matrices), expected_cost)\n",
" print('Success: test_find_min_cost')\n",
"\n",
"\n",
@ -275,9 +269,7 @@
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -308,9 +300,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.0"
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

View File

@ -1,18 +1,18 @@
from nose.tools import assert_equal, assert_raises
import unittest
class TestMatrixMultiplicationCost(object):
class TestMatrixMultiplicationCost(unittest.TestCase):
def test_find_min_cost(self):
matrix_mult_cost = MatrixMultiplicationCost()
assert_raises(TypeError, matrix_mult_cost.find_min_cost, None)
assert_equal(matrix_mult_cost.find_min_cost([]), 0)
self.assertRaises(TypeError, matrix_mult_cost.find_min_cost, None)
self.assertEqual(matrix_mult_cost.find_min_cost([]), 0)
matrices = [Matrix(2, 3),
Matrix(3, 6),
Matrix(6, 4),
Matrix(4, 5)]
expected_cost = 124
assert_equal(matrix_mult_cost.find_min_cost(matrices), expected_cost)
self.assertEqual(matrix_mult_cost.find_min_cost(matrices), expected_cost)
print('Success: test_find_min_cost')
@ -22,4 +22,4 @@ def main():
if __name__ == '__main__':
main()
main()

View File

@ -124,9 +124,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class StockTrader(object):\n",
@ -153,45 +151,41 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# %load test_max_profit.py\n",
"from nose.tools import assert_equal\n",
"from nose.tools import assert_raises\n",
"from nose.tools import assert_true\n",
"import unittest\n",
"\n",
"\n",
"class TestMaxProfit(object):\n",
"class TestMaxProfit(unittest.TestCase):\n",
"\n",
" def test_max_profit(self):\n",
" stock_trader = StockTrader()\n",
" assert_raises(TypeError, stock_trader.find_max_profit, None, None)\n",
" assert_equal(stock_trader.find_max_profit(prices=[], k=0), [])\n",
" self.assertRaises(TypeError, stock_trader.find_max_profit, None, None)\n",
" self.assertEqual(stock_trader.find_max_profit(prices=[], k=0), [])\n",
" prices = [5, 4, 3, 2, 1]\n",
" k = 3\n",
" assert_equal(stock_trader.find_max_profit(prices, k), (0, []))\n",
" self.assertEqual(stock_trader.find_max_profit(prices, k), (0, []))\n",
" prices = [2, 5, 7, 1, 4, 3, 1, 3]\n",
" profit, transactions = stock_trader.find_max_profit(prices, k)\n",
" assert_equal(profit, 10)\n",
" assert_true(Transaction(Type.SELL,\n",
" self.assertEqual(profit, 10)\n",
" self.assertTrue(Transaction(Type.SELL,\n",
" day=7,\n",
" price=3) in transactions)\n",
" assert_true(Transaction(Type.BUY,\n",
" self.assertTrue(Transaction(Type.BUY,\n",
" day=6,\n",
" price=1) in transactions)\n",
" assert_true(Transaction(Type.SELL,\n",
" self.assertTrue(Transaction(Type.SELL,\n",
" day=4,\n",
" price=4) in transactions)\n",
" assert_true(Transaction(Type.BUY,\n",
" self.assertTrue(Transaction(Type.BUY,\n",
" day=3,\n",
" price=1) in transactions)\n",
" assert_true(Transaction(Type.SELL,\n",
" self.assertTrue(Transaction(Type.SELL,\n",
" day=2,\n",
" price=7) in transactions)\n",
" assert_true(Transaction(Type.BUY,\n",
" self.assertTrue(Transaction(Type.BUY,\n",
" day=0,\n",
" price=2) in transactions)\n",
" print('Success: test_max_profit')\n",
@ -232,9 +226,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.0"
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

View File

@ -123,9 +123,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"from enum import Enum # Python 2 users: Run pip install enum34\n",
@ -157,9 +155,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
@ -241,9 +237,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -255,39 +249,37 @@
],
"source": [
"%%writefile test_max_profit.py\n",
"from nose.tools import assert_equal\n",
"from nose.tools import assert_raises\n",
"from nose.tools import assert_true\n",
"import unittest\n",
"\n",
"\n",
"class TestMaxProfit(object):\n",
"class TestMaxProfit(unittest.TestCase):\n",
"\n",
" def test_max_profit(self):\n",
" stock_trader = StockTrader()\n",
" assert_raises(TypeError, stock_trader.find_max_profit, None, None)\n",
" assert_equal(stock_trader.find_max_profit(prices=[], k=0), [])\n",
" self.assertRaises(TypeError, stock_trader.find_max_profit, None, None)\n",
" self.assertEqual(stock_trader.find_max_profit(prices=[], k=0), [])\n",
" prices = [5, 4, 3, 2, 1]\n",
" k = 3\n",
" assert_equal(stock_trader.find_max_profit(prices, k), (0, []))\n",
" self.assertEqual(stock_trader.find_max_profit(prices, k), (0, []))\n",
" prices = [2, 5, 7, 1, 4, 3, 1, 3]\n",
" profit, transactions = stock_trader.find_max_profit(prices, k)\n",
" assert_equal(profit, 10)\n",
" assert_true(Transaction(Type.SELL,\n",
" self.assertEqual(profit, 10)\n",
" self.assertTrue(Transaction(Type.SELL,\n",
" day=7,\n",
" price=3) in transactions)\n",
" assert_true(Transaction(Type.BUY,\n",
" self.assertTrue(Transaction(Type.BUY,\n",
" day=6,\n",
" price=1) in transactions)\n",
" assert_true(Transaction(Type.SELL,\n",
" self.assertTrue(Transaction(Type.SELL,\n",
" day=4,\n",
" price=4) in transactions)\n",
" assert_true(Transaction(Type.BUY,\n",
" self.assertTrue(Transaction(Type.BUY,\n",
" day=3,\n",
" price=1) in transactions)\n",
" assert_true(Transaction(Type.SELL,\n",
" self.assertTrue(Transaction(Type.SELL,\n",
" day=2,\n",
" price=7) in transactions)\n",
" assert_true(Transaction(Type.BUY,\n",
" self.assertTrue(Transaction(Type.BUY,\n",
" day=0,\n",
" price=2) in transactions)\n",
" print('Success: test_max_profit')\n",
@ -305,9 +297,7 @@
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -338,9 +328,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
}

View File

@ -1,36 +1,34 @@
from nose.tools import assert_equal
from nose.tools import assert_raises
from nose.tools import assert_true
import unittest
class TestMaxProfit(object):
class TestMaxProfit(unittest.TestCase):
def test_max_profit(self):
stock_trader = StockTrader()
assert_raises(TypeError, stock_trader.find_max_profit, None, None)
assert_equal(stock_trader.find_max_profit(prices=[], k=0), [])
self.assertRaises(TypeError, stock_trader.find_max_profit, None, None)
self.assertEqual(stock_trader.find_max_profit(prices=[], k=0), [])
prices = [5, 4, 3, 2, 1]
k = 3
assert_equal(stock_trader.find_max_profit(prices, k), (0, []))
self.assertEqual(stock_trader.find_max_profit(prices, k), (0, []))
prices = [2, 5, 7, 1, 4, 3, 1, 3]
profit, transactions = stock_trader.find_max_profit(prices, k)
assert_equal(profit, 10)
assert_true(Transaction(Type.SELL,
self.assertEqual(profit, 10)
self.assertTrue(Transaction(Type.SELL,
day=7,
price=3) in transactions)
assert_true(Transaction(Type.BUY,
self.assertTrue(Transaction(Type.BUY,
day=6,
price=1) in transactions)
assert_true(Transaction(Type.SELL,
self.assertTrue(Transaction(Type.SELL,
day=4,
price=4) in transactions)
assert_true(Transaction(Type.BUY,
self.assertTrue(Transaction(Type.BUY,
day=3,
price=1) in transactions)
assert_true(Transaction(Type.SELL,
self.assertTrue(Transaction(Type.SELL,
day=2,
price=7) in transactions)
assert_true(Transaction(Type.BUY,
self.assertTrue(Transaction(Type.BUY,
day=0,
price=2) in transactions)
print('Success: test_max_profit')
@ -42,4 +40,4 @@ def main():
if __name__ == '__main__':
main()
main()

View File

@ -103,26 +103,24 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# %load test_n_pairs_parentheses.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestPairParentheses(object):\n",
"class TestPairParentheses(unittest.TestCase):\n",
"\n",
" def test_pair_parentheses(self):\n",
" parentheses = Parentheses()\n",
" assert_raises(TypeError, parentheses.find_pair, None)\n",
" assert_raises(ValueError, parentheses.find_pair, -1)\n",
" assert_equal(parentheses.find_pair(0), [])\n",
" assert_equal(parentheses.find_pair(1), ['()'])\n",
" assert_equal(parentheses.find_pair(2), ['(())',\n",
" self.assertRaises(TypeError, parentheses.find_pair, None)\n",
" self.assertRaises(ValueError, parentheses.find_pair, -1)\n",
" self.assertEqual(parentheses.find_pair(0), [])\n",
" self.assertEqual(parentheses.find_pair(1), ['()'])\n",
" self.assertEqual(parentheses.find_pair(2), ['(())',\n",
" '()()'])\n",
" assert_equal(parentheses.find_pair(3), ['((()))',\n",
" self.assertEqual(parentheses.find_pair(3), ['((()))',\n",
" '(()())',\n",
" '(())()',\n",
" '()(())',\n",
@ -165,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
}

View File

@ -98,9 +98,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"class Parentheses(object):\n",
@ -137,9 +135,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -151,20 +147,20 @@
],
"source": [
"%%writefile test_n_pairs_parentheses.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestPairParentheses(object):\n",
"class TestPairParentheses(unittest.TestCase):\n",
"\n",
" def test_pair_parentheses(self):\n",
" parentheses = Parentheses()\n",
" assert_raises(TypeError, parentheses.find_pair, None)\n",
" assert_raises(ValueError, parentheses.find_pair, -1)\n",
" assert_equal(parentheses.find_pair(0), [])\n",
" assert_equal(parentheses.find_pair(1), ['()'])\n",
" assert_equal(parentheses.find_pair(2), ['(())',\n",
" self.assertRaises(TypeError, parentheses.find_pair, None)\n",
" self.assertRaises(ValueError, parentheses.find_pair, -1)\n",
" self.assertEqual(parentheses.find_pair(0), [])\n",
" self.assertEqual(parentheses.find_pair(1), ['()'])\n",
" self.assertEqual(parentheses.find_pair(2), ['(())',\n",
" '()()'])\n",
" assert_equal(parentheses.find_pair(3), ['((()))',\n",
" self.assertEqual(parentheses.find_pair(3), ['((()))',\n",
" '(()())',\n",
" '(())()',\n",
" '()(())',\n",
@ -184,9 +180,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -217,9 +211,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.0"
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

View File

@ -1,17 +1,17 @@
from nose.tools import assert_equal, assert_raises
import unittest
class TestPairParentheses(object):
class TestPairParentheses(unittest.TestCase):
def test_pair_parentheses(self):
parentheses = Parentheses()
assert_raises(TypeError, parentheses.find_pair, None)
assert_raises(ValueError, parentheses.find_pair, -1)
assert_equal(parentheses.find_pair(0), [])
assert_equal(parentheses.find_pair(1), ['()'])
assert_equal(parentheses.find_pair(2), ['(())',
self.assertRaises(TypeError, parentheses.find_pair, None)
self.assertRaises(ValueError, parentheses.find_pair, -1)
self.assertEqual(parentheses.find_pair(0), [])
self.assertEqual(parentheses.find_pair(1), ['()'])
self.assertEqual(parentheses.find_pair(2), ['(())',
'()()'])
assert_equal(parentheses.find_pair(3), ['((()))',
self.assertEqual(parentheses.find_pair(3), ['((()))',
'(()())',
'(())()',
'()(())',
@ -25,4 +25,4 @@ def main():
if __name__ == '__main__':
main()
main()

View File

@ -82,9 +82,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class Permutations(object):\n",
@ -111,28 +109,26 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# %load test_permutations.py\n",
"from nose.tools import assert_equal\n",
"import unittest\n",
"\n",
"\n",
"class TestPermutations(object):\n",
"class TestPermutations(unittest.TestCase):\n",
"\n",
" def test_permutations(self):\n",
" permutations = Permutations()\n",
" assert_equal(permutations.find_permutations(None), None)\n",
" assert_equal(permutations.find_permutations(''), '')\n",
" self.assertEqual(permutations.find_permutations(None), None)\n",
" self.assertEqual(permutations.find_permutations(''), '')\n",
" string = 'AABC'\n",
" expected = [\n",
" 'AABC', 'AACB', 'ABAC', 'ABCA',\n",
" 'ACAB', 'ACBA', 'BAAC', 'BACA',\n",
" 'BCAA', 'CAAB', 'CABA', 'CBAA'\n",
" ]\n",
" assert_equal(permutations.find_permutations(string), expected)\n",
" self.assertEqual(permutations.find_permutations(string), expected)\n",
" print('Success: test_permutations')\n",
"\n",
"\n",
@ -171,9 +167,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.0"
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

View File

@ -94,9 +94,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"from collections import OrderedDict\n",
@ -148,9 +146,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -162,22 +158,22 @@
],
"source": [
"%%writefile test_permutations.py\n",
"from nose.tools import assert_equal\n",
"import unittest\n",
"\n",
"\n",
"class TestPermutations(object):\n",
"class TestPermutations(unittest.TestCase):\n",
"\n",
" def test_permutations(self):\n",
" permutations = Permutations()\n",
" assert_equal(permutations.find_permutations(None), None)\n",
" assert_equal(permutations.find_permutations(''), '')\n",
" self.assertEqual(permutations.find_permutations(None), None)\n",
" self.assertEqual(permutations.find_permutations(''), '')\n",
" string = 'AABC'\n",
" expected = [\n",
" 'AABC', 'AACB', 'ABAC', 'ABCA',\n",
" 'ACAB', 'ACBA', 'BAAC', 'BACA',\n",
" 'BCAA', 'CAAB', 'CABA', 'CBAA'\n",
" ]\n",
" assert_equal(permutations.find_permutations(string), expected)\n",
" self.assertEqual(permutations.find_permutations(string), expected)\n",
" print('Success: test_permutations')\n",
"\n",
"\n",
@ -193,9 +189,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -226,9 +220,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.0"
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

View File

@ -1,19 +1,19 @@
from nose.tools import assert_equal
import unittest
class TestPermutations(object):
class TestPermutations(unittest.TestCase):
def test_permutations(self):
permutations = Permutations()
assert_equal(permutations.find_permutations(None), None)
assert_equal(permutations.find_permutations(''), '')
self.assertEqual(permutations.find_permutations(None), None)
self.assertEqual(permutations.find_permutations(''), '')
string = 'AABC'
expected = [
'AABC', 'AACB', 'ABAC', 'ABCA',
'ACAB', 'ACBA', 'BAAC', 'BACA',
'BCAA', 'CAAB', 'CABA', 'CBAA'
]
assert_equal(permutations.find_permutations(string), expected)
self.assertEqual(permutations.find_permutations(string), expected)
print('Success: test_permutations')
@ -23,4 +23,4 @@ def main():
if __name__ == '__main__':
main()
main()

View File

@ -91,9 +91,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class Sets(object):\n",
@ -124,16 +122,14 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# %load test_power_set.py\n",
"from nose.tools import assert_equal\n",
"import unittest\n",
"\n",
"\n",
"class TestPowerSet(object):\n",
"class TestPowerSet(unittest.TestCase):\n",
"\n",
" def test_power_set(self):\n",
" input_set = []\n",
@ -154,9 +150,9 @@
" def run_test(self, input_set, expected):\n",
" combinatoric = Combinatoric()\n",
" result = combinatoric.find_power_set_recursive(input_set)\n",
" assert_equal(result, expected)\n",
" self.assertEqual(result, expected)\n",
" result = combinatoric.find_power_set_iterative(input_set)\n",
" assert_equal(result, expected)\n",
" self.assertEqual(result, expected)\n",
"\n",
"\n",
"def main():\n",
@ -194,9 +190,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.0"
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

View File

@ -115,9 +115,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"from collections import OrderedDict\n",
@ -171,9 +169,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -185,10 +181,10 @@
],
"source": [
"%%writefile test_power_set.py\n",
"from nose.tools import assert_equal\n",
"import unittest\n",
"\n",
"\n",
"class TestPowerSet(object):\n",
"class TestPowerSet(unittest.TestCase):\n",
"\n",
" def test_power_set(self):\n",
" input_set = ''\n",
@ -214,7 +210,7 @@
" def run_test(self, input_set, expected):\n",
" combinatoric = Combinatoric()\n",
" result = combinatoric.find_power_set(input_set)\n",
" assert_equal(result, expected)\n",
" self.assertEqual(result, expected)\n",
"\n",
"\n",
"def main():\n",
@ -229,9 +225,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -262,9 +256,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
}

View File

@ -1,7 +1,7 @@
from nose.tools import assert_equal
import unittest
class TestPowerSet(object):
class TestPowerSet(unittest.TestCase):
def test_power_set(self):
input_set = ''
@ -27,7 +27,7 @@ class TestPowerSet(object):
def run_test(self, input_set, expected):
combinatoric = Combinatoric()
result = combinatoric.find_power_set(input_set)
assert_equal(result, expected)
self.assertEqual(result, expected)
def main():
@ -36,4 +36,4 @@ def main():
if __name__ == '__main__':
main()
main()

View File

@ -76,9 +76,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class Steps(object):\n",
@ -105,27 +103,25 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# %load test_steps.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestSteps(object):\n",
"class TestSteps(unittest.TestCase):\n",
"\n",
" def test_steps(self):\n",
" steps = Steps()\n",
" assert_raises(TypeError, steps.count_ways, None)\n",
" assert_raises(TypeError, steps.count_ways, -1)\n",
" assert_equal(steps.count_ways(0), 1)\n",
" assert_equal(steps.count_ways(1), 1)\n",
" assert_equal(steps.count_ways(2), 2)\n",
" assert_equal(steps.count_ways(3), 4)\n",
" assert_equal(steps.count_ways(4), 7)\n",
" assert_equal(steps.count_ways(10), 274)\n",
" self.assertRaises(TypeError, steps.count_ways, None)\n",
" self.assertRaises(TypeError, steps.count_ways, -1)\n",
" self.assertEqual(steps.count_ways(0), 1)\n",
" self.assertEqual(steps.count_ways(1), 1)\n",
" self.assertEqual(steps.count_ways(2), 2)\n",
" self.assertEqual(steps.count_ways(3), 4)\n",
" self.assertEqual(steps.count_ways(4), 7)\n",
" self.assertEqual(steps.count_ways(10), 274)\n",
" print('Success: test_steps')\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
}

View File

@ -107,9 +107,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class Steps(object):\n",
@ -143,9 +141,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -157,21 +153,21 @@
],
"source": [
"%%writefile test_steps.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestSteps(object):\n",
"class TestSteps(unittest.TestCase):\n",
"\n",
" def test_steps(self):\n",
" steps = Steps()\n",
" assert_raises(TypeError, steps.count_ways, None)\n",
" assert_raises(TypeError, steps.count_ways, -1)\n",
" assert_equal(steps.count_ways(0), 1)\n",
" assert_equal(steps.count_ways(1), 1)\n",
" assert_equal(steps.count_ways(2), 2)\n",
" assert_equal(steps.count_ways(3), 4)\n",
" assert_equal(steps.count_ways(4), 7)\n",
" assert_equal(steps.count_ways(10), 274)\n",
" self.assertRaises(TypeError, steps.count_ways, None)\n",
" self.assertRaises(TypeError, steps.count_ways, -1)\n",
" self.assertEqual(steps.count_ways(0), 1)\n",
" self.assertEqual(steps.count_ways(1), 1)\n",
" self.assertEqual(steps.count_ways(2), 2)\n",
" self.assertEqual(steps.count_ways(3), 4)\n",
" self.assertEqual(steps.count_ways(4), 7)\n",
" self.assertEqual(steps.count_ways(10), 274)\n",
" print('Success: test_steps')\n",
"\n",
"\n",
@ -187,9 +183,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -220,9 +214,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.0"
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

View File

@ -1,18 +1,18 @@
from nose.tools import assert_equal, assert_raises
import unittest
class TestSteps(object):
class TestSteps(unittest.TestCase):
def test_steps(self):
steps = Steps()
assert_raises(TypeError, steps.count_ways, None)
assert_raises(TypeError, steps.count_ways, -1)
assert_equal(steps.count_ways(0), 1)
assert_equal(steps.count_ways(1), 1)
assert_equal(steps.count_ways(2), 2)
assert_equal(steps.count_ways(3), 4)
assert_equal(steps.count_ways(4), 7)
assert_equal(steps.count_ways(10), 274)
self.assertRaises(TypeError, steps.count_ways, None)
self.assertRaises(TypeError, steps.count_ways, -1)
self.assertEqual(steps.count_ways(0), 1)
self.assertEqual(steps.count_ways(1), 1)
self.assertEqual(steps.count_ways(2), 2)
self.assertEqual(steps.count_ways(3), 4)
self.assertEqual(steps.count_ways(4), 7)
self.assertEqual(steps.count_ways(10), 274)
print('Success: test_steps')
@ -22,4 +22,4 @@ def main():
if __name__ == '__main__':
main()
main()