def test_isDeompressed(self): ''' Test if the compress function updates iscompressed() properly ''' for test in succeed_tests: rle = RLEString(test) rle.compress() rle.decompress() result = rle.iscompressed() self.assertFalse(result)
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)
def test_doubleDecompress(self): ''' Test if the compress function handles double-decompress ''' for test in succeed_tests: with self.assertRaises(Exception): rle = RLEString(test) rle.compress() rle.decompress() rle.decompress()
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() except Exception as e: print(e) pass