mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
a88f0a0b0b
* Add two more test cases for string compress coding challenge. I believe that the existing test cases are not strict enough to assure a proper solution for this challenge. I was able to implement a wrong, but still passing solution to this basing on set and collections.Counter mechanism, since the test cases present only situations with singular occurrences of a letter chain and all the test strings are alphabetically sorted. I believe that the two new test cases enforce more thorough approach to the problem and, in effect, the test cases are more descriptive. * Fix the results in tests since the solution changed in the meantine on original branch. * Update also the test_compress and solution.
23 lines
592 B
Python
23 lines
592 B
Python
from nose.tools import assert_equal
|
|
|
|
|
|
class TestCompress(object):
|
|
|
|
def test_compress(self, func):
|
|
assert_equal(func(None), None)
|
|
assert_equal(func(''), '')
|
|
assert_equal(func('AABBCC'), 'AABBCC')
|
|
assert_equal(func('AAABCCDDDDE'), 'A3BC2D4E')
|
|
assert_equal(func('BAAACCDDDD'), 'BA3C2D4')
|
|
assert_equal(func('AAABAACCDDDD'), 'A3BA2C2D4')
|
|
print('Success: test_compress')
|
|
|
|
|
|
def main():
|
|
test = TestCompress()
|
|
compress_string = CompressString()
|
|
test.test_compress(compress_string.compress)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main() |