mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-10 11:28:03 +00:00
@@ -100,20 +100,24 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from nose.tools import assert_equal\n",
|
||||
"import unittest\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class UnitTest(unittest.TestCase):\n",
|
||||
"\n",
|
||||
"class UnitTest (object):\n",
|
||||
" def testReverseWords(self, func):\n",
|
||||
" assert_equal(func('the sun is hot'), 'eht nus si toh')\n",
|
||||
" assert_equal(func(''), None)\n",
|
||||
" assert_equal(func('123 456 789'), '321 654 987')\n",
|
||||
" assert_equal(func('magic'), 'cigam')\n",
|
||||
" self.assertEqual(func('the sun is hot'), 'eht nus si toh')\n",
|
||||
" self.assertEqual(func(''), None)\n",
|
||||
" self.assertEqual(func('123 456 789'), '321 654 987')\n",
|
||||
" self.assertEqual(func('magic'), 'cigam')\n",
|
||||
" print('Success: reverse_words')\n",
|
||||
" \n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def main():\n",
|
||||
" test = UnitTest()\n",
|
||||
" test.testReverseWords(reverse_words)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"if __name__==\"__main__\":\n",
|
||||
" main()"
|
||||
]
|
||||
@@ -129,23 +133,23 @@
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 2",
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python2"
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 2.0
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython2",
|
||||
"version": "2.7.10"
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.7.2"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 0
|
||||
"nbformat_minor": 1
|
||||
}
|
||||
|
||||
@@ -66,29 +66,25 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def reverse_words(S):\n",
|
||||
" if len(S) is 0:\n",
|
||||
" return None\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" words = S.split()\n",
|
||||
" for i in range (len(words)):\n",
|
||||
" words[i] = words[i][::-1]\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" return \" \".join(words)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
@@ -100,30 +96,32 @@
|
||||
],
|
||||
"source": [
|
||||
"%%writefile reverse_words_solution.py\n",
|
||||
"from nose.tools import assert_equal\n",
|
||||
"import unittest\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestReverseWords(unittest.TestCase):\n",
|
||||
"\n",
|
||||
"class UnitTest (object):\n",
|
||||
" def testReverseWords(self, func):\n",
|
||||
" assert_equal(func('the sun is hot'), 'eht nus si toh')\n",
|
||||
" assert_equal(func(''), None)\n",
|
||||
" assert_equal(func('123 456 789'), '321 654 987')\n",
|
||||
" assert_equal(func('magic'), 'cigam')\n",
|
||||
" self.assertEqual(func('the sun is hot'), 'eht nus si toh')\n",
|
||||
" self.assertEqual(func(''), None)\n",
|
||||
" self.assertEqual(func('123 456 789'), '321 654 987')\n",
|
||||
" self.assertEqual(func('magic'), 'cigam')\n",
|
||||
" print('Success: reverse_words')\n",
|
||||
" \n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def main():\n",
|
||||
" test = UnitTest()\n",
|
||||
" test = TestReverseWords()\n",
|
||||
" test.testReverseWords(reverse_words)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"if __name__==\"__main__\":\n",
|
||||
" main()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
@@ -140,23 +138,23 @@
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 2",
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python2"
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 2
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython2",
|
||||
"version": "2.7.6"
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.7.2"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 0
|
||||
"nbformat_minor": 1
|
||||
}
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
from nose.tools import assert_equal
|
||||
import unittest
|
||||
|
||||
|
||||
class TestReverseWords(unittest.TestCase):
|
||||
|
||||
class UnitTest (object):
|
||||
def testReverseWords(self, func):
|
||||
assert_equal(func('the sun is hot'), 'eht nus si toh')
|
||||
assert_equal(func(''), None)
|
||||
assert_equal(func('123 456 789'), '321 654 987')
|
||||
assert_equal(func('magic'), 'cigam')
|
||||
self.assertEqual(func('the sun is hot'), 'eht nus si toh')
|
||||
self.assertEqual(func(''), None)
|
||||
self.assertEqual(func('123 456 789'), '321 654 987')
|
||||
self.assertEqual(func('magic'), 'cigam')
|
||||
print('Success: reverse_words')
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
test = UnitTest()
|
||||
test = TestReverseWords()
|
||||
test.testReverseWords(reverse_words)
|
||||
|
||||
|
||||
if __name__=="__main__":
|
||||
main()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user