mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
Updated unit test to use nose and moved it to Test Case section.
This commit is contained in:
parent
ce757b7d63
commit
cf81f70c1d
|
@ -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)"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
|
Loading…
Reference in New Issue
Block a user