Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions arrays_strings/compress/compress_challenge.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class CompressString(object):\n",
Expand Down Expand Up @@ -107,24 +105,22 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# %load test_compress.py\n",
"from nose.tools import assert_equal\n",
"import unittest\n",
"\n",
"\n",
"class TestCompress(object):\n",
"class TestCompress(unittest.TestCase):\n",
"\n",
" def test_compress(self, func):\n",
" assert_equal(func(None), None)\n",
" assert_equal(func(''), '')\n",
" assert_equal(func('AABBCC'), 'AABBCC')\n",
" assert_equal(func('AAABCCDDDDE'), 'A3BC2D4E')\n",
" assert_equal(func('BAAACCDDDD'), 'BA3C2D4')\n",
" assert_equal(func('AAABAACCDDDD'), 'A3BA2C2D4')\n",
" self.assertEqual(func(None), None)\n",
" self.assertEqual(func(''), '')\n",
" self.assertEqual(func('AABBCC'), 'AABBCC')\n",
" self.assertEqual(func('AAABCCDDDDE'), 'A3BC2D4E')\n",
" self.assertEqual(func('BAAACCDDDD'), 'BA3C2D4')\n",
" self.assertEqual(func('AAABAACCDDDD'), 'A3BA2C2D4')\n",
" print('Success: test_compress')\n",
"\n",
"\n",
Expand Down Expand Up @@ -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
}
32 changes: 13 additions & 19 deletions arrays_strings/compress/compress_solution.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class CompressString(object):\n",
Expand Down Expand Up @@ -129,9 +127,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand All @@ -143,18 +139,18 @@
],
"source": [
"%%writefile test_compress.py\n",
"from nose.tools import assert_equal\n",
"import unittest\n",
"\n",
"\n",
"class TestCompress(object):\n",
"class TestCompress(unittest.TestCase):\n",
"\n",
" def test_compress(self, func):\n",
" assert_equal(func(None), None)\n",
" assert_equal(func(''), '')\n",
" assert_equal(func('AABBCC'), 'AABBCC')\n",
" assert_equal(func('AAABCCDDDDE'), 'A3BC2D4E')\n",
" assert_equal(func('BAAACCDDDD'), 'BA3C2D4')\n",
" assert_equal(func('AAABAACCDDDD'), 'A3BA2C2D4')\n",
" self.assertEqual(func(None), None)\n",
" self.assertEqual(func(''), '')\n",
" self.assertEqual(func('AABBCC'), 'AABBCC')\n",
" self.assertEqual(func('AAABCCDDDDE'), 'A3BC2D4E')\n",
" self.assertEqual(func('BAAACCDDDD'), 'BA3C2D4')\n",
" self.assertEqual(func('AAABAACCDDDD'), 'A3BA2C2D4')\n",
" print('Success: test_compress')\n",
"\n",
"\n",
Expand All @@ -171,9 +167,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand Down Expand Up @@ -204,9 +198,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
}
17 changes: 8 additions & 9 deletions arrays_strings/compress/test_compress.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
from nose.tools import assert_equal
import unittest


class TestCompress(object):
class TestCompress(unittest.TestCase):

def test_compress(self, func):
assert_equal(func(None), None)
assert_equal(func(''), '')
assert_equal(func('ABC'), 'ABC')
assert_equal(func('AABBCC'), 'AABBCC')
assert_equal(func('AAABCCDDDDE'), 'A3BC2D4E')
assert_equal(func('BAAACCDDDD'), 'BA3C2D4')
assert_equal(func('AAABAACCDDDD'), 'A3BA2C2D4')
self.assertEqual(func(None), None)
self.assertEqual(func(''), '')
self.assertEqual(func('AABBCC'), 'AABBCC')
self.assertEqual(func('AAABCCDDDDE'), 'A3BC2D4E')
self.assertEqual(func('BAAACCDDDD'), 'BA3C2D4')
self.assertEqual(func('AAABAACCDDDD'), 'A3BA2C2D4')
print('Success: test_compress')


Expand Down
28 changes: 14 additions & 14 deletions arrays_strings/compress_alt/better_compress_challenge.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"def compress_string(string):\n",
Expand All @@ -105,22 +103,24 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# %load test_compress.py\n",
"from nose.tools import assert_equal\n",
"import unittest\n",
"\n",
"\n",
"class TestCompress(object):\n",
"class TestCompress(unittest.TestCase):\n",
"\n",
" def test_compress(self, func):\n",
" assert_equal(func(None), None)\n",
" assert_equal(func(''), '')\n",
" assert_equal(func('AABBCC'), 'AABBCC')\n",
" assert_equal(func('AAABCCDDDD'), 'A3BCCD4')\n",
" self.assertEqual(func(None), None)\n",
" self.assertEqual(func(''), '')\n",
" self.assertEqual(func('AABBCC'), 'AABBCC')\n",
" self.assertEqual(func('AAABCCDDDD'), 'A3BCCD4')\n",
" self.assertEqual(\n",
" func('aaBCCEFFFFKKMMMMMMP taaammanlaarrrr seeeeeeeeek tooo'),\n",
" 'aaBCCEF4KKM6P ta3mmanlaar4 se9k to3',\n",
" )\n",
" print('Success: test_compress')\n",
"\n",
"\n",
Expand Down Expand Up @@ -159,9 +159,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
}
67 changes: 39 additions & 28 deletions arrays_strings/compress_alt/better_compress_solution.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook was prepared by [hashhar](https://github.com/hashhar), second solution added by [janhak] (https://github.com/janhak). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
"This notebook was prepared by [hashhar](https://github.com/hashhar), second solution added by [janhak](https://github.com/janhak). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
]
},
{
Expand Down Expand Up @@ -103,10 +103,8 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"def compress_string(string):\n",
Expand Down Expand Up @@ -200,10 +198,8 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"def split_to_blocks(string):\n",
Expand Down Expand Up @@ -239,24 +235,33 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting test_compress.py\n"
]
}
],
"source": [
"%%writefile test_compress.py\n",
"from nose.tools import assert_equal\n",
"import unittest\n",
"\n",
"\n",
"class TestCompress(object):\n",
"class TestCompress(unittest.TestCase):\n",
"\n",
" def test_compress(self, func):\n",
" assert_equal(func(None), None)\n",
" assert_equal(func(''), '')\n",
" assert_equal(func('AABBCC'), 'AABBCC')\n",
" assert_equal(func('AAABCCDDDD'), 'A3BCCD4')\n",
" assert_equal(func('aaBCCEFFFFKKMMMMMMP taaammanlaarrrr seeeeeeeeek tooo'), 'aaBCCEF4KKM6P ta3mmanlaar4 se9k to3')\n",
" self.assertEqual(func(None), None)\n",
" self.assertEqual(func(''), '')\n",
" self.assertEqual(func('AABBCC'), 'AABBCC')\n",
" self.assertEqual(func('AAABCCDDDD'), 'A3BCCD4')\n",
" self.assertEqual(\n",
" func('aaBCCEFFFFKKMMMMMMP taaammanlaarrrr seeeeeeeeek tooo'),\n",
" 'aaBCCEF4KKM6P ta3mmanlaar4 se9k to3',\n",
" )\n",
" print('Success: test_compress')\n",
"\n",
"\n",
Expand All @@ -271,11 +276,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Success: test_compress\n"
]
}
],
"source": [
"%run -i test_compress.py"
]
Expand All @@ -297,9 +308,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
}
19 changes: 11 additions & 8 deletions arrays_strings/compress_alt/test_compress.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
from nose.tools import assert_equal
import unittest


class TestCompress(object):
class TestCompress(unittest.TestCase):

def test_compress(self, func):
assert_equal(func(None), None)
assert_equal(func(''), '')
assert_equal(func('AABBCC'), 'AABBCC')
assert_equal(func('AAABCCDDDD'), 'A3BCCD4')
assert_equal(func('aaBCCEFFFFKKMMMMMMP taaammanlaarrrr seeeeeeeeek tooo'), 'aaBCCEF4KKM6P ta3mmanlaar4 se9k to3')
self.assertEqual(func(None), None)
self.assertEqual(func(''), '')
self.assertEqual(func('AABBCC'), 'AABBCC')
self.assertEqual(func('AAABCCDDDD'), 'A3BCCD4')
self.assertEqual(
func('aaBCCEFFFFKKMMMMMMP taaammanlaarrrr seeeeeeeeek tooo'),
'aaBCCEF4KKM6P ta3mmanlaar4 se9k to3',
)
print('Success: test_compress')


Expand All @@ -18,4 +21,4 @@ def main():


if __name__ == '__main__':
main()
main()
Loading