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