def test_can_compress_after_decompress(self): s = RLEString('iwillbecompressed') s.compress() s.decompress() try: s.compress() except Exception: self.fail('Unable to compress after decompress')
def test_str(self): rle = RLEString.RLEString("Hello") self.assertEqual(rle.__str__(), "Hello")
def test_iscompressed_after_decompress_false(self): rle = RLEString.RLEString("Hello") rle.compress() rle.decompress() self.assertFalse(rle.iscompressed())
def test_iscompressed_false(self): rle = RLEString.RLEString("Hello") self.assertFalse(rle.iscompressed())
def test_iscompressed_true(self): rle = RLEString.RLEString("Hello") rle.compress() self.assertTrue(rle.iscompressed())
def test_decompressed_correctly(self): rle = RLEString.RLEString("Hello") hello_decompressed = "Hello" rle.compress() rle.decompress() self.assertEqual(rle.__str__(), hello_decompressed)
def test_already_decompressed(self): rle = RLEString.RLEString("Hello") #print(rle.compress()) with self.assertRaises(Exception): rle.decompress()
def test_decompresses_correctly(self): for string in ALPHABETIC: s = RLEString(string) s.compress() s.decompress() self.assertEqual(str(s), string)
def test_compresses_correctly(self): for string, comp in zip(ALPHABETIC, COMPRESSED): s = RLEString(string) s.compress() self.assertEqual(str(s), comp)
def test_cannot_decompress_when_uncompressed(self): s = RLEString('iamverycompressed') with self.assertRaises(Exception): s.decompress()
def test_cannot_compress_twice(self): s = RLEString('hellllotherre') s.compress() with self.assertRaises(Exception): s.compress()
def test_iscompressed_after_compress(self): s = RLEString('abcddd') s.compress() self.assertTrue(s.iscompressed())
def test_raises_if_nonalphabetic(self): for s in NONALPHABETIC: with self.assertRaises(Exception): RLEString(s)
def test_throws_exception_if_empty(self): with self.assertRaises(Exception): RLEString('')