Sha256: 72a61d1f3b1a1f4cb3cd4f5903244ec4bd41f87cbeb7e826c42744df5cd7301c

Contents?: true

Size: 1.9 KB

Versions: 135

Compression:

Stored size: 1.9 KB

Contents

import unittest

from run_length_encoding import encode, decode


# test cases adapted from `x-common//canonical-data.json` @ version: 1.0.0

class WordCountTests(unittest.TestCase):
    def test_encode_empty_string(self):
        self.assertMultiLineEqual(encode(''), '')

    def test_encode_single_characters_only_are_encoded_without_count(self):
        self.assertMultiLineEqual(encode('XYZ'), 'XYZ')

    def test_encode_string_with_no_single_characters(self):
        self.assertMultiLineEqual(encode('AABBBCCCC'), '2A3B4C')

    def test_encode_single_characters_mixed_with_repeated_characters(self):
        self.assertMultiLineEqual(
            encode('WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB'),
            '12WB12W3B24WB')

    def test_encode_multiple_whitespace_mixed_in_string(self):
        self.assertMultiLineEqual(encode('  hsqq qww  '), '2 hs2q q2w2 ')

    def test_encode_lowercase_characters(self):
        self.assertMultiLineEqual(encode('aabbbcccc'), '2a3b4c')

    def test_decode_empty_string(self):
        self.assertMultiLineEqual(decode(''), '')

    def test_decode_single_characters_only(self):
        self.assertMultiLineEqual(decode('XYZ'), 'XYZ')

    def test_decode_string_with_no_single_characters(self):
        self.assertMultiLineEqual(decode('2A3B4C'), 'AABBBCCCC')

    def test_decode_single_characters_with_repeated_characters(self):
        self.assertMultiLineEqual(
            decode('12WB12W3B24WB'),
            'WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB')

    def test_decode_multiple_whitespace_mixed_in_string(self):
        self.assertMultiLineEqual(decode('2 hs2q q2w2 '), '  hsqq qww  ')

    def test_decode_lower_case_string(self):
        self.assertMultiLineEqual(decode('2a3b4c'), 'aabbbcccc')

    def test_combination(self):
        self.assertMultiLineEqual(decode(encode('zzz ZZ  zZ')), 'zzz ZZ  zZ')


if __name__ == '__main__':
    unittest.main()

Version data entries

135 entries across 135 versions & 1 rubygems

Version Path
trackler-2.2.1.45 tracks/python/exercises/run-length-encoding/run_length_encoding_test.py
trackler-2.2.1.44 tracks/python/exercises/run-length-encoding/run_length_encoding_test.py
trackler-2.2.1.43 tracks/python/exercises/run-length-encoding/run_length_encoding_test.py
trackler-2.2.1.42 tracks/python/exercises/run-length-encoding/run_length_encoding_test.py
trackler-2.2.1.41 tracks/python/exercises/run-length-encoding/run_length_encoding_test.py
trackler-2.2.1.40 tracks/python/exercises/run-length-encoding/run_length_encoding_test.py
trackler-2.2.1.39 tracks/python/exercises/run-length-encoding/run_length_encoding_test.py
trackler-2.2.1.38 tracks/python/exercises/run-length-encoding/run_length_encoding_test.py
trackler-2.2.1.37 tracks/python/exercises/run-length-encoding/run_length_encoding_test.py
trackler-2.2.1.36 tracks/python/exercises/run-length-encoding/run_length_encoding_test.py
trackler-2.2.1.35 tracks/python/exercises/run-length-encoding/run_length_encoding_test.py
trackler-2.2.1.34 tracks/python/exercises/run-length-encoding/run_length_encoding_test.py
trackler-2.2.1.33 tracks/python/exercises/run-length-encoding/run_length_encoding_test.py
trackler-2.2.1.32 tracks/python/exercises/run-length-encoding/run_length_encoding_test.py
trackler-2.2.1.31 tracks/python/exercises/run-length-encoding/run_length_encoding_test.py
trackler-2.2.1.30 tracks/python/exercises/run-length-encoding/run_length_encoding_test.py
trackler-2.2.1.29 tracks/python/exercises/run-length-encoding/run_length_encoding_test.py
trackler-2.2.1.28 tracks/python/exercises/run-length-encoding/run_length_encoding_test.py
trackler-2.2.1.27 tracks/python/exercises/run-length-encoding/run_length_encoding_test.py
trackler-2.2.1.26 tracks/python/exercises/run-length-encoding/run_length_encoding_test.py