def test_isCompressed(self): ''' Test if the compress function updates iscompressed() properly ''' for test in succeed_tests: rle = RLEString(test) rle.compress() result = rle.iscompressed() self.assertTrue(result)
def test_doubleCompress(self): ''' Test if the compress function handles double-compress ''' for test in succeed_tests: with self.assertRaises(Exception): rle = RLEString(test) rle.compress() rle.compress()
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)
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)
# NOTE: Change the import below to reflect your filename 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()