Move xor challenge solution to a class (#143)

This commit is contained in:
Donne Martin 2017-02-04 19:07:06 -05:00 committed by GitHub
parent 098aaf196d
commit cf48629858
3 changed files with 31 additions and 24 deletions

View File

@ -72,7 +72,9 @@
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
"def max_xor(lower, upper):\n", "class Solution(object):\n",
"\n",
" def max_xor(self, lower, upper):\n",
" # TODO: Implement me\n", " # TODO: Implement me\n",
" pass" " pass"
] ]
@ -101,7 +103,8 @@
"class TestMaximingXor(object):\n", "class TestMaximingXor(object):\n",
"\n", "\n",
" def test_maximizing_xor(self):\n", " def test_maximizing_xor(self):\n",
" assert_equal(max_xor(10, 15), 7)\n", " solution = Solution()\n",
" assert_equal(solution.max_xor(10, 15), 7)\n",
" print('Success: test_maximizing_xor')\n", " print('Success: test_maximizing_xor')\n",
"\n", "\n",
"\n", "\n",
@ -126,21 +129,21 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Python 2", "display_name": "Python 3",
"language": "python", "language": "python",
"name": "python2" "name": "python3"
}, },
"language_info": { "language_info": {
"codemirror_mode": { "codemirror_mode": {
"name": "ipython", "name": "ipython",
"version": 2 "version": 3
}, },
"file_extension": ".py", "file_extension": ".py",
"mimetype": "text/x-python", "mimetype": "text/x-python",
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython2", "pygments_lexer": "ipython3",
"version": "2.7.10" "version": "3.5.0"
} }
}, },
"nbformat": 4, "nbformat": 4,

View File

@ -82,7 +82,9 @@
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
"def max_xor(lower, upper):\n", "class Solution(object):\n",
"\n",
" def max_xor(self, lower, upper):\n",
" result = 0\n", " result = 0\n",
" for l in range(lower, upper + 1):\n", " for l in range(lower, upper + 1):\n",
" for u in range(lower, upper + 1):\n", " for u in range(lower, upper + 1):\n",
@ -123,7 +125,8 @@
"class TestMaximingXor(object):\n", "class TestMaximingXor(object):\n",
"\n", "\n",
" def test_maximizing_xor(self):\n", " def test_maximizing_xor(self):\n",
" assert_equal(max_xor(10, 15), 7)\n", " solution = Solution()\n",
" assert_equal(solution.max_xor(10, 15), 7)\n",
" print('Success: test_maximizing_xor')\n", " print('Success: test_maximizing_xor')\n",
"\n", "\n",
"\n", "\n",
@ -158,21 +161,21 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Python 2", "display_name": "Python 3",
"language": "python", "language": "python",
"name": "python2" "name": "python3"
}, },
"language_info": { "language_info": {
"codemirror_mode": { "codemirror_mode": {
"name": "ipython", "name": "ipython",
"version": 2 "version": 3
}, },
"file_extension": ".py", "file_extension": ".py",
"mimetype": "text/x-python", "mimetype": "text/x-python",
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython2", "pygments_lexer": "ipython3",
"version": "2.7.10" "version": "3.5.0"
} }
}, },
"nbformat": 4, "nbformat": 4,

View File

@ -4,7 +4,8 @@ from nose.tools import assert_equal
class TestMaximingXor(object): class TestMaximingXor(object):
def test_maximizing_xor(self): def test_maximizing_xor(self):
assert_equal(max_xor(10, 15), 7) solution = Solution()
assert_equal(solution.max_xor(10, 15), 7)
print('Success: test_maximizing_xor') print('Success: test_maximizing_xor')