mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-05 17:08:02 +00:00
Reworked tree bfs unit tests.
This commit is contained in:
@@ -84,7 +84,8 @@
|
|||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"def bfs(self, visit_func):\n",
|
"def bfs(self, visit_func):\n",
|
||||||
" # TODO: Implement me"
|
" # TODO: Implement me\n",
|
||||||
|
" pass"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -102,7 +103,7 @@
|
|||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%run ../utils/captured_output.py"
|
"%run ../utils/results.py"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -114,22 +115,22 @@
|
|||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# %load test_bfs.py\n",
|
"# %load test_bfs.py\n",
|
||||||
"from __future__ import print_function\n",
|
|
||||||
"from nose.tools import assert_equal\n",
|
"from nose.tools import assert_equal\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestBfs(object):\n",
|
"class TestBfs(object):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_bfs(self):\n",
|
" def __init__(self):\n",
|
||||||
" root = Node(5)\n",
|
" self.results = Results()\n",
|
||||||
" root.insert(2)\n",
|
|
||||||
" root.insert(8)\n",
|
|
||||||
" root.insert(1)\n",
|
|
||||||
" root.insert(3)\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
" with captured_output() as (out, err):\n",
|
" def test_bfs(self):\n",
|
||||||
" root.bfs(sys.stdout.write)\n",
|
" node = Node(5)\n",
|
||||||
" assert_equal(out.getvalue().strip(), '52813')\n",
|
" insert(node, 2)\n",
|
||||||
|
" insert(node, 8)\n",
|
||||||
|
" insert(node, 1)\n",
|
||||||
|
" insert(node, 3)\n",
|
||||||
|
" bfs(node, self.results.add_result)\n",
|
||||||
|
" assert_equal(str(self.results), '[5, 2, 8, 1, 3]')\n",
|
||||||
"\n",
|
"\n",
|
||||||
" print('Success: test_bfs')\n",
|
" print('Success: test_bfs')\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
|||||||
@@ -122,7 +122,7 @@
|
|||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%run ../utils/captured_output.py"
|
"%run ../utils/results.py"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -142,22 +142,22 @@
|
|||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"%%writefile test_bfs.py\n",
|
"%%writefile test_bfs.py\n",
|
||||||
"from __future__ import print_function\n",
|
|
||||||
"from nose.tools import assert_equal\n",
|
"from nose.tools import assert_equal\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestBfs(object):\n",
|
"class TestBfs(object):\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
" def __init__(self):\n",
|
||||||
|
" self.results = Results()\n",
|
||||||
|
"\n",
|
||||||
" def test_bfs(self):\n",
|
" def test_bfs(self):\n",
|
||||||
" node = Node(5)\n",
|
" node = Node(5)\n",
|
||||||
" insert(node, 2)\n",
|
" insert(node, 2)\n",
|
||||||
" insert(node, 8)\n",
|
" insert(node, 8)\n",
|
||||||
" insert(node, 1)\n",
|
" insert(node, 1)\n",
|
||||||
" insert(node, 3)\n",
|
" insert(node, 3)\n",
|
||||||
"\n",
|
" bfs(node, self.results.add_result)\n",
|
||||||
" with captured_output() as (out, err):\n",
|
" assert_equal(str(self.results), '[5, 2, 8, 1, 3]')\n",
|
||||||
" bfs(node, sys.stdout.write)\n",
|
|
||||||
" assert_equal(out.getvalue().strip(), '52813')\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
" print('Success: test_bfs')\n",
|
" print('Success: test_bfs')\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
from __future__ import print_function
|
|
||||||
from nose.tools import assert_equal
|
from nose.tools import assert_equal
|
||||||
|
|
||||||
|
|
||||||
class TestBfs(object):
|
class TestBfs(object):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.results = Results()
|
||||||
|
|
||||||
def test_bfs(self):
|
def test_bfs(self):
|
||||||
node = Node(5)
|
node = Node(5)
|
||||||
insert(node, 2)
|
insert(node, 2)
|
||||||
insert(node, 8)
|
insert(node, 8)
|
||||||
insert(node, 1)
|
insert(node, 1)
|
||||||
insert(node, 3)
|
insert(node, 3)
|
||||||
|
bfs(node, self.results.add_result)
|
||||||
with captured_output() as (out, err):
|
assert_equal(str(self.results), '[5, 2, 8, 1, 3]')
|
||||||
bfs(node, sys.stdout.write)
|
|
||||||
assert_equal(out.getvalue().strip(), '52813')
|
|
||||||
|
|
||||||
print('Success: test_bfs')
|
print('Success: test_bfs')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user