From cf81f70c1d532391220e5b8c165127b444fbd6f1 Mon Sep 17 00:00:00 2001 From: Donne Martin Date: Sun, 21 Jun 2015 21:45:32 -0400 Subject: [PATCH] Updated unit test to use nose and moved it to Test Case section. --- arrays-strings/permutation.ipynb | 34 +++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/arrays-strings/permutation.ipynb b/arrays-strings/permutation.ipynb index 4e20b35..4a4afb1 100644 --- a/arrays-strings/permutation.ipynb +++ b/arrays-strings/permutation.ipynb @@ -47,6 +47,28 @@ "* 'a ct', 'ca t' -> 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_permutation(self, func):\n", + " assert_equal(func('', 'foo'), False)\n", + " assert_equal(func('Nib', 'bin'), False)\n", + " assert_equal(func('act', 'cat'), True)\n", + " assert_equal(func('a ct', 'ca t'), True)\n", + "\n", + "def run_tests(func):\n", + " test = Test()\n", + " test.test_permutation(func)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -84,10 +106,7 @@ "def permutations(str1, str2):\n", " return sorted(str1) == sorted(str2)\n", "\n", - "print(permutations('', 'foo'))\n", - "print(permutations('Nib', 'bin'))\n", - "print(permutations('act', 'cat'))\n", - "print(permutations('a ct', 'ca t'))" + "run_tests(permutations)" ] }, { @@ -141,17 +160,14 @@ " dict_chars[char] += 1\n", " return dict_chars\n", "\n", - "def permutations(str1, str2):\n", + "def permutations_alt(str1, str2):\n", " if len(str1) != len(str2):\n", " return False\n", " unique_counts1 = unique_counts(str1)\n", " unique_counts2 = unique_counts(str2)\n", " return unique_counts1 == unique_counts2\n", "\n", - "print(permutations('', 'foo'))\n", - "print(permutations('Nib', 'bin'))\n", - "print(permutations('act', 'cat'))\n", - "print(permutations('a ct', 'ca t'))" + "run_tests(permutations_alt)" ] } ],