      "collapsed": false
     },
     "outputs": [],
     "source": [
      "# Test find\n",
      "# Find in an empty list\n",
      "linked_list = LinkedList(None)\n",
      "node = linked_list.find('a')\n",
      "print(node)\n",
      "# Find a NULL\n",
      "head = Node(10)\n",
      "linked_list = LinkedList(head)\n",
      "node = linked_list.find(None)\n",
      "print(node)\n",
      "# Find in a list with one element or more matching elements\n",
      "head = Node(10)\n",
      "linked_list = LinkedList(head)\n",
      "linked_list.insert_to_front('a')\n",
      "linked_list.insert_to_front('bc')\n",
      "node = linked_list.find('a')\n",
      "print(node)\n",
      "# Find in a list with no matches\n",
      "node = linked_list.find('aaa')\n",
      "print(node)"
     ]
    },
    {
     "cell_type": "code",
     "execution_count": null,
 
</s> remove     "# Test delete\n",
    "# Delete in an empty list\n",
    "linked_list = LinkedList(None)\n",
    "linked_list.delete('a')\n",
    "linked_list.print_list()\n",
    "# Delete a NULL\n",
    "head = Node(10)\n",
    "linked_list = LinkedList(head)\n",
    "linked_list.delete(None)\n",
    "linked_list.print_list()\n",
    "# Delete in a list with one element or more matching elements\n",
    "head = Node(10)\n",
    "linked_list = LinkedList(head)\n",
    "linked_list.insert_to_front('a')\n",
    "linked_list.insert_to_front('bc')\n",
    "linked_list.delete('a')\n",
    "linked_list.print_list()\n",
    "# Delete in a list with no matches\n",
    "linked_list.delete('aa')"
 </s> add     "## Unit Test" </s> remove     "            curr_node = curr_node.next"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "%run linked_list.py"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Test insert_to_front\n",
    "# Insert in an empty list\n",
    "linked_list = LinkedList(None)\n",
    "linked_list.insert_to_front(10)\n",
    "linked_list.print_list()\n",
    "# Insert a NULL\n",
    "linked_list.insert_to_front(None)\n",
    "linked_list.print_list()\n",
    "# Insert in a list with one element or more elements\n",
    "linked_list.insert_to_front('a')\n",
    "linked_list.insert_to_front('bc')\n",
    "linked_list.print_list()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Test append\n",
    "# Insert in an empty list\n",
    "linked_list = LinkedList(None)\n",
    "linked_list.append(10)\n",
    "linked_list.print_list()\n",
    "# Insert a NULL\n",
    "linked_list.append(None)\n",
    "linked_list.print_list()\n",
    "# Insert in a list with one element or more elements\n",
    "linked_list.append('a')\n",
    "linked_list.append('bc')\n",
    "linked_list.print_list()"
 </s> add     "            curr_node = curr_node.next\n",
    "\n",
    "    def get_all_data(self):\n",
    "        data = []\n",
    "        curr_node = self.head\n",
    "        while curr_node is not None:\n",
    "            data.append(curr_node.data)\n",
    "            curr_node = curr_node.next\n",
    "        return data" </s> remove     "# Test length\n",
    "# Zero elements\n",
    "linked_list = LinkedList(None)\n",
    "print(len(linked_list))\n",
    "# One or more elements\n",
    "head = Node(10)\n",
    "linked_list = LinkedList(head)\n",
    "linked_list.insert_to_front('a')\n",
    "linked_list.insert_to_front('bc')\n",
    "print(len(linked_list))"
 </s> add     "*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.*" </s> remove    "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
 </s> add    "cell_type": "markdown",
   "metadata": {}, </s> remove     "# Test empty print\n",
    "linked_list = LinkedList(None)\n",
    "linked_list.print_list()"
 </s> add     "from nose.tools import assert_equal\n",
    "\n",
    "class Test(object):\n",
    "    def test_insert_to_front(self):\n",
    "        print('Test: insert_to_front on an empty list')\n",
    "        linked_list = LinkedList(None)\n",
    "        linked_list.insert_to_front(10)\n",
    "        assert_equal(linked_list.get_all_data(), [10])\n",
    "\n",
    "        print('Test: insert_to_front on a NULL')\n",
    "        linked_list.insert_to_front(None)\n",
    "        assert_equal(linked_list.get_all_data(), [10])\n",
    "\n",
    "        print('Test: insert_to_front general case')\n",
    "        linked_list.insert_to_front('a')\n",
    "        linked_list.insert_to_front('bc')\n",
    "        assert_equal(linked_list.get_all_data(), ['bc', 'a', 10])\n",
    "        \n",
    "        print('Success: test_insert_to_front\\n')\n",
    "        \n",
    "    def test_append(self):\n",
    "        print('Test: append on an empty list')\n",
    "        linked_list = LinkedList(None)\n",
    "        linked_list.append(10)\n",
    "        assert_equal(linked_list.get_all_data(), [10])\n",
    "\n",
    "        print('Test: append a NULL')\n",
    "        linked_list.append(None)\n",
    "        assert_equal(linked_list.get_all_data(), [10])\n",
    "\n",
    "        print('Test: append general case')\n",
    "        linked_list.append('a')\n",
    "        linked_list.append('bc')\n",
    "        assert_equal(linked_list.get_all_data(), [10, 'a', 'bc'])\n",
    "        \n",
    "        print('Success: test_append\\n')\n",
    "        \n",
    "    def test_find(self):\n",
    "        print('Test: find on an empty list')\n",
    "        linked_list = LinkedList(None)\n",
    "        node = linked_list.find('a')\n",
    "        assert_equal(node, None)\n",
    "\n",
    "        print('Test: find a NULL')\n",
    "        head = Node(10)\n",
    "        linked_list = LinkedList(head)\n",
    "        node = linked_list.find(None)\n",
    "        assert_equal(node, None)\n",
    "\n",
    "        print('Test: find general case with matches')\n",
    "        head = Node(10)\n",
    "        linked_list = LinkedList(head)\n",
    "        linked_list.insert_to_front('a')\n",
    "        linked_list.insert_to_front('bc')\n",
    "        node = linked_list.find('a')\n",
    "        assert_equal(str(node), 'a')\n",
    "\n",
    "        print('Test: find general case with no matches')\n",
    "        node = linked_list.find('aaa')\n",
    "        assert_equal(node, None)\n",
    "        \n",
    "        print('Success: test_find\\n')\n",
    "        \n",
    "    def test_delete(self):\n",
    "        print('Test: delete on an empty list')\n",
    "        linked_list = LinkedList(None)\n",
    "        linked_list.delete('a')\n",
    "        assert_equal(linked_list.get_all_data(), [])\n",
    "\n",
    "        print('Test: delete a NULL')\n",
    "        head = Node(10)\n",
    "        linked_list = LinkedList(head)\n",
    "        linked_list.delete(None)\n",
    "        assert_equal(linked_list.get_all_data(), [10])\n",
    "\n",
    "        print('Test: delete general case with matches')\n",
    "        head = Node(10)\n",
    "        linked_list = LinkedList(head)\n",
    "        linked_list.insert_to_front('a')\n",
    "        linked_list.insert_to_front('bc')\n",
    "        linked_list.delete('a')\n",
    "        assert_equal(linked_list.get_all_data(), ['bc', 10])\n",
    "\n",
    "        print('Test: delete general case with no matches')\n",
    "        linked_list.delete('aa')\n",
    "        assert_equal(linked_list.get_all_data(), ['bc', 10])\n",
    "        \n",
    "        print('Success: test_delete\\n')\n",
    "        \n",
    "    def test_len(self):\n",
    "        print('Test: len on an empty list')\n",
    "        linked_list = LinkedList(None)\n",
    "        assert_equal(len(linked_list), 0)\n",
    "\n",
    "        print('Test: len general case')\n",
    "        head = Node(10)\n",
    "        linked_list = LinkedList(head)\n",
    "        linked_list.insert_to_front('a')\n",
    "        linked_list.insert_to_front('bc')\n",
    "        assert_equal(len(linked_list), 3)\n",
    "        \n",
    "        print('Success: test_len\\n')\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    test = Test()\n",
    "    test.test_insert_to_front()\n",
    "    test.test_append()\n",
    "    test.test_find()\n",
    "    test.test_delete()\n",
    "    test.test_len()"
    "%run linked_list.py"
      "collapsed": false
     },
     "outputs": [],
     "source": [
    "%run linked_list.py"
    "%run linked_list.py"
    "%run linked_list.py"
    "%run linked_list.py"
    "%run linked_list.py"
    "%run linked_list.py"
    "%run linked_list.py"
    "%run linked_list.py"
    "%run linked_list.py"
    "%run linked_list.py"
    "%run linked_list.py"
    "%run linked_list.py"
    "%run linked_list.py"
    "%run linked_list.py"
    "%run linked_list.py"
    "%run linked_list.py"
    "%run linked_list.py"
    "%run linked_list.py"
    "%run linked_list.py"
    "%run linked_list.py"
     ]
    },
    {
     "cell_type": "code",
     "execution_count": null,
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
 Reworked notebook: Added more detail to constraints and test cases.  Reworked algorithm discussion, code, and unit test. 
linked-lists/linked-list.ipynb