diff --git a/graphs_trees/tree_bfs/bfs_challenge.ipynb b/graphs_trees/tree_bfs/bfs_challenge.ipynb index 467f036..11f78a6 100644 --- a/graphs_trees/tree_bfs/bfs_challenge.ipynb +++ b/graphs_trees/tree_bfs/bfs_challenge.ipynb @@ -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", diff --git a/graphs_trees/tree_bfs/bfs_solution.ipynb b/graphs_trees/tree_bfs/bfs_solution.ipynb index 21cf5e6..46f76f3 100644 --- a/graphs_trees/tree_bfs/bfs_solution.ipynb +++ b/graphs_trees/tree_bfs/bfs_solution.ipynb @@ -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", diff --git a/graphs_trees/tree_bfs/test_bfs.py b/graphs_trees/tree_bfs/test_bfs.py index 6eba107..33ddd10 100644 --- a/graphs_trees/tree_bfs/test_bfs.py +++ b/graphs_trees/tree_bfs/test_bfs.py @@ -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')