diff --git a/bit_manipulation/bit/bit_challenge.ipynb b/bit_manipulation/bit/bit_challenge.ipynb index 85fc5ae..7236150 100644 --- a/bit_manipulation/bit/bit_challenge.ipynb +++ b/bit_manipulation/bit/bit_challenge.ipynb @@ -92,9 +92,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "class Bit(object):\n", @@ -145,40 +143,38 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "# %load test_bit.py\n", - "from nose.tools import assert_equal\n", + "import unittest\n", "\n", "\n", - "class TestBit(object):\n", + "class TestBit(unittest.TestCase):\n", "\n", " def test_bit(self):\n", " number = int('10001110', base=2)\n", " bit = Bit(number)\n", - " assert_equal(bit.get_bit(index=3), True)\n", + " self.assertEqual(bit.get_bit(index=3), True)\n", " expected = int('10011110', base=2)\n", - " assert_equal(bit.set_bit(index=4), expected)\n", + " self.assertEqual(bit.set_bit(index=4), expected)\n", " bit = Bit(number)\n", " expected = int('10000110', base=2)\n", - " assert_equal(bit.clear_bit(index=3), expected)\n", + " self.assertEqual(bit.clear_bit(index=3), expected)\n", " bit = Bit(number)\n", " expected = int('00000110', base=2)\n", - " assert_equal(bit.clear_bits_msb_to_index(index=3), expected)\n", + " self.assertEqual(bit.clear_bits_msb_to_index(index=3), expected)\n", " bit = Bit(number)\n", " expected = int('10000000', base=2)\n", - " assert_equal(bit.clear_bits_index_to_lsb(index=3), expected)\n", + " self.assertEqual(bit.clear_bits_index_to_lsb(index=3), expected)\n", " bit = Bit(number)\n", - " assert_equal(bit.update_bit(index=3, value=1), number)\n", + " self.assertEqual(bit.update_bit(index=3, value=1), number)\n", " bit = Bit(number)\n", " expected = int('10000110', base=2)\n", - " assert_equal(bit.update_bit(index=3, value=0), expected)\n", + " self.assertEqual(bit.update_bit(index=3, value=0), expected)\n", " bit = Bit(number)\n", " expected = int('10001111', base=2)\n", - " assert_equal(bit.update_bit(index=0, value=1), expected)\n", + " self.assertEqual(bit.update_bit(index=0, value=1), expected)\n", " print('Success: test_bit')\n", "\n", "\n", @@ -217,9 +213,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.0" + "version": "3.7.2" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/bit_manipulation/bit/bit_solution.ipynb b/bit_manipulation/bit/bit_solution.ipynb index be72758..dbd80b7 100644 --- a/bit_manipulation/bit/bit_solution.ipynb +++ b/bit_manipulation/bit/bit_solution.ipynb @@ -179,9 +179,7 @@ { "cell_type": "code", "execution_count": 1, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "def validate_index(func):\n", @@ -196,9 +194,7 @@ { "cell_type": "code", "execution_count": 2, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "class Bit(object):\n", @@ -260,9 +256,7 @@ { "cell_type": "code", "execution_count": 3, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -274,34 +268,34 @@ ], "source": [ "%%writefile test_bit.py\n", - "from nose.tools import assert_equal\n", + "import unittest\n", "\n", "\n", - "class TestBit(object):\n", + "class TestBit(unittest.TestCase):\n", "\n", " def test_bit(self):\n", " number = int('10001110', base=2)\n", " bit = Bit(number)\n", - " assert_equal(bit.get_bit(index=3), True)\n", + " self.assertEqual(bit.get_bit(index=3), True)\n", " expected = int('10011110', base=2)\n", - " assert_equal(bit.set_bit(index=4), expected)\n", + " self.assertEqual(bit.set_bit(index=4), expected)\n", " bit = Bit(number)\n", " expected = int('10000110', base=2)\n", - " assert_equal(bit.clear_bit(index=3), expected)\n", + " self.assertEqual(bit.clear_bit(index=3), expected)\n", " bit = Bit(number)\n", " expected = int('00000110', base=2)\n", - " assert_equal(bit.clear_bits_msb_to_index(index=3), expected)\n", + " self.assertEqual(bit.clear_bits_msb_to_index(index=3), expected)\n", " bit = Bit(number)\n", " expected = int('10000000', base=2)\n", - " assert_equal(bit.clear_bits_index_to_lsb(index=3), expected)\n", + " self.assertEqual(bit.clear_bits_index_to_lsb(index=3), expected)\n", " bit = Bit(number)\n", - " assert_equal(bit.update_bit(index=3, value=1), number)\n", + " self.assertEqual(bit.update_bit(index=3, value=1), number)\n", " bit = Bit(number)\n", " expected = int('10000110', base=2)\n", - " assert_equal(bit.update_bit(index=3, value=0), expected)\n", + " self.assertEqual(bit.update_bit(index=3, value=0), expected)\n", " bit = Bit(number)\n", " expected = int('10001111', base=2)\n", - " assert_equal(bit.update_bit(index=0, value=1), expected)\n", + " self.assertEqual(bit.update_bit(index=0, value=1), expected)\n", " print('Success: test_bit')\n", "\n", "\n", @@ -317,9 +311,7 @@ { "cell_type": "code", "execution_count": 4, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -350,9 +342,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.0" + "version": "3.7.2" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/bit_manipulation/bit/test_bit.py b/bit_manipulation/bit/test_bit.py index 2bca822..95835c3 100644 --- a/bit_manipulation/bit/test_bit.py +++ b/bit_manipulation/bit/test_bit.py @@ -1,31 +1,31 @@ -from nose.tools import assert_equal +import unittest -class TestBit(object): +class TestBit(unittest.TestCase): def test_bit(self): number = int('10001110', base=2) bit = Bit(number) - assert_equal(bit.get_bit(index=3), True) + self.assertEqual(bit.get_bit(index=3), True) expected = int('10011110', base=2) - assert_equal(bit.set_bit(index=4), expected) + self.assertEqual(bit.set_bit(index=4), expected) bit = Bit(number) expected = int('10000110', base=2) - assert_equal(bit.clear_bit(index=3), expected) + self.assertEqual(bit.clear_bit(index=3), expected) bit = Bit(number) expected = int('00000110', base=2) - assert_equal(bit.clear_bits_msb_to_index(index=3), expected) + self.assertEqual(bit.clear_bits_msb_to_index(index=3), expected) bit = Bit(number) expected = int('10000000', base=2) - assert_equal(bit.clear_bits_index_to_lsb(index=3), expected) + self.assertEqual(bit.clear_bits_index_to_lsb(index=3), expected) bit = Bit(number) - assert_equal(bit.update_bit(index=3, value=1), number) + self.assertEqual(bit.update_bit(index=3, value=1), number) bit = Bit(number) expected = int('10000110', base=2) - assert_equal(bit.update_bit(index=3, value=0), expected) + self.assertEqual(bit.update_bit(index=3, value=0), expected) bit = Bit(number) expected = int('10001111', base=2) - assert_equal(bit.update_bit(index=0, value=1), expected) + self.assertEqual(bit.update_bit(index=0, value=1), expected) print('Success: test_bit') @@ -35,4 +35,4 @@ def main(): if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/bit_manipulation/bits_to_flip/bits_to_flip_challenge.ipynb b/bit_manipulation/bits_to_flip/bits_to_flip_challenge.ipynb index 29a18e1..20a35b4 100644 --- a/bit_manipulation/bits_to_flip/bits_to_flip_challenge.ipynb +++ b/bit_manipulation/bits_to_flip/bits_to_flip_challenge.ipynb @@ -80,9 +80,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "class Bits(object):\n", @@ -109,23 +107,21 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "# %load test_bits_to_flip.py\n", - "from nose.tools import assert_equal\n", + "import unittest\n", "\n", "\n", - "class TestBits(object):\n", + "class TestBits(unittest.TestCase):\n", "\n", " def test_bits_to_flip(self):\n", " bits = Bits()\n", " a = int('11101', base=2)\n", " b = int('01111', base=2)\n", " expected = 2\n", - " assert_equal(bits.bits_to_flip(a, b), expected)\n", + " self.assertEqual(bits.bits_to_flip(a, b), expected)\n", " print('Success: test_bits_to_flip')\n", "\n", "\n", @@ -164,9 +160,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.0" + "version": "3.7.2" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/bit_manipulation/bits_to_flip/bits_to_flip_solution.ipynb b/bit_manipulation/bits_to_flip/bits_to_flip_solution.ipynb index 87db11d..a709e68 100644 --- a/bit_manipulation/bits_to_flip/bits_to_flip_solution.ipynb +++ b/bit_manipulation/bits_to_flip/bits_to_flip_solution.ipynb @@ -91,9 +91,7 @@ { "cell_type": "code", "execution_count": 1, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "class Bits(object):\n", @@ -119,9 +117,7 @@ { "cell_type": "code", "execution_count": 2, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -133,17 +129,17 @@ ], "source": [ "%%writefile test_bits_to_flip.py\n", - "from nose.tools import assert_equal\n", + "import unittest\n", "\n", "\n", - "class TestBits(object):\n", + "class TestBits(unittest.TestCase):\n", "\n", " def test_bits_to_flip(self):\n", " bits = Bits()\n", " a = int('11101', base=2)\n", " b = int('01111', base=2)\n", " expected = 2\n", - " assert_equal(bits.bits_to_flip(a, b), expected)\n", + " self.assertEqual(bits.bits_to_flip(a, b), expected)\n", " print('Success: test_bits_to_flip')\n", "\n", "\n", @@ -159,9 +155,7 @@ { "cell_type": "code", "execution_count": 3, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -192,9 +186,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.0" + "version": "3.7.2" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/bit_manipulation/bits_to_flip/test_bits_to_flip.py b/bit_manipulation/bits_to_flip/test_bits_to_flip.py index c2bbd0b..a49e196 100644 --- a/bit_manipulation/bits_to_flip/test_bits_to_flip.py +++ b/bit_manipulation/bits_to_flip/test_bits_to_flip.py @@ -1,14 +1,14 @@ -from nose.tools import assert_equal +import unittest -class TestBits(object): +class TestBits(unittest.TestCase): def test_bits_to_flip(self): bits = Bits() a = int('11101', base=2) b = int('01111', base=2) expected = 2 - assert_equal(bits.bits_to_flip(a, b), expected) + self.assertEqual(bits.bits_to_flip(a, b), expected) print('Success: test_bits_to_flip') @@ -18,4 +18,4 @@ def main(): if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/bit_manipulation/draw_line/draw_line_challenge.ipynb b/bit_manipulation/draw_line/draw_line_challenge.ipynb index ed9ce5d..4b8fde9 100644 --- a/bit_manipulation/draw_line/draw_line_challenge.ipynb +++ b/bit_manipulation/draw_line/draw_line_challenge.ipynb @@ -81,9 +81,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "class BitsScreen(object):\n", @@ -110,16 +108,14 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "# %load test_draw_line.py\n", - "from nose.tools import assert_equal\n", + "import unittest\n", "\n", "\n", - "class TestBitsScreen(object):\n", + "class TestBitsScreen(unittest.TestCase):\n", "\n", " def test_draw_line(self):\n", " bits_screen = BitsScreen()\n", @@ -127,13 +123,13 @@ " for _ in range(20):\n", " screen.append(int('00000000', base=2))\n", " bits_screen.draw_line(screen, width=32, x1=68, x2=80)\n", - " assert_equal(screen[8], int('00001111', base=2))\n", - " assert_equal(screen[9], int('11111111', base=2))\n", - " assert_equal(screen[10], int('10000000', base=2))\n", + " self.assertEqual(screen[8], int('00001111', base=2))\n", + " self.assertEqual(screen[9], int('11111111', base=2))\n", + " self.assertEqual(screen[10], int('10000000', base=2))\n", " bits_screen.draw_line(screen, width=32, x1=2, x2=6)\n", - " assert_equal(screen[0], int('00111110', base=2))\n", + " self.assertEqual(screen[0], int('00111110', base=2))\n", " bits_screen.draw_line(screen, width=32, x1=10, x2=13)\n", - " assert_equal(screen[1], int('00111100', base=2))\n", + " self.assertEqual(screen[1], int('00111100', base=2))\n", " print('Success: test_draw_line')\n", "\n", "\n", @@ -172,9 +168,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.0" + "version": "3.7.2" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/bit_manipulation/draw_line/draw_line_solution.ipynb b/bit_manipulation/draw_line/draw_line_solution.ipynb index 798f46f..c84b59f 100644 --- a/bit_manipulation/draw_line/draw_line_solution.ipynb +++ b/bit_manipulation/draw_line/draw_line_solution.ipynb @@ -151,9 +151,7 @@ { "cell_type": "code", "execution_count": 1, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "class BitsScreen(object):\n", @@ -200,9 +198,7 @@ { "cell_type": "code", "execution_count": 2, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -214,10 +210,10 @@ ], "source": [ "%%writefile test_draw_line.py\n", - "from nose.tools import assert_equal\n", + "import unittest\n", "\n", "\n", - "class TestBitsScreen(object):\n", + "class TestBitsScreen(unittest.TestCase):\n", "\n", " def test_draw_line(self):\n", " bits_screen = BitsScreen()\n", @@ -225,13 +221,13 @@ " for _ in range(20):\n", " screen.append(int('00000000', base=2))\n", " bits_screen.draw_line(screen, width=32, x1=68, x2=80)\n", - " assert_equal(screen[8], int('00001111', base=2))\n", - " assert_equal(screen[9], int('11111111', base=2))\n", - " assert_equal(screen[10], int('10000000', base=2))\n", + " self.assertEqual(screen[8], int('00001111', base=2))\n", + " self.assertEqual(screen[9], int('11111111', base=2))\n", + " self.assertEqual(screen[10], int('10000000', base=2))\n", " bits_screen.draw_line(screen, width=32, x1=2, x2=6)\n", - " assert_equal(screen[0], int('00111110', base=2))\n", + " self.assertEqual(screen[0], int('00111110', base=2))\n", " bits_screen.draw_line(screen, width=32, x1=10, x2=13)\n", - " assert_equal(screen[1], int('00111100', base=2))\n", + " self.assertEqual(screen[1], int('00111100', base=2))\n", " print('Success: test_draw_line')\n", "\n", "\n", @@ -247,9 +243,7 @@ { "cell_type": "code", "execution_count": 3, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -280,9 +274,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.4.3" + "version": "3.7.2" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/bit_manipulation/draw_line/test_draw_line.py b/bit_manipulation/draw_line/test_draw_line.py index 69f736d..a60a50d 100644 --- a/bit_manipulation/draw_line/test_draw_line.py +++ b/bit_manipulation/draw_line/test_draw_line.py @@ -1,7 +1,7 @@ -from nose.tools import assert_equal +import unittest -class TestBitsScreen(object): +class TestBitsScreen(unittest.TestCase): def test_draw_line(self): bits_screen = BitsScreen() @@ -9,13 +9,13 @@ class TestBitsScreen(object): for _ in range(20): screen.append(int('00000000', base=2)) bits_screen.draw_line(screen, width=32, x1=68, x2=80) - assert_equal(screen[8], int('00001111', base=2)) - assert_equal(screen[9], int('11111111', base=2)) - assert_equal(screen[10], int('10000000', base=2)) + self.assertEqual(screen[8], int('00001111', base=2)) + self.assertEqual(screen[9], int('11111111', base=2)) + self.assertEqual(screen[10], int('10000000', base=2)) bits_screen.draw_line(screen, width=32, x1=2, x2=6) - assert_equal(screen[0], int('00111110', base=2)) + self.assertEqual(screen[0], int('00111110', base=2)) bits_screen.draw_line(screen, width=32, x1=10, x2=13) - assert_equal(screen[1], int('00111100', base=2)) + self.assertEqual(screen[1], int('00111100', base=2)) print('Success: test_draw_line') @@ -25,4 +25,4 @@ def main(): if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/bit_manipulation/flip_bit/flip_bit_challenge.ipynb b/bit_manipulation/flip_bit/flip_bit_challenge.ipynb index c755106..1ff4cf5 100644 --- a/bit_manipulation/flip_bit/flip_bit_challenge.ipynb +++ b/bit_manipulation/flip_bit/flip_bit_challenge.ipynb @@ -82,9 +82,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "class Bits(object):\n", @@ -111,31 +109,29 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "# %load test_flip_bit.py\n", - "from nose.tools import assert_equal, assert_raises\n", + "import unittest\n", "\n", "\n", - "class TestBits(object):\n", + "class TestBits(unittest.TestCase):\n", "\n", " def test_flip_bit(self):\n", " bits = Bits()\n", - " assert_raises(TypeError, bits.flip_bit, None)\n", - " assert_equal(bits.flip_bit(0), 1)\n", - " assert_equal(bits.flip_bit(-1), bits.MAX_BITS)\n", + " self.assertRaises(TypeError, bits.flip_bit, None)\n", + " self.assertEqual(bits.flip_bit(0), 1)\n", + " self.assertEqual(bits.flip_bit(-1), bits.MAX_BITS)\n", " num = int('00001111110111011110001111110000', base=2)\n", " expected = 10\n", - " assert_equal(bits.flip_bit(num), expected)\n", + " self.assertEqual(bits.flip_bit(num), expected)\n", " num = int('00000100111011101111100011111011', base=2)\n", " expected = 9\n", - " assert_equal(bits.flip_bit(num), expected)\n", + " self.assertEqual(bits.flip_bit(num), expected)\n", " num = int('00010011101110111110001111101111', base=2)\n", " expected = 10\n", - " assert_equal(bits.flip_bit(num), expected)\n", + " self.assertEqual(bits.flip_bit(num), expected)\n", " print('Success: test_print_binary')\n", "\n", "\n", @@ -174,9 +170,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.0" + "version": "3.7.2" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/bit_manipulation/flip_bit/flip_bit_solution.ipynb b/bit_manipulation/flip_bit/flip_bit_solution.ipynb index 6b7889f..9618895 100644 --- a/bit_manipulation/flip_bit/flip_bit_solution.ipynb +++ b/bit_manipulation/flip_bit/flip_bit_solution.ipynb @@ -112,9 +112,7 @@ { "cell_type": "code", "execution_count": 1, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "class Bits(object):\n", @@ -186,9 +184,7 @@ { "cell_type": "code", "execution_count": 2, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -200,25 +196,25 @@ ], "source": [ "%%writefile test_flip_bit.py\n", - "from nose.tools import assert_equal, assert_raises\n", + "import unittest\n", "\n", "\n", - "class TestBits(object):\n", + "class TestBits(unittest.TestCase):\n", "\n", " def test_flip_bit(self):\n", " bits = Bits()\n", - " assert_raises(TypeError, bits.flip_bit, None)\n", - " assert_equal(bits.flip_bit(0), 1)\n", - " assert_equal(bits.flip_bit(-1), bits.MAX_BITS)\n", + " self.assertRaises(TypeError, bits.flip_bit, None)\n", + " self.assertEqual(bits.flip_bit(0), 1)\n", + " self.assertEqual(bits.flip_bit(-1), bits.MAX_BITS)\n", " num = int('00001111110111011110001111110000', base=2)\n", " expected = 10\n", - " assert_equal(bits.flip_bit(num), expected)\n", + " self.assertEqual(bits.flip_bit(num), expected)\n", " num = int('00000100111011101111100011111011', base=2)\n", " expected = 9\n", - " assert_equal(bits.flip_bit(num), expected)\n", + " self.assertEqual(bits.flip_bit(num), expected)\n", " num = int('00010011101110111110001111101111', base=2)\n", " expected = 10\n", - " assert_equal(bits.flip_bit(num), expected)\n", + " self.assertEqual(bits.flip_bit(num), expected)\n", " print('Success: test_print_binary')\n", "\n", "\n", @@ -234,9 +230,7 @@ { "cell_type": "code", "execution_count": 3, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -267,9 +261,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.4.3" + "version": "3.7.2" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/bit_manipulation/flip_bit/test_flip_bit.py b/bit_manipulation/flip_bit/test_flip_bit.py index 6d72d58..2463bf7 100644 --- a/bit_manipulation/flip_bit/test_flip_bit.py +++ b/bit_manipulation/flip_bit/test_flip_bit.py @@ -1,22 +1,22 @@ -from nose.tools import assert_equal, assert_raises +import unittest -class TestBits(object): +class TestBits(unittest.TestCase): def test_flip_bit(self): bits = Bits() - assert_raises(TypeError, bits.flip_bit, None) - assert_equal(bits.flip_bit(0), 1) - assert_equal(bits.flip_bit(-1), bits.MAX_BITS) + self.assertRaises(TypeError, bits.flip_bit, None) + self.assertEqual(bits.flip_bit(0), 1) + self.assertEqual(bits.flip_bit(-1), bits.MAX_BITS) num = int('00001111110111011110001111110000', base=2) expected = 10 - assert_equal(bits.flip_bit(num), expected) + self.assertEqual(bits.flip_bit(num), expected) num = int('00000100111011101111100011111011', base=2) expected = 9 - assert_equal(bits.flip_bit(num), expected) + self.assertEqual(bits.flip_bit(num), expected) num = int('00010011101110111110001111101111', base=2) expected = 10 - assert_equal(bits.flip_bit(num), expected) + self.assertEqual(bits.flip_bit(num), expected) print('Success: test_print_binary') @@ -26,4 +26,4 @@ def main(): if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/bit_manipulation/get_next/get_next_challenge.ipynb b/bit_manipulation/get_next/get_next_challenge.ipynb index 265dafd..b445f9b 100644 --- a/bit_manipulation/get_next/get_next_challenge.ipynb +++ b/bit_manipulation/get_next/get_next_challenge.ipynb @@ -78,9 +78,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "class Bits(object):\n", @@ -111,35 +109,33 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "# %load test_get_next_largest.py\n", - "from nose.tools import assert_equal, assert_raises\n", + "import unittest\n", "\n", "\n", - "class TestBits(object):\n", + "class TestBits(unittest.TestCase):\n", "\n", " def test_get_next_largest(self):\n", " bits = Bits()\n", - " assert_raises(Exception, bits.get_next_largest, None)\n", - " assert_raises(Exception, bits.get_next_largest, 0)\n", - " assert_raises(Exception, bits.get_next_largest, -1)\n", + " self.assertRaises(Exception, bits.get_next_largest, None)\n", + " self.assertRaises(Exception, bits.get_next_largest, 0)\n", + " self.assertRaises(Exception, bits.get_next_largest, -1)\n", " num = int('011010111', base=2)\n", " expected = int('011011011', base=2)\n", - " assert_equal(bits.get_next_largest(num), expected)\n", + " self.assertEqual(bits.get_next_largest(num), expected)\n", " print('Success: test_get_next_largest')\n", "\n", " def test_get_next_smallest(self):\n", " bits = Bits()\n", - " assert_raises(Exception, bits.get_next_smallest, None)\n", - " assert_raises(Exception, bits.get_next_smallest, 0)\n", - " assert_raises(Exception, bits.get_next_smallest, -1)\n", + " self.assertRaises(Exception, bits.get_next_smallest, None)\n", + " self.assertRaises(Exception, bits.get_next_smallest, 0)\n", + " self.assertRaises(Exception, bits.get_next_smallest, -1)\n", " num = int('011010111', base=2)\n", " expected = int('011001111', base=2)\n", - " assert_equal(bits.get_next_smallest(num), expected)\n", + " self.assertEqual(bits.get_next_smallest(num), expected)\n", " print('Success: test_get_next_smallest')\n", "\n", "def main():\n", @@ -178,9 +174,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.0" + "version": "3.7.2" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/bit_manipulation/get_next/get_next_solution.ipynb b/bit_manipulation/get_next/get_next_solution.ipynb index fa87ce3..c414343 100644 --- a/bit_manipulation/get_next/get_next_solution.ipynb +++ b/bit_manipulation/get_next/get_next_solution.ipynb @@ -108,9 +108,7 @@ { "cell_type": "code", "execution_count": 1, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "class Bits(object):\n", @@ -178,9 +176,7 @@ { "cell_type": "code", "execution_count": 2, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -192,29 +188,29 @@ ], "source": [ "%%writefile test_get_next_largest.py\n", - "from nose.tools import assert_equal, assert_raises\n", + "import unittest\n", "\n", "\n", - "class TestBits(object):\n", + "class TestBits(unittest.TestCase):\n", "\n", " def test_get_next_largest(self):\n", " bits = Bits()\n", - " assert_raises(Exception, bits.get_next_largest, None)\n", - " assert_raises(Exception, bits.get_next_largest, 0)\n", - " assert_raises(Exception, bits.get_next_largest, -1)\n", + " self.assertRaises(Exception, bits.get_next_largest, None)\n", + " self.assertRaises(Exception, bits.get_next_largest, 0)\n", + " self.assertRaises(Exception, bits.get_next_largest, -1)\n", " num = int('011010111', base=2)\n", " expected = int('011011011', base=2)\n", - " assert_equal(bits.get_next_largest(num), expected)\n", + " self.assertEqual(bits.get_next_largest(num), expected)\n", " print('Success: test_get_next_largest')\n", "\n", " def test_get_next_smallest(self):\n", " bits = Bits()\n", - " assert_raises(Exception, bits.get_next_smallest, None)\n", - " assert_raises(Exception, bits.get_next_smallest, 0)\n", - " assert_raises(Exception, bits.get_next_smallest, -1)\n", + " self.assertRaises(Exception, bits.get_next_smallest, None)\n", + " self.assertRaises(Exception, bits.get_next_smallest, 0)\n", + " self.assertRaises(Exception, bits.get_next_smallest, -1)\n", " num = int('011010111', base=2)\n", " expected = int('011001111', base=2)\n", - " assert_equal(bits.get_next_smallest(num), expected)\n", + " self.assertEqual(bits.get_next_smallest(num), expected)\n", " print('Success: test_get_next_smallest')\n", "\n", "def main():\n", @@ -230,9 +226,7 @@ { "cell_type": "code", "execution_count": 3, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -264,9 +258,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.4.3" + "version": "3.7.2" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/bit_manipulation/get_next/test_get_next_largest.py b/bit_manipulation/get_next/test_get_next_largest.py index 0fd11e2..c8c35df 100644 --- a/bit_manipulation/get_next/test_get_next_largest.py +++ b/bit_manipulation/get_next/test_get_next_largest.py @@ -1,26 +1,26 @@ -from nose.tools import assert_equal, assert_raises +import unittest -class TestBits(object): +class TestBits(unittest.TestCase): def test_get_next_largest(self): bits = Bits() - assert_raises(Exception, bits.get_next_largest, None) - assert_raises(Exception, bits.get_next_largest, 0) - assert_raises(Exception, bits.get_next_largest, -1) + self.assertRaises(Exception, bits.get_next_largest, None) + self.assertRaises(Exception, bits.get_next_largest, 0) + self.assertRaises(Exception, bits.get_next_largest, -1) num = int('011010111', base=2) expected = int('011011011', base=2) - assert_equal(bits.get_next_largest(num), expected) + self.assertEqual(bits.get_next_largest(num), expected) print('Success: test_get_next_largest') def test_get_next_smallest(self): bits = Bits() - assert_raises(Exception, bits.get_next_smallest, None) - assert_raises(Exception, bits.get_next_smallest, 0) - assert_raises(Exception, bits.get_next_smallest, -1) + self.assertRaises(Exception, bits.get_next_smallest, None) + self.assertRaises(Exception, bits.get_next_smallest, 0) + self.assertRaises(Exception, bits.get_next_smallest, -1) num = int('011010111', base=2) expected = int('011001111', base=2) - assert_equal(bits.get_next_smallest(num), expected) + self.assertEqual(bits.get_next_smallest(num), expected) print('Success: test_get_next_smallest') def main(): @@ -30,4 +30,4 @@ def main(): if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/bit_manipulation/insert_m_into_n/insert_m_into_n_challenge.ipynb b/bit_manipulation/insert_m_into_n/insert_m_into_n_challenge.ipynb index 6d98306..97673a0 100644 --- a/bit_manipulation/insert_m_into_n/insert_m_into_n_challenge.ipynb +++ b/bit_manipulation/insert_m_into_n/insert_m_into_n_challenge.ipynb @@ -81,9 +81,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "class Bits(object):\n", @@ -110,23 +108,21 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "# %load test_insert_m_into_n.py\n", - "from nose.tools import assert_equal\n", + "import unittest\n", "\n", "\n", - "class TestBit(object):\n", + "class TestBit(unittest.TestCase):\n", "\n", " def test_insert_m_into_n(self):\n", " n = int('0000010000111101', base=2)\n", " m = int('0000000000010011', base=2)\n", " expected = int('0000010001001101', base=2)\n", " bits = Bits()\n", - " assert_equal(bits.insert_m_into_n(m, n, i=2, j=6), expected)\n", + " self.assertEqual(bits.insert_m_into_n(m, n, i=2, j=6), expected)\n", " print('Success: test_insert_m_into_n')\n", "\n", "\n", @@ -165,9 +161,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.0" + "version": "3.7.2" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/bit_manipulation/insert_m_into_n/insert_m_into_n_solution.ipynb b/bit_manipulation/insert_m_into_n/insert_m_into_n_solution.ipynb index c65f66a..4ab5512 100644 --- a/bit_manipulation/insert_m_into_n/insert_m_into_n_solution.ipynb +++ b/bit_manipulation/insert_m_into_n/insert_m_into_n_solution.ipynb @@ -108,9 +108,7 @@ { "cell_type": "code", "execution_count": 1, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "class Bits(object):\n", @@ -140,9 +138,7 @@ { "cell_type": "code", "execution_count": 2, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -154,17 +150,17 @@ ], "source": [ "%%writefile test_insert_m_into_n.py\n", - "from nose.tools import assert_equal\n", + "import unittest\n", "\n", "\n", - "class TestBit(object):\n", + "class TestBit(unittest.TestCase):\n", "\n", " def test_insert_m_into_n(self):\n", " n = int('0000010000111101', base=2)\n", " m = int('0000000000010011', base=2)\n", " expected = int('0000010001001101', base=2)\n", " bits = Bits()\n", - " assert_equal(bits.insert_m_into_n(m, n, i=2, j=6), expected)\n", + " self.assertEqual(bits.insert_m_into_n(m, n, i=2, j=6), expected)\n", " print('Success: test_insert_m_into_n')\n", "\n", "\n", @@ -180,9 +176,7 @@ { "cell_type": "code", "execution_count": 3, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -213,9 +207,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.0" + "version": "3.7.2" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/bit_manipulation/insert_m_into_n/test_insert_m_into_n.py b/bit_manipulation/insert_m_into_n/test_insert_m_into_n.py index 4fcc231..1793f30 100644 --- a/bit_manipulation/insert_m_into_n/test_insert_m_into_n.py +++ b/bit_manipulation/insert_m_into_n/test_insert_m_into_n.py @@ -1,14 +1,14 @@ -from nose.tools import assert_equal +import unittest -class TestBit(object): +class TestBit(unittest.TestCase): def test_insert_m_into_n(self): n = int('0000010000111101', base=2) m = int('0000000000010011', base=2) expected = int('0000010001001101', base=2) bits = Bits() - assert_equal(bits.insert_m_into_n(m, n, i=2, j=6), expected) + self.assertEqual(bits.insert_m_into_n(m, n, i=2, j=6), expected) print('Success: test_insert_m_into_n') @@ -18,4 +18,4 @@ def main(): if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/bit_manipulation/pairwise_swap/pairwise_swap_challenge.ipynb b/bit_manipulation/pairwise_swap/pairwise_swap_challenge.ipynb index 6174be8..0de5261 100644 --- a/bit_manipulation/pairwise_swap/pairwise_swap_challenge.ipynb +++ b/bit_manipulation/pairwise_swap/pairwise_swap_challenge.ipynb @@ -81,9 +81,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "class Bits(object):\n", @@ -110,24 +108,22 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "# %load test_pairwise_swap.py\n", - "from nose.tools import assert_equal\n", + "import unittest\n", "\n", "\n", - "class TestBits(object):\n", + "class TestBits(unittest.TestCase):\n", "\n", " def test_pairwise_swap(self):\n", " bits = Bits()\n", - " assert_equal(bits.pairwise_swap(0), 0)\n", - " assert_equal(bits.pairwise_swap(1), 1)\n", + " self.assertEqual(bits.pairwise_swap(0), 0)\n", + " self.assertEqual(bits.pairwise_swap(1), 1)\n", " num = int('0000100111110110', base=2)\n", " expected = int('0000011011111001', base=2)\n", - " assert_equal(bits.pairwise_swap(num), expected)\n", + " self.assertEqual(bits.pairwise_swap(num), expected)\n", " print('Success: test_pairwise_swap')\n", "\n", "\n", @@ -166,9 +162,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.0" + "version": "3.7.2" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/bit_manipulation/pairwise_swap/pairwise_swap_solution.ipynb b/bit_manipulation/pairwise_swap/pairwise_swap_solution.ipynb index 9de5545..b042bff 100644 --- a/bit_manipulation/pairwise_swap/pairwise_swap_solution.ipynb +++ b/bit_manipulation/pairwise_swap/pairwise_swap_solution.ipynb @@ -108,9 +108,7 @@ { "cell_type": "code", "execution_count": 1, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "class Bits(object):\n", @@ -135,9 +133,7 @@ { "cell_type": "code", "execution_count": 2, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -149,19 +145,19 @@ ], "source": [ "%%writefile test_pairwise_swap.py\n", - "from nose.tools import assert_equal, assert_raises\n", + "import unittest\n", "\n", "\n", - "class TestBits(object):\n", + "class TestBits(unittest.TestCase):\n", "\n", " def test_pairwise_swap(self):\n", " bits = Bits()\n", - " assert_equal(bits.pairwise_swap(0), 0)\n", - " assert_equal(bits.pairwise_swap(1), 1)\n", + " self.assertEqual(bits.pairwise_swap(0), 0)\n", + " self.assertEqual(bits.pairwise_swap(1), 1)\n", " num = int('0000100111110110', base=2)\n", " expected = int('0000011011111001', base=2)\n", - " assert_equal(bits.pairwise_swap(num), expected)\n", - " assert_raises(TypeError, bits.pairwise_swap, None)\n", + " self.assertEqual(bits.pairwise_swap(num), expected)\n", + " self.assertRaises(TypeError, bits.pairwise_swap, None)\n", " \n", " print('Success: test_pairwise_swap')\n", "\n", @@ -178,9 +174,7 @@ { "cell_type": "code", "execution_count": 3, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -211,9 +205,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.0" + "version": "3.7.2" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/bit_manipulation/pairwise_swap/test_pairwise_swap.py b/bit_manipulation/pairwise_swap/test_pairwise_swap.py index 5ee4cae..c081502 100644 --- a/bit_manipulation/pairwise_swap/test_pairwise_swap.py +++ b/bit_manipulation/pairwise_swap/test_pairwise_swap.py @@ -1,16 +1,16 @@ -from nose.tools import assert_equal, assert_raises +import unittest -class TestBits(object): +class TestBits(unittest.TestCase): def test_pairwise_swap(self): bits = Bits() - assert_equal(bits.pairwise_swap(0), 0) - assert_equal(bits.pairwise_swap(1), 1) + self.assertEqual(bits.pairwise_swap(0), 0) + self.assertEqual(bits.pairwise_swap(1), 1) num = int('0000100111110110', base=2) expected = int('0000011011111001', base=2) - assert_equal(bits.pairwise_swap(num), expected) - assert_raises(TypeError, bits.pairwise_swap, None) + self.assertEqual(bits.pairwise_swap(num), expected) + self.assertRaises(TypeError, bits.pairwise_swap, None) print('Success: test_pairwise_swap') @@ -21,4 +21,4 @@ def main(): if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/bit_manipulation/print_binary/print_binary_challenge.ipynb b/bit_manipulation/print_binary/print_binary_challenge.ipynb index 8eff2bc..6d64cfb 100644 --- a/bit_manipulation/print_binary/print_binary_challenge.ipynb +++ b/bit_manipulation/print_binary/print_binary_challenge.ipynb @@ -82,9 +82,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "class Bits(object):\n", @@ -111,27 +109,25 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "# %load test_print_binary.py\n", - "from nose.tools import assert_equal\n", + "import unittest\n", "\n", "\n", - "class TestBits(object):\n", + "class TestBits(unittest.TestCase):\n", "\n", " def test_print_binary(self):\n", " bit = Bits()\n", - " assert_equal(bit.print_binary(None), 'ERROR')\n", - " assert_equal(bit.print_binary(0), 'ERROR')\n", - " assert_equal(bit.print_binary(1), 'ERROR')\n", + " self.assertEqual(bit.print_binary(None), 'ERROR')\n", + " self.assertEqual(bit.print_binary(0), 'ERROR')\n", + " self.assertEqual(bit.print_binary(1), 'ERROR')\n", " num = 0.625\n", " expected = '0.101'\n", - " assert_equal(bit.print_binary(num), expected)\n", + " self.assertEqual(bit.print_binary(num), expected)\n", " num = 0.987654321\n", - " assert_equal(bit.print_binary(num), 'ERROR')\n", + " self.assertEqual(bit.print_binary(num), 'ERROR')\n", " print('Success: test_print_binary')\n", "\n", "\n", @@ -170,9 +166,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.0" + "version": "3.7.2" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/bit_manipulation/print_binary/print_binary_solution.ipynb b/bit_manipulation/print_binary/print_binary_solution.ipynb index 9f697a9..bc52472 100644 --- a/bit_manipulation/print_binary/print_binary_solution.ipynb +++ b/bit_manipulation/print_binary/print_binary_solution.ipynb @@ -91,9 +91,7 @@ { "cell_type": "code", "execution_count": 1, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "from __future__ import division\n", @@ -130,9 +128,7 @@ { "cell_type": "code", "execution_count": 2, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -144,21 +140,21 @@ ], "source": [ "%%writefile test_print_binary.py\n", - "from nose.tools import assert_equal\n", + "import unittest\n", "\n", "\n", - "class TestBits(object):\n", + "class TestBits(unittest.TestCase):\n", "\n", " def test_print_binary(self):\n", " bit = Bits()\n", - " assert_equal(bit.print_binary(None), 'ERROR')\n", - " assert_equal(bit.print_binary(0), 'ERROR')\n", - " assert_equal(bit.print_binary(1), 'ERROR')\n", + " self.assertEqual(bit.print_binary(None), 'ERROR')\n", + " self.assertEqual(bit.print_binary(0), 'ERROR')\n", + " self.assertEqual(bit.print_binary(1), 'ERROR')\n", " num = 0.625\n", " expected = '0.101'\n", - " assert_equal(bit.print_binary(num), expected)\n", + " self.assertEqual(bit.print_binary(num), expected)\n", " num = 0.987654321\n", - " assert_equal(bit.print_binary(num), 'ERROR')\n", + " self.assertEqual(bit.print_binary(num), 'ERROR')\n", " print('Success: test_print_binary')\n", "\n", "\n", @@ -174,9 +170,7 @@ { "cell_type": "code", "execution_count": 3, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -207,9 +201,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.0" + "version": "3.7.2" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/bit_manipulation/print_binary/test_print_binary.py b/bit_manipulation/print_binary/test_print_binary.py index e32267b..11945b4 100644 --- a/bit_manipulation/print_binary/test_print_binary.py +++ b/bit_manipulation/print_binary/test_print_binary.py @@ -1,18 +1,18 @@ -from nose.tools import assert_equal +import unittest -class TestBits(object): +class TestBits(unittest.TestCase): def test_print_binary(self): bit = Bits() - assert_equal(bit.print_binary(None), 'ERROR') - assert_equal(bit.print_binary(0), 'ERROR') - assert_equal(bit.print_binary(1), 'ERROR') + self.assertEqual(bit.print_binary(None), 'ERROR') + self.assertEqual(bit.print_binary(0), 'ERROR') + self.assertEqual(bit.print_binary(1), 'ERROR') num = 0.625 expected = '0.101' - assert_equal(bit.print_binary(num), expected) + self.assertEqual(bit.print_binary(num), expected) num = 0.987654321 - assert_equal(bit.print_binary(num), 'ERROR') + self.assertEqual(bit.print_binary(num), 'ERROR') print('Success: test_print_binary') @@ -22,4 +22,4 @@ def main(): if __name__ == '__main__': - main() \ No newline at end of file + main()