mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-02 23:48:02 +00:00
@@ -76,9 +76,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"class Solution(object):\n",
|
"class Solution(object):\n",
|
||||||
@@ -105,24 +103,22 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# %load test_add_digits.py\n",
|
"# %load test_add_digits.py\n",
|
||||||
"from nose.tools import assert_equal, assert_raises\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestAddDigits(object):\n",
|
"class TestAddDigits(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_add_digits(self, func):\n",
|
" def test_add_digits(self, func):\n",
|
||||||
" assert_raises(TypeError, func, None)\n",
|
" self.assertRaises(TypeError, func, None)\n",
|
||||||
" assert_raises(ValueError, func, -1)\n",
|
" self.assertRaises(ValueError, func, -1)\n",
|
||||||
" assert_equal(func(0), 0)\n",
|
" self.assertEqual(func(0), 0)\n",
|
||||||
" assert_equal(func(9), 9)\n",
|
" self.assertEqual(func(9), 9)\n",
|
||||||
" assert_equal(func(138), 3)\n",
|
" self.assertEqual(func(138), 3)\n",
|
||||||
" assert_equal(func(65536), 7) \n",
|
" self.assertEqual(func(65536), 7) \n",
|
||||||
" print('Success: test_add_digits')\n",
|
" print('Success: test_add_digits')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -168,9 +164,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.0"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
"nbformat_minor": 0
|
"nbformat_minor": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,9 +89,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 1,
|
"execution_count": 1,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"class Solution(object):\n",
|
"class Solution(object):\n",
|
||||||
@@ -134,9 +132,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 2,
|
"execution_count": 2,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -148,18 +144,18 @@
|
|||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"%%writefile test_add_digits.py\n",
|
"%%writefile test_add_digits.py\n",
|
||||||
"from nose.tools import assert_equal, assert_raises\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestAddDigits(object):\n",
|
"class TestAddDigits(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_add_digits(self, func):\n",
|
" def test_add_digits(self, func):\n",
|
||||||
" assert_raises(TypeError, func, None)\n",
|
" self.assertRaises(TypeError, func, None)\n",
|
||||||
" assert_raises(ValueError, func, -1)\n",
|
" self.assertRaises(ValueError, func, -1)\n",
|
||||||
" assert_equal(func(0), 0)\n",
|
" self.assertEqual(func(0), 0)\n",
|
||||||
" assert_equal(func(9), 9)\n",
|
" self.assertEqual(func(9), 9)\n",
|
||||||
" assert_equal(func(138), 3)\n",
|
" self.assertEqual(func(138), 3)\n",
|
||||||
" assert_equal(func(65536), 7) \n",
|
" self.assertEqual(func(65536), 7) \n",
|
||||||
" print('Success: test_add_digits')\n",
|
" print('Success: test_add_digits')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -182,9 +178,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": 3,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -216,9 +210,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.4.3"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
"nbformat_minor": 0
|
"nbformat_minor": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
from nose.tools import assert_equal, assert_raises
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
class TestAddDigits(object):
|
class TestAddDigits(unittest.TestCase):
|
||||||
|
|
||||||
def test_add_digits(self, func):
|
def test_add_digits(self, func):
|
||||||
assert_raises(TypeError, func, None)
|
self.assertRaises(TypeError, func, None)
|
||||||
assert_raises(ValueError, func, -1)
|
self.assertRaises(ValueError, func, -1)
|
||||||
assert_equal(func(0), 0)
|
self.assertEqual(func(0), 0)
|
||||||
assert_equal(func(9), 9)
|
self.assertEqual(func(9), 9)
|
||||||
assert_equal(func(138), 3)
|
self.assertEqual(func(138), 3)
|
||||||
assert_equal(func(65536), 7)
|
self.assertEqual(func(65536), 7)
|
||||||
print('Success: test_add_digits')
|
print('Success: test_add_digits')
|
||||||
|
|
||||||
|
|
||||||
@@ -26,4 +26,4 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -73,9 +73,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"class Math(object):\n",
|
"class Math(object):\n",
|
||||||
@@ -102,24 +100,22 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# %load test_check_prime.py\n",
|
"# %load test_check_prime.py\n",
|
||||||
"from nose.tools import assert_equal, assert_raises\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestMath(object):\n",
|
"class TestMath(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_check_prime(self):\n",
|
" def test_check_prime(self):\n",
|
||||||
" math = Math()\n",
|
" math = Math()\n",
|
||||||
" assert_raises(TypeError, math.check_prime, None)\n",
|
" self.assertRaises(TypeError, math.check_prime, None)\n",
|
||||||
" assert_raises(TypeError, math.check_prime, 98.6)\n",
|
" self.assertRaises(TypeError, math.check_prime, 98.6)\n",
|
||||||
" assert_equal(math.check_prime(0), False)\n",
|
" self.assertEqual(math.check_prime(0), False)\n",
|
||||||
" assert_equal(math.check_prime(1), False)\n",
|
" self.assertEqual(math.check_prime(1), False)\n",
|
||||||
" assert_equal(math.check_prime(97), True)\n",
|
" self.assertEqual(math.check_prime(97), True)\n",
|
||||||
" print('Success: test_check_prime')\n",
|
" print('Success: test_check_prime')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -158,9 +154,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.0"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
"nbformat_minor": 0
|
"nbformat_minor": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,9 +84,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 1,
|
"execution_count": 1,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"import math\n",
|
"import math\n",
|
||||||
@@ -125,9 +123,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 2,
|
"execution_count": 2,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -139,18 +135,18 @@
|
|||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"%%writefile test_check_prime.py\n",
|
"%%writefile test_check_prime.py\n",
|
||||||
"from nose.tools import assert_equal, assert_raises\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestMath(object):\n",
|
"class TestMath(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_check_prime(self):\n",
|
" def test_check_prime(self):\n",
|
||||||
" math = Math()\n",
|
" math = Math()\n",
|
||||||
" assert_raises(TypeError, math.check_prime, None)\n",
|
" self.assertRaises(TypeError, math.check_prime, None)\n",
|
||||||
" assert_raises(TypeError, math.check_prime, 98.6)\n",
|
" self.assertRaises(TypeError, math.check_prime, 98.6)\n",
|
||||||
" assert_equal(math.check_prime(0), False)\n",
|
" self.assertEqual(math.check_prime(0), False)\n",
|
||||||
" assert_equal(math.check_prime(1), False)\n",
|
" self.assertEqual(math.check_prime(1), False)\n",
|
||||||
" assert_equal(math.check_prime(97), True)\n",
|
" self.assertEqual(math.check_prime(97), True)\n",
|
||||||
" print('Success: test_check_prime')\n",
|
" print('Success: test_check_prime')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -166,9 +162,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": 3,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -199,9 +193,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.0"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
"nbformat_minor": 0
|
"nbformat_minor": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
from nose.tools import assert_equal, assert_raises
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
class TestMath(object):
|
class TestMath(unittest.TestCase):
|
||||||
|
|
||||||
def test_check_prime(self):
|
def test_check_prime(self):
|
||||||
math = Math()
|
math = Math()
|
||||||
assert_raises(TypeError, math.check_prime, None)
|
self.assertRaises(TypeError, math.check_prime, None)
|
||||||
assert_raises(TypeError, math.check_prime, 98.6)
|
self.assertRaises(TypeError, math.check_prime, 98.6)
|
||||||
assert_equal(math.check_prime(0), False)
|
self.assertEqual(math.check_prime(0), False)
|
||||||
assert_equal(math.check_prime(1), False)
|
self.assertEqual(math.check_prime(1), False)
|
||||||
assert_equal(math.check_prime(97), True)
|
self.assertEqual(math.check_prime(97), True)
|
||||||
print('Success: test_check_prime')
|
print('Success: test_check_prime')
|
||||||
|
|
||||||
|
|
||||||
@@ -19,4 +19,4 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -72,9 +72,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": 3,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"class PrimeGenerator(object):\n",
|
"class PrimeGenerator(object):\n",
|
||||||
@@ -101,22 +99,20 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# %load test_generate_primes.py\n",
|
"# %load test_generate_primes.py\n",
|
||||||
"from nose.tools import assert_equal, assert_raises\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestMath(object):\n",
|
"class TestMath(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_generate_primes(self):\n",
|
" def test_generate_primes(self):\n",
|
||||||
" prime_generator = PrimeGenerator()\n",
|
" prime_generator = PrimeGenerator()\n",
|
||||||
" assert_raises(TypeError, prime_generator.generate_primes, None)\n",
|
" self.assertRaises(TypeError, prime_generator.generate_primes, None)\n",
|
||||||
" assert_raises(TypeError, prime_generator.generate_primes, 98.6)\n",
|
" self.assertRaises(TypeError, prime_generator.generate_primes, 98.6)\n",
|
||||||
" assert_equal(prime_generator.generate_primes(20), [False, False, True, \n",
|
" self.assertEqual(prime_generator.generate_primes(20), [False, False, True, \n",
|
||||||
" True, False, True, \n",
|
" True, False, True, \n",
|
||||||
" False, True, False, \n",
|
" False, True, False, \n",
|
||||||
" False, False, True, \n",
|
" False, False, True, \n",
|
||||||
@@ -161,9 +157,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.0"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
"nbformat_minor": 0
|
"nbformat_minor": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,9 +88,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 1,
|
"execution_count": 1,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"import math\n",
|
"import math\n",
|
||||||
@@ -134,9 +132,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 2,
|
"execution_count": 2,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -148,16 +144,16 @@
|
|||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"%%writefile test_generate_primes.py\n",
|
"%%writefile test_generate_primes.py\n",
|
||||||
"from nose.tools import assert_equal, assert_raises\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestMath(object):\n",
|
"class TestMath(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_generate_primes(self):\n",
|
" def test_generate_primes(self):\n",
|
||||||
" prime_generator = PrimeGenerator()\n",
|
" prime_generator = PrimeGenerator()\n",
|
||||||
" assert_raises(TypeError, prime_generator.generate_primes, None)\n",
|
" self.assertRaises(TypeError, prime_generator.generate_primes, None)\n",
|
||||||
" assert_raises(TypeError, prime_generator.generate_primes, 98.6)\n",
|
" self.assertRaises(TypeError, prime_generator.generate_primes, 98.6)\n",
|
||||||
" assert_equal(prime_generator.generate_primes(20), [False, False, True, \n",
|
" self.assertEqual(prime_generator.generate_primes(20), [False, False, True, \n",
|
||||||
" True, False, True, \n",
|
" True, False, True, \n",
|
||||||
" False, True, False, \n",
|
" False, True, False, \n",
|
||||||
" False, False, True, \n",
|
" False, False, True, \n",
|
||||||
@@ -179,9 +175,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": 3,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -212,9 +206,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.0"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
"nbformat_minor": 0
|
"nbformat_minor": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
from nose.tools import assert_equal, assert_raises
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
class TestMath(object):
|
class TestMath(unittest.TestCase):
|
||||||
|
|
||||||
def test_generate_primes(self):
|
def test_generate_primes(self):
|
||||||
prime_generator = PrimeGenerator()
|
prime_generator = PrimeGenerator()
|
||||||
assert_raises(TypeError, prime_generator.generate_primes, None)
|
self.assertRaises(TypeError, prime_generator.generate_primes, None)
|
||||||
assert_raises(TypeError, prime_generator.generate_primes, 98.6)
|
self.assertRaises(TypeError, prime_generator.generate_primes, 98.6)
|
||||||
assert_equal(prime_generator.generate_primes(20), [False, False, True,
|
self.assertEqual(prime_generator.generate_primes(20), [False, False, True,
|
||||||
True, False, True,
|
True, False, True,
|
||||||
False, True, False,
|
False, True, False,
|
||||||
False, False, True,
|
False, False, True,
|
||||||
@@ -23,4 +23,4 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -82,9 +82,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"class Solution(object):\n",
|
"class Solution(object):\n",
|
||||||
@@ -115,20 +113,18 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# %load test_math_ops.py\n",
|
"# %load test_math_ops.py\n",
|
||||||
"from nose.tools import assert_equal, assert_true, assert_raises\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestMathOps(object):\n",
|
"class TestMathOps(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_math_ops(self):\n",
|
" def test_math_ops(self):\n",
|
||||||
" solution = Solution()\n",
|
" solution = Solution()\n",
|
||||||
" assert_raises(TypeError, solution.insert, None)\n",
|
" self.assertRaises(TypeError, solution.insert, None)\n",
|
||||||
" solution.insert(5)\n",
|
" solution.insert(5)\n",
|
||||||
" solution.insert(2)\n",
|
" solution.insert(2)\n",
|
||||||
" solution.insert(7)\n",
|
" solution.insert(7)\n",
|
||||||
@@ -140,10 +136,10 @@
|
|||||||
" solution.insert(3)\n",
|
" solution.insert(3)\n",
|
||||||
" solution.insert(3)\n",
|
" solution.insert(3)\n",
|
||||||
" solution.insert(2)\n",
|
" solution.insert(2)\n",
|
||||||
" assert_equal(solution.max, 9)\n",
|
" self.assertEqual(solution.max, 9)\n",
|
||||||
" assert_equal(solution.min, 2)\n",
|
" self.assertEqual(solution.min, 2)\n",
|
||||||
" assert_equal(solution.mean, 5)\n",
|
" self.assertEqual(solution.mean, 5)\n",
|
||||||
" assert_true(solution.mode in (2, 9))\n",
|
" self.assertTrue(solution.mode in (2, 9))\n",
|
||||||
" print('Success: test_math_ops')\n",
|
" print('Success: test_math_ops')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -182,9 +178,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.0"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
"nbformat_minor": 0
|
"nbformat_minor": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,9 +93,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 1,
|
"execution_count": 1,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"from __future__ import division\n",
|
"from __future__ import division\n",
|
||||||
@@ -143,9 +141,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 2,
|
"execution_count": 2,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -157,14 +153,14 @@
|
|||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"%%writefile test_math_ops.py\n",
|
"%%writefile test_math_ops.py\n",
|
||||||
"from nose.tools import assert_equal, assert_true, assert_raises\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestMathOps(object):\n",
|
"class TestMathOps(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_math_ops(self):\n",
|
" def test_math_ops(self):\n",
|
||||||
" solution = Solution()\n",
|
" solution = Solution()\n",
|
||||||
" assert_raises(TypeError, solution.insert, None)\n",
|
" self.assertRaises(TypeError, solution.insert, None)\n",
|
||||||
" solution.insert(5)\n",
|
" solution.insert(5)\n",
|
||||||
" solution.insert(2)\n",
|
" solution.insert(2)\n",
|
||||||
" solution.insert(7)\n",
|
" solution.insert(7)\n",
|
||||||
@@ -176,10 +172,10 @@
|
|||||||
" solution.insert(3)\n",
|
" solution.insert(3)\n",
|
||||||
" solution.insert(3)\n",
|
" solution.insert(3)\n",
|
||||||
" solution.insert(2)\n",
|
" solution.insert(2)\n",
|
||||||
" assert_equal(solution.max, 9)\n",
|
" self.assertEqual(solution.max, 9)\n",
|
||||||
" assert_equal(solution.min, 2)\n",
|
" self.assertEqual(solution.min, 2)\n",
|
||||||
" assert_equal(solution.mean, 5)\n",
|
" self.assertEqual(solution.mean, 5)\n",
|
||||||
" assert_true(solution.mode in (2, 9))\n",
|
" self.assertTrue(solution.mode in (2, 9))\n",
|
||||||
" print('Success: test_math_ops')\n",
|
" print('Success: test_math_ops')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -195,9 +191,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": 3,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -228,9 +222,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.0"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
"nbformat_minor": 0
|
"nbformat_minor": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
from nose.tools import assert_equal, assert_true, assert_raises
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
class TestMathOps(object):
|
class TestMathOps(unittest.TestCase):
|
||||||
|
|
||||||
def test_math_ops(self):
|
def test_math_ops(self):
|
||||||
solution = Solution()
|
solution = Solution()
|
||||||
assert_raises(TypeError, solution.insert, None)
|
self.assertRaises(TypeError, solution.insert, None)
|
||||||
solution.insert(5)
|
solution.insert(5)
|
||||||
solution.insert(2)
|
solution.insert(2)
|
||||||
solution.insert(7)
|
solution.insert(7)
|
||||||
@@ -17,10 +17,10 @@ class TestMathOps(object):
|
|||||||
solution.insert(3)
|
solution.insert(3)
|
||||||
solution.insert(3)
|
solution.insert(3)
|
||||||
solution.insert(2)
|
solution.insert(2)
|
||||||
assert_equal(solution.max, 9)
|
self.assertEqual(solution.max, 9)
|
||||||
assert_equal(solution.min, 2)
|
self.assertEqual(solution.min, 2)
|
||||||
assert_equal(solution.mean, 5)
|
self.assertEqual(solution.mean, 5)
|
||||||
assert_true(solution.mode in (2, 9))
|
self.assertTrue(solution.mode in (2, 9))
|
||||||
print('Success: test_math_ops')
|
print('Success: test_math_ops')
|
||||||
|
|
||||||
|
|
||||||
@@ -30,4 +30,4 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -77,9 +77,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"class Solution(object):\n",
|
"class Solution(object):\n",
|
||||||
@@ -106,25 +104,23 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# %load test_is_power_of_two.py\n",
|
"# %load test_is_power_of_two.py\n",
|
||||||
"from nose.tools import assert_equal, assert_raises\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestSolution(object):\n",
|
"class TestSolution(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_is_power_of_two(self):\n",
|
" def test_is_power_of_two(self):\n",
|
||||||
" solution = Solution()\n",
|
" solution = Solution()\n",
|
||||||
" assert_raises(TypeError, solution.is_power_of_two, None)\n",
|
" self.assertRaises(TypeError, solution.is_power_of_two, None)\n",
|
||||||
" assert_equal(solution.is_power_of_two(0), False)\n",
|
" self.assertEqual(solution.is_power_of_two(0), False)\n",
|
||||||
" assert_equal(solution.is_power_of_two(1), True)\n",
|
" self.assertEqual(solution.is_power_of_two(1), True)\n",
|
||||||
" assert_equal(solution.is_power_of_two(2), True)\n",
|
" self.assertEqual(solution.is_power_of_two(2), True)\n",
|
||||||
" assert_equal(solution.is_power_of_two(15), False)\n",
|
" self.assertEqual(solution.is_power_of_two(15), False)\n",
|
||||||
" assert_equal(solution.is_power_of_two(16), True)\n",
|
" self.assertEqual(solution.is_power_of_two(16), True)\n",
|
||||||
" print('Success: test_is_power_of_two')\n",
|
" print('Success: test_is_power_of_two')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -163,9 +159,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.0"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
"nbformat_minor": 0
|
"nbformat_minor": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,9 +98,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 1,
|
"execution_count": 1,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"class Solution(object):\n",
|
"class Solution(object):\n",
|
||||||
@@ -123,9 +121,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 2,
|
"execution_count": 2,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -137,19 +133,19 @@
|
|||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"%%writefile test_is_power_of_two.py\n",
|
"%%writefile test_is_power_of_two.py\n",
|
||||||
"from nose.tools import assert_equal, assert_raises\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestSolution(object):\n",
|
"class TestSolution(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_is_power_of_two(self):\n",
|
" def test_is_power_of_two(self):\n",
|
||||||
" solution = Solution()\n",
|
" solution = Solution()\n",
|
||||||
" assert_raises(TypeError, solution.is_power_of_two, None)\n",
|
" self.assertRaises(TypeError, solution.is_power_of_two, None)\n",
|
||||||
" assert_equal(solution.is_power_of_two(0), False)\n",
|
" self.assertEqual(solution.is_power_of_two(0), False)\n",
|
||||||
" assert_equal(solution.is_power_of_two(1), True)\n",
|
" self.assertEqual(solution.is_power_of_two(1), True)\n",
|
||||||
" assert_equal(solution.is_power_of_two(2), True)\n",
|
" self.assertEqual(solution.is_power_of_two(2), True)\n",
|
||||||
" assert_equal(solution.is_power_of_two(15), False)\n",
|
" self.assertEqual(solution.is_power_of_two(15), False)\n",
|
||||||
" assert_equal(solution.is_power_of_two(16), True)\n",
|
" self.assertEqual(solution.is_power_of_two(16), True)\n",
|
||||||
" print('Success: test_is_power_of_two')\n",
|
" print('Success: test_is_power_of_two')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -165,9 +161,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": 3,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -198,9 +192,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.0"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
"nbformat_minor": 0
|
"nbformat_minor": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
from nose.tools import assert_equal, assert_raises
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
class TestSolution(object):
|
class TestSolution(unittest.TestCase):
|
||||||
|
|
||||||
def test_is_power_of_two(self):
|
def test_is_power_of_two(self):
|
||||||
solution = Solution()
|
solution = Solution()
|
||||||
assert_raises(TypeError, solution.is_power_of_two, None)
|
self.assertRaises(TypeError, solution.is_power_of_two, None)
|
||||||
assert_equal(solution.is_power_of_two(0), False)
|
self.assertEqual(solution.is_power_of_two(0), False)
|
||||||
assert_equal(solution.is_power_of_two(1), True)
|
self.assertEqual(solution.is_power_of_two(1), True)
|
||||||
assert_equal(solution.is_power_of_two(2), True)
|
self.assertEqual(solution.is_power_of_two(2), True)
|
||||||
assert_equal(solution.is_power_of_two(15), False)
|
self.assertEqual(solution.is_power_of_two(15), False)
|
||||||
assert_equal(solution.is_power_of_two(16), True)
|
self.assertEqual(solution.is_power_of_two(16), True)
|
||||||
print('Success: test_is_power_of_two')
|
print('Success: test_is_power_of_two')
|
||||||
|
|
||||||
|
|
||||||
@@ -20,4 +20,4 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -74,9 +74,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"class Solution(object):\n",
|
"class Solution(object):\n",
|
||||||
@@ -103,24 +101,22 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# %load test_sub_two.py\n",
|
"# %load test_sub_two.py\n",
|
||||||
"from nose.tools import assert_equal, assert_raises\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestSubTwo(object):\n",
|
"class TestSubTwo(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_sub_two(self):\n",
|
" def test_sub_two(self):\n",
|
||||||
" solution = Solution()\n",
|
" solution = Solution()\n",
|
||||||
" assert_raises(TypeError, solution.sub_two, None)\n",
|
" self.assertRaises(TypeError, solution.sub_two, None)\n",
|
||||||
" assert_equal(solution.sub_two(7, 5), 2)\n",
|
" self.assertEqual(solution.sub_two(7, 5), 2)\n",
|
||||||
" assert_equal(solution.sub_two(-5, -7), 2)\n",
|
" self.assertEqual(solution.sub_two(-5, -7), 2)\n",
|
||||||
" assert_equal(solution.sub_two(-5, 7), -12)\n",
|
" self.assertEqual(solution.sub_two(-5, 7), -12)\n",
|
||||||
" assert_equal(solution.sub_two(5, -7), 12)\n",
|
" self.assertEqual(solution.sub_two(5, -7), 12)\n",
|
||||||
" print('Success: test_sub_two')\n",
|
" print('Success: test_sub_two')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -159,9 +155,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.0"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
"nbformat_minor": 0
|
"nbformat_minor": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,9 +96,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 1,
|
"execution_count": 1,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"class Solution(object):\n",
|
"class Solution(object):\n",
|
||||||
@@ -123,9 +121,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 2,
|
"execution_count": 2,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -137,18 +133,18 @@
|
|||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"%%writefile test_sub_two.py\n",
|
"%%writefile test_sub_two.py\n",
|
||||||
"from nose.tools import assert_equal, assert_raises\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestSubTwo(object):\n",
|
"class TestSubTwo(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_sub_two(self):\n",
|
" def test_sub_two(self):\n",
|
||||||
" solution = Solution()\n",
|
" solution = Solution()\n",
|
||||||
" assert_raises(TypeError, solution.sub_two, None)\n",
|
" self.assertRaises(TypeError, solution.sub_two, None)\n",
|
||||||
" assert_equal(solution.sub_two(7, 5), 2)\n",
|
" self.assertEqual(solution.sub_two(7, 5), 2)\n",
|
||||||
" assert_equal(solution.sub_two(-5, -7), 2)\n",
|
" self.assertEqual(solution.sub_two(-5, -7), 2)\n",
|
||||||
" assert_equal(solution.sub_two(-5, 7), -12)\n",
|
" self.assertEqual(solution.sub_two(-5, 7), -12)\n",
|
||||||
" assert_equal(solution.sub_two(5, -7), 12)\n",
|
" self.assertEqual(solution.sub_two(5, -7), 12)\n",
|
||||||
" print('Success: test_sub_two')\n",
|
" print('Success: test_sub_two')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -165,7 +161,6 @@
|
|||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": 3,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"collapsed": false,
|
|
||||||
"scrolled": true
|
"scrolled": true
|
||||||
},
|
},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
@@ -198,9 +193,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.0"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
"nbformat_minor": 0
|
"nbformat_minor": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
from nose.tools import assert_equal, assert_raises
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
class TestSubTwo(object):
|
class TestSubTwo(unittest.TestCase):
|
||||||
|
|
||||||
def test_sub_two(self):
|
def test_sub_two(self):
|
||||||
solution = Solution()
|
solution = Solution()
|
||||||
assert_raises(TypeError, solution.sub_two, None)
|
self.assertRaises(TypeError, solution.sub_two, None)
|
||||||
assert_equal(solution.sub_two(7, 5), 2)
|
self.assertEqual(solution.sub_two(7, 5), 2)
|
||||||
assert_equal(solution.sub_two(-5, -7), 2)
|
self.assertEqual(solution.sub_two(-5, -7), 2)
|
||||||
assert_equal(solution.sub_two(-5, 7), -12)
|
self.assertEqual(solution.sub_two(-5, 7), -12)
|
||||||
assert_equal(solution.sub_two(5, -7), 12)
|
self.assertEqual(solution.sub_two(5, -7), 12)
|
||||||
print('Success: test_sub_two')
|
print('Success: test_sub_two')
|
||||||
|
|
||||||
|
|
||||||
@@ -19,4 +19,4 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -68,9 +68,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"class Solution(object):\n",
|
"class Solution(object):\n",
|
||||||
@@ -97,23 +95,21 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# %load test_sum_two.py\n",
|
"# %load test_sum_two.py\n",
|
||||||
"from nose.tools import assert_equal, assert_raises\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestSumTwo(object):\n",
|
"class TestSumTwo(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_sum_two(self):\n",
|
" def test_sum_two(self):\n",
|
||||||
" solution = Solution()\n",
|
" solution = Solution()\n",
|
||||||
" assert_raises(TypeError, solution.sum_two, None)\n",
|
" self.assertRaises(TypeError, solution.sum_two, None)\n",
|
||||||
" assert_equal(solution.sum_two(5, 7), 12)\n",
|
" self.assertEqual(solution.sum_two(5, 7), 12)\n",
|
||||||
" assert_equal(solution.sum_two(-5, -7), -12)\n",
|
" self.assertEqual(solution.sum_two(-5, -7), -12)\n",
|
||||||
" assert_equal(solution.sum_two(5, -7), -2)\n",
|
" self.assertEqual(solution.sum_two(5, -7), -2)\n",
|
||||||
" print('Success: test_sum_two')\n",
|
" print('Success: test_sum_two')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -152,9 +148,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.0"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
"nbformat_minor": 0
|
"nbformat_minor": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,9 +112,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 1,
|
"execution_count": 1,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"class Solution(object):\n",
|
"class Solution(object):\n",
|
||||||
@@ -139,9 +137,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 2,
|
"execution_count": 2,
|
||||||
"metadata": {
|
"metadata": {},
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@@ -153,17 +149,17 @@
|
|||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"%%writefile test_sum_two.py\n",
|
"%%writefile test_sum_two.py\n",
|
||||||
"from nose.tools import assert_equal, assert_raises\n",
|
"import unittest\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class TestSumTwo(object):\n",
|
"class TestSumTwo(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_sum_two(self):\n",
|
" def test_sum_two(self):\n",
|
||||||
" solution = Solution()\n",
|
" solution = Solution()\n",
|
||||||
" assert_raises(TypeError, solution.sum_two, None)\n",
|
" self.assertRaises(TypeError, solution.sum_two, None)\n",
|
||||||
" assert_equal(solution.sum_two(5, 7), 12)\n",
|
" self.assertEqual(solution.sum_two(5, 7), 12)\n",
|
||||||
" assert_equal(solution.sum_two(-5, -7), -12)\n",
|
" self.assertEqual(solution.sum_two(-5, -7), -12)\n",
|
||||||
" assert_equal(solution.sum_two(5, -7), -2)\n",
|
" self.assertEqual(solution.sum_two(5, -7), -2)\n",
|
||||||
" print('Success: test_sum_two')\n",
|
" print('Success: test_sum_two')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -180,7 +176,6 @@
|
|||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": 3,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"collapsed": false,
|
|
||||||
"scrolled": true
|
"scrolled": true
|
||||||
},
|
},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
@@ -213,9 +208,9 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.5.0"
|
"version": "3.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
"nbformat_minor": 0
|
"nbformat_minor": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
from nose.tools import assert_equal, assert_raises
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
class TestSumTwo(object):
|
class TestSumTwo(unittest.TestCase):
|
||||||
|
|
||||||
def test_sum_two(self):
|
def test_sum_two(self):
|
||||||
solution = Solution()
|
solution = Solution()
|
||||||
assert_raises(TypeError, solution.sum_two, None)
|
self.assertRaises(TypeError, solution.sum_two, None)
|
||||||
assert_equal(solution.sum_two(5, 7), 12)
|
self.assertEqual(solution.sum_two(5, 7), 12)
|
||||||
assert_equal(solution.sum_two(-5, -7), -12)
|
self.assertEqual(solution.sum_two(-5, -7), -12)
|
||||||
assert_equal(solution.sum_two(5, -7), -2)
|
self.assertEqual(solution.sum_two(5, -7), -2)
|
||||||
print('Success: test_sum_two')
|
print('Success: test_sum_two')
|
||||||
|
|
||||||
|
|
||||||
@@ -18,4 +18,4 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user