     "source": [
      "from random import randint\n",
      "\n",
      "class Test(object):\n",
      "    def get_sorted_stack(self, numbers):\n",
      "        stack = MyStack()\n",
      "        for x in numbers:\n",
      "            stack.push(x)\n",
 
</s> remove     "def test_sort(num_items, stack=None):\n",
    "    if stack is None:\n",
 </s> add     "class Test(object):\n",
    "    def get_sorted_stack(self, numbers):\n", </s> remove     "        for _ in xrange(0, num_items):\n",
    "            stack.push(randint(0, num_items))\n",
    "    sorted_stack = stack.sort()\n",
    "    for _ in xrange(0, num_items):\n",
    "        print(sorted_stack.pop())\n",
    "    return sorted_stack\n",
 </s> add     "        for x in numbers:\n",
    "            stack.push(x)\n",
    "        sorted_stack = stack.sort()\n",
    "        return sorted_stack\n",
    "\n",
    "    def test_sort_stack(self):\n",
    "        print('Test: Empty stack')\n",
    "        sorted_stack = self.get_sorted_stack([])\n",
    "        assert_equal(sorted_stack.pop(), None)\n",
    "\n",
    "        print('Test: One element stack')\n",
    "        sorted_stack = self.get_sorted_stack([1])\n",
    "        assert_equal(sorted_stack.pop(), 1)\n",
    "\n",
    "        print('Test: Two or more element stack (general case)')\n",
    "        num_items = 10\n",
    "        numbers = [randint(0, 10) for x in xrange(num_items)]\n",
    "        sorted_stack = self.get_sorted_stack(numbers)\n",
    "        sorted_numbers = []\n",
    "        for _ in xrange(num_items):\n",
    "            sorted_numbers.append(sorted_stack.pop())\n",
    "        assert_equal(sorted_numbers, sorted(numbers, reverse=True))\n",
    "        \n",
    "        print('Success: test_sort_stack')\n", </s> remove    "outputs": [],
 </s> add    "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Test: Empty stack\n",
      "Test: One element stack\n",
      "Test: Two or more element stack (general case)\n",
      "Success: test_sort_stack\n"
     ]
    }
   ], </s> remove     "print('Empty stack')\n",
    "test_sort(0)\n",
    "print('One element stack')\n",
    "test_sort(1)\n",
    "print('Two or more element stack (general case)')\n",
    "sorted_stack = test_sort(5)"
 </s> add     "if __name__ == '__main__':\n",
    "    test = Test()\n",
    "    test.test_sort_stack()" </s> remove     "* Can you have duplicate values, saw two 5s?\n",
 </s> add     "* Can you have duplicate values like 5, 5?\n",
    "    * Yes\n",
    "* Can we assume we already have a stack class that can be used for this problem?\n",
    "from nose.tools import assert_equal\n",
     "source": [
      "from random import randint\n",
    "from nose.tools import assert_equal\n",
      "\n",
      "class Test(object):\n",
      "    def get_sorted_stack(self, numbers):\n",
      "        stack = MyStack()\n",
      "        for x in numbers:\n",
      "            stack.push(x)\n",
keep add keep keep keep keep keep keep
 Reworked notebook: Added more detail to constraints and test cases.  Reworked unit test. 
stacks-queues/sort-stack.ipynb