mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
Cleaned up n pairs parentheses solution notebook and unit test.
This commit is contained in:
parent
d35af98522
commit
c868f891e7
|
@ -18,7 +18,7 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Problem: Print all valid combinations of n-pairs of parentheses\n",
|
||||
"## Problem: Print all valid combinations of n-pairs of parentheses.\n",
|
||||
"\n",
|
||||
"* [Constraints](#Constraints)\n",
|
||||
"* [Test Cases](#Test-Cases)\n",
|
||||
|
@ -104,7 +104,7 @@
|
|||
" if n == 0:\n",
|
||||
" return result_set\n",
|
||||
" parentheses_util(n, n, '', result_set)\n",
|
||||
" return result_set\n"
|
||||
" return result_set"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -125,30 +125,57 @@
|
|||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Success: test_pair_parentheses\n"
|
||||
"Overwriting test_n_pairs_parentheses.py\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# %load test_n_pairs_parentheses.py\n",
|
||||
"%%writefile test_n_pairs_parentheses.py\n",
|
||||
"from nose.tools import assert_equal\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestPairParentheses(object):\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" def test_pair_parentheses(self, solution):\n",
|
||||
" assert_equal(solution(0), set([]))\n",
|
||||
" assert_equal(solution(1), set(['()']))\n",
|
||||
" assert_equal(solution(2), set(['(())', '()()']))\n",
|
||||
" assert_equal(solution(3), set(['((()))','(()())', '(())()', '()(())', '()()()']))\n",
|
||||
" assert_equal(solution(2), set(['(())', \n",
|
||||
" '()()']))\n",
|
||||
" assert_equal(solution(3), set(['((()))', \n",
|
||||
" '(()())', \n",
|
||||
" '(())()', \n",
|
||||
" '()(())', \n",
|
||||
" '()()()']))\n",
|
||||
" print('Success: test_pair_parentheses')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def main():\n",
|
||||
" test = TestPairParentheses()\n",
|
||||
" test.test_pair_parentheses(pair_parentheses)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"if __name__ == '__main__':\n",
|
||||
" main()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Success: test_pair_parentheses\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"%run -i test_n_pairs_parentheses.py"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
@ -167,7 +194,7 @@
|
|||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython2",
|
||||
"version": "2.7.9"
|
||||
"version": "2.7.10"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
|
|
@ -1,17 +1,25 @@
|
|||
from nose.tools import assert_equal
|
||||
|
||||
|
||||
class TestPairParentheses(object):
|
||||
|
||||
|
||||
def test_pair_parentheses(self, solution):
|
||||
assert_equal(solution(0), set([]))
|
||||
assert_equal(solution(1), set(['()']))
|
||||
assert_equal(solution(2), set(['(())', '()()']))
|
||||
assert_equal(solution(3), set(['((()))','(()())', '(())()', '()(())', '()()()']))
|
||||
assert_equal(solution(2), set(['(())',
|
||||
'()()']))
|
||||
assert_equal(solution(3), set(['((()))',
|
||||
'(()())',
|
||||
'(())()',
|
||||
'()(())',
|
||||
'()()()']))
|
||||
print('Success: test_pair_parentheses')
|
||||
|
||||
|
||||
def main():
|
||||
test = TestPairParentheses()
|
||||
test.test_pair_parentheses(pair_parentheses)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in New Issue
Block a user