<commit_before><commit_msg>string compressor kata sixth day<commit_after># -*- codeing: utf-8 -*-

class Compressor(object):

    def compress(self, toCompress):
        if toCompress is None:
            return ""
        else:
            result = []
            index = 0
            length = len (toCompress)
            while index < length:
                counter = 1
                index += 1
                while index < length and toCompress[index - 1] == toCompress[index]:
                    counter += 1
                    index += 1
                result.append(str(counter))
                result.append(toCompress[index - 1])
            return ''.join(result)

import unittest

class StringCompressorTest(unittest.TestCase):

    def setUp(self):
        self.compressor = Compressor()

    def test_nothing_is_compressed_to_an_empty_string(self):
        self.assertEqual("", self.compressor.compress(None))

    def test_compresses_a_single_character_string(self):
        self.assertEqual("1a", self.compressor.compress("a"))

    def test_compresses_a_string_of_unique_characters(self):
        self.assertEqual("1a1b1c", self.compressor.compress("abc"))

    def test_compresses_a_string_of_doubled_characters(self):
        self.assertEqual("2a2b2c", self.compressor.compress("aabbcc"))

    def test_compresses_an_empty_string(self):
        self.assertEqual("", self.compressor.compress(""))
{'fraction_non_alphanumeric': 0.10618846694796062, 'fraction_numerical': 0.010548523206751054, 'mean_word_length': 2.4455205811138017, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4202288', 'n_tokens_mistral': 425, 'n_tokens_neox': 397, 'n_words': 75}