diff --git a/arrays-strings/unique_chars.ipynb b/arrays-strings/unique_chars.ipynb index 2af80af..21d5a62 100644 --- a/arrays-strings/unique_chars.ipynb +++ b/arrays-strings/unique_chars.ipynb @@ -45,6 +45,27 @@ "* 'bar' -> True" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "from nose.tools import assert_equal\n", + "\n", + "class Test(object):\n", + " def test_unique_chars(self, func):\n", + " assert_equal(func(''), True)\n", + " assert_equal(func('foo'), False)\n", + " assert_equal(func('bar'), True)\n", + "\n", + "def run_tests(func):\n", + " test = Test()\n", + " test.test_unique_chars(func)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -79,30 +100,9 @@ "outputs": [], "source": [ "def unique_chars(string):\n", - " return len(set(string)) == len(string)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "from nose.tools import assert_equal\n", + " return len(set(string)) == len(string)\n", "\n", - "class Test(object):\n", - " def test_unique_chars(self):\n", - " assert_equal(unique_chars(''), True)\n", - " assert_equal(unique_chars('foo'), False)\n", - " assert_equal(unique_chars('bar'), True) \n", - "\n", - "def run_tests():\n", - " test = Test()\n", - " test.test_unique_chars()\n", - "\n", - "run_tests()" + "run_tests(unique_chars)" ] }, { @@ -144,7 +144,7 @@ }, "outputs": [], "source": [ - "def unique_chars_alt(string):\n", + "def unique_chars_hash(string):\n", " chars_set = set()\n", " for char in string:\n", " if char in chars_set:\n", @@ -153,7 +153,7 @@ " chars_set.add(char)\n", " return True\n", "\n", - "run_tests()" + "run_tests(unique_chars_hash)" ] }, { @@ -190,13 +190,13 @@ }, "outputs": [], "source": [ - "def unique_chars_alt(string):\n", + "def unique_chars_inplace(string):\n", " for char in string:\n", " if string.count(char) > 1:\n", " return False\n", " return True\n", "\n", - "run_tests()" + "run_tests(unique_chars_inplace)" ] } ],