Exemple #1
0
    def test_compress(self):
        ''' 
            Test if the compress function compresses properly
        '''
        for test in succeed_tests:
            rle = RLEString(test)
            rle.compress()
            result = rle.__str__()
            self.assertNotEqual(result, test)

        for test in fail_tests:
            with self.assertRaises(Exception):
                rle = RLEString(test)
                rle.compress()
                result = rle.__str__()
                self.assertNotEqual(result, test)
Exemple #2
0
 def test_decompress(self):
     ''' 
         Test if the decompress function decompresses properly
     '''
     for test in succeed_tests:
         rle = RLEString(test)
         rle.compress()
         rle.decompress()
         result = rle.__str__()
         self.assertEqual(result, test)
Exemple #3
0
from Assignment_8_RLE import RLEString

if __name__ == '__main__':
    tests = [
        "aaa", "a", "TTTTTeeeesssst", "AAAABBBBCCCCDEFGHIIIIIIJJ",
        "There are more than 3 non-alphabeticals in this one when we count spaces!",
        "abcdefghjiklmno", ""
    ]

    for t in tests:
        try:
            rle = RLEString(t)

            print("Original: %s" % (rle))
            rle.compress()
            compressed = rle.__str__()
            if compressed == t:
                raise Exception("Original string equals compressed!")
                pass

            print("Compressed: %s" % (rle))

            rle.decompress()
            if not rle.__str__() == t:
                raise Exception(
                    "Compression error, expected original after decompress!")

            rle.decompress()
            rle.compress()
            rle.compress()