* Corrected small typos around resistor bands. * Due to failing CI, alterations to the test generator script were needed. The generated vs submitted diff now skips the first three lines of the file so that the generation date is not picked up and flagged as needing regeneration. Sadly, a workaround was also needed to prevent Python difflib from noting the difference anyways and producing an empty "false positive" diff. All templates and test files also needed to be altered to ensure that the first three lines of every test file will always be the autogeneration comment and date. Hopefully, this will now stop the CI failures without creating any subtle additional bugs. * Touch up to bowling template. Added back the error raising utility. * Touch up to two-bucket template to add back in error raising utility. [no important files changed]
58 lines
2.0 KiB
Python
58 lines
2.0 KiB
Python
# These tests are auto-generated with test data from:
|
|
# https://github.com/exercism/problem-specifications/tree/main/exercises/run-length-encoding/canonical-data.json
|
|
# File last updated on 2023-07-19
|
|
|
|
import unittest
|
|
|
|
from run_length_encoding import (
|
|
encode,
|
|
decode,
|
|
)
|
|
|
|
|
|
class RunLengthEncodingTest(unittest.TestCase):
|
|
def test_encode_empty_string(self):
|
|
self.assertMultiLineEqual(encode(""), "")
|
|
|
|
def test_encode_single_characters_only_are_encoded_without_count(self):
|
|
self.assertMultiLineEqual(encode("XYZ"), "XYZ")
|
|
|
|
def test_encode_string_with_no_single_characters(self):
|
|
self.assertMultiLineEqual(encode("AABBBCCCC"), "2A3B4C")
|
|
|
|
def test_encode_single_characters_mixed_with_repeated_characters(self):
|
|
self.assertMultiLineEqual(
|
|
encode("WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB"),
|
|
"12WB12W3B24WB",
|
|
)
|
|
|
|
def test_encode_multiple_whitespace_mixed_in_string(self):
|
|
self.assertMultiLineEqual(encode(" hsqq qww "), "2 hs2q q2w2 ")
|
|
|
|
def test_encode_lowercase_characters(self):
|
|
self.assertMultiLineEqual(encode("aabbbcccc"), "2a3b4c")
|
|
|
|
def test_decode_empty_string(self):
|
|
self.assertMultiLineEqual(decode(""), "")
|
|
|
|
def test_decode_single_characters_only(self):
|
|
self.assertMultiLineEqual(decode("XYZ"), "XYZ")
|
|
|
|
def test_decode_string_with_no_single_characters(self):
|
|
self.assertMultiLineEqual(decode("2A3B4C"), "AABBBCCCC")
|
|
|
|
def test_decode_single_characters_with_repeated_characters(self):
|
|
self.assertMultiLineEqual(
|
|
decode("12WB12W3B24WB"),
|
|
"WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB",
|
|
)
|
|
|
|
def test_decode_multiple_whitespace_mixed_in_string(self):
|
|
self.assertMultiLineEqual(decode("2 hs2q q2w2 "), " hsqq qww ")
|
|
|
|
def test_decode_lowercase_string(self):
|
|
self.assertMultiLineEqual(decode("2a3b4c"), "aabbbcccc")
|
|
|
|
def test_encode_followed_by_decode_gives_original_string(self):
|
|
self.assertMultiLineEqual(decode(encode("zzz ZZ zZ")), "zzz ZZ zZ")
|