     },
     "outputs": [],
     "source": [
      "def fib_iterative(n):\n",
      "        a = 0        \n",
      "        b = 1\n",
      "        for _ in xrange(n):\n",
      "            a, b = b, a + b\n",
      "        return a\n",
      "\n",
      "for i in xrange(num_items):\n",
      "    print(fib_iterative(i))"
     ]
    }
 
</s> remove     "for i in xrange(num_items):\n",
    "    print(fib_iterative(i))"
 </s> add     "if __name__ == '__main__':\n",
    "    test = Test()\n",
    "    test.test_fib(fib_recursive)\n",
    "    test.test_fib(fib_dynamic)\n",
    "    test.test_fib(fib_iterative)" </s> remove     "        return fib_recursive(n-1) + fib_recursive(n-2)\n",
    "\n",
    "for i in xrange(num_items):\n",
    "    print(fib_recursive(i))"
 </s> add     "        return fib_recursive(n-1) + fib_recursive(n-2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Code: Dynamic" </s> remove     "    return cache[n]\n",
    "\n",
    "for i in xrange(num_items):\n",
    "    print(fib_dynamic(i))"
 </s> add     "    return cache[n]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Code: Iterative" </s> remove     "## Code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "num_items = 10"
 </s> add     "## Code: Recursive"
    "    a = 0        \n",
    "    b = 1\n",
    "    for _ in xrange(n):\n",
    "        a, b = b, a + b\n",
    "    return a"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Unit Test\n",
    "\n",
    "*It is important to identify and run through general and edge cases from the [Test Cases](#Test-Cases) section by hand.  You generally will not be asked to write a unit test like what is shown below.*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Success: test_fib\n",
      "Success: test_fib\n",
      "Success: test_fib\n"
     ]
    }
   ],
   "source": [
    "from nose.tools import assert_equal\n",
    "\n",
    "class Test(object):\n",
    "    def test_fib(self, func):\n",
    "        result = []\n",
    "        for i in xrange(num_items):\n",
    "            result.append(func(i))\n",
    "        fib_seq = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]\n",
    "        assert_equal(result, fib_seq)\n",
    "        print('Success: test_fib')\n",
     },
     "outputs": [],
     "source": [
      "def fib_iterative(n):\n",
    "    a = 0        \n",
    "    b = 1\n",
    "    for _ in xrange(n):\n",
    "        a, b = b, a + b\n",
    "    return a"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Unit Test\n",
    "\n",
    "*It is important to identify and run through general and edge cases from the [Test Cases](#Test-Cases) section by hand.  You generally will not be asked to write a unit test like what is shown below.*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Success: test_fib\n",
      "Success: test_fib\n",
      "Success: test_fib\n"
     ]
    }
   ],
   "source": [
    "from nose.tools import assert_equal\n",
    "\n",
    "class Test(object):\n",
    "    def test_fib(self, func):\n",
    "        result = []\n",
    "        for i in xrange(num_items):\n",
    "            result.append(func(i))\n",
    "        fib_seq = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]\n",
    "        assert_equal(result, fib_seq)\n",
    "        print('Success: test_fib')\n",
    "    a = 0        \n",
    "    b = 1\n",
    "    for _ in xrange(n):\n",
    "        a, b = b, a + b\n",
    "    return a"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Unit Test\n",
    "\n",
    "*It is important to identify and run through general and edge cases from the [Test Cases](#Test-Cases) section by hand.  You generally will not be asked to write a unit test like what is shown below.*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Success: test_fib\n",
      "Success: test_fib\n",
      "Success: test_fib\n"
     ]
    }
   ],
   "source": [
    "from nose.tools import assert_equal\n",
    "\n",
    "class Test(object):\n",
    "    def test_fib(self, func):\n",
    "        result = []\n",
    "        for i in xrange(num_items):\n",
    "            result.append(func(i))\n",
    "        fib_seq = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]\n",
    "        assert_equal(result, fib_seq)\n",
    "        print('Success: test_fib')\n",
    "    a = 0        \n",
    "    b = 1\n",
    "    for _ in xrange(n):\n",
    "        a, b = b, a + b\n",
    "    return a"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Unit Test\n",
    "\n",
    "*It is important to identify and run through general and edge cases from the [Test Cases](#Test-Cases) section by hand.  You generally will not be asked to write a unit test like what is shown below.*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Success: test_fib\n",
      "Success: test_fib\n",
      "Success: test_fib\n"
     ]
    }
   ],
   "source": [
    "from nose.tools import assert_equal\n",
    "\n",
    "class Test(object):\n",
    "    def test_fib(self, func):\n",
    "        result = []\n",
    "        for i in xrange(num_items):\n",
    "            result.append(func(i))\n",
    "        fib_seq = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]\n",
    "        assert_equal(result, fib_seq)\n",
    "        print('Success: test_fib')\n",
    "    a = 0        \n",
    "    b = 1\n",
    "    for _ in xrange(n):\n",
    "        a, b = b, a + b\n",
    "    return a"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Unit Test\n",
    "\n",
    "*It is important to identify and run through general and edge cases from the [Test Cases](#Test-Cases) section by hand.  You generally will not be asked to write a unit test like what is shown below.*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Success: test_fib\n",
      "Success: test_fib\n",
      "Success: test_fib\n"
     ]
    }
   ],
   "source": [
    "from nose.tools import assert_equal\n",
    "\n",
    "class Test(object):\n",
    "    def test_fib(self, func):\n",
    "        result = []\n",
    "        for i in xrange(num_items):\n",
    "            result.append(func(i))\n",
    "        fib_seq = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]\n",
    "        assert_equal(result, fib_seq)\n",
    "        print('Success: test_fib')\n",
    "    a = 0        \n",
    "    b = 1\n",
    "    for _ in xrange(n):\n",
    "        a, b = b, a + b\n",
    "    return a"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Unit Test\n",
    "\n",
    "*It is important to identify and run through general and edge cases from the [Test Cases](#Test-Cases) section by hand.  You generally will not be asked to write a unit test like what is shown below.*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Success: test_fib\n",
      "Success: test_fib\n",
      "Success: test_fib\n"
     ]
    }
   ],
   "source": [
    "from nose.tools import assert_equal\n",
    "\n",
    "class Test(object):\n",
    "    def test_fib(self, func):\n",
    "        result = []\n",
    "        for i in xrange(num_items):\n",
    "            result.append(func(i))\n",
    "        fib_seq = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]\n",
    "        assert_equal(result, fib_seq)\n",
    "        print('Success: test_fib')\n",
      "\n",
      "for i in xrange(num_items):\n",
      "    print(fib_iterative(i))"
     ]
    }
keep keep keep keep replace replace replace replace replace keep keep keep keep keep
 Reworked notebook: Added more detail to constraints and test cases.  Reworked code and unit test. 
recursion-dynamic/fibonacci.ipynb