     "metadata": {},
     "source": [
      "## Test Cases\n",
      "\n",
      "* NULL\n",
      "* '' -> ''\n",
      "* 'ABC' -> 'ABC'\n",
      "* 'AAABCCDDDD' -> 'A3B1C2D4'"
     ]
 
</s> remove   {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from nose.tools import assert_equal\n",
    "\n",
    "class Test(object):\n",
    "    def test_compress(self, func):\n",
    "        assert_equal(func(None), None)\n",
    "        assert_equal(func(''), '')\n",
    "        assert_equal(func('ABC'), 'ABC')\n",
    "        assert_equal(func('AAABCCDDDD'), 'A3B1C2D4')\n",
    "\n",
    "def run_tests(func):\n",
    "    test = Test()\n",
    "    test.test_compress(func)"
   ]
  },
 </s> add  </s> remove     "* [Code: Byte array](#Code:-Byte-Array)"
 </s> add     "* [Code: Byte array](#Code:-Byte-Array)\n",
    "* [Unit Test](#Unit-Test)" </s> remove     "* Is the string ASCII (extended)?  Or Unicode?\n",
    "    * ASCII extended, which is 256 characters\n",
 </s> add     "*Problem statements are sometimes intentionally ambiguous.  Asking clarifying questions, identifying constraints, and stating assumptions help to ensure you code the intended solution.*\n",
    "\n",
    "* Can I assume the string is ASCII?\n",
    "    * Yes\n",
    "    * Note: Unicode strings could require special handling depending on your language\n", </s> remove     "![alt text](https://raw.githubusercontent.com/donnemartin/algorithms-data-structures/master/images/compress_string.jpg)\n",
 </s> add     "Since Python strings are immutable, we'll use a list of characters instead to exercise in-place string manipulation as you would get with a C string (which is null terminated, as seen in the diagram below).  Python does not use a null-terminator.\n", </s> remove     "    compressed_string[pos + 1] = ord(str(count))\n",
    "    return compressed_string\n",
 </s> add     "    compressed_string[pos+1] = ord(str(count))\n",
    "    return compressed_string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Unit Test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Success: test_compress\n",
      "Success: test_compress\n"
     ]
    }
   ],
   "source": [
    "from nose.tools import assert_equal\n",
    "*Identifying and running through general and edge cases are important.  You generally will not be asked to write a unit test like what is shown below.*\n",
    "\n",
     "metadata": {},
     "source": [
      "## Test Cases\n",
      "\n",
    "*Identifying and running through general and edge cases are important.  You generally will not be asked to write a unit test like what is shown below.*\n",
    "\n",
      "* NULL\n",
      "* '' -> ''\n",
      "* 'ABC' -> 'ABC'\n",
      "* 'AAABCCDDDD' -> 'A3B1C2D4'"
     ]
keep keep keep add keep keep keep keep keep
 Reworked notebook: Added more detail to clarifying questions and test cases.  Reworked algorithm discussion, code, and unit test. 
arrays-strings/compress.ipynb