public static IList <byte> RLE(IList <byte> bytes) { var rle = new RunLengthEncoding(bytes); var rleResult = rle.Decode(); return(rleResult); }
public void Encode_simple() { const string input = "AABBBCCCC"; const string expected = "2A3B4C"; Assert.That(RunLengthEncoding.Encode(input), Is.EqualTo(expected)); }
public void Decode_unicode() { const string input = "⏰3⚽2⭐⏰"; const string expected = "⏰⚽⚽⚽⭐⭐⏰"; Assert.That(RunLengthEncoding.Decode(input), Is.EqualTo(expected)); }
public void Decode_with_single_values() { const string input = "12WB12W3B24WB"; const string expected = "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB"; Assert.That(RunLengthEncoding.Decode(input), Is.EqualTo(expected)); }
public void Encode_and_then_decode() { const string input = "zzz ZZ zZ"; const string expected = "zzz ZZ zZ"; Assert.That(RunLengthEncoding.Decode(RunLengthEncoding.Encode(input)), Is.EqualTo(expected)); }
public void NewByteRunLengthEncoding() { int length = (int)dataStack.Pop(); RunLengthEncoding <byte> enc = RunLengthEncoding <byte> .Encode(YieldValues <byte>(length)); dataStack.Push(enc); }
public void Encode_with_single_values() { const string input = "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB"; const string expected = "12WB12W3B24WB"; Assert.Equal(expected, RunLengthEncoding.Encode(input)); }
public void DecodingTest(string expected, string input) { var target = new RunLengthEncoding(); string actual = target.Decode(input); Assert.That(actual, Is.EqualTo(expected)); }
public void Encode_unicode() { const string input = "⏰⚽⚽⚽⭐⭐⏰"; const string expected = "⏰3⚽2⭐⏰"; Assert.Equal(expected, RunLengthEncoding.Encode(input)); }
public void NewIntRunLengthEncoding() { int length = (int)dataStack.Pop(); RunLengthEncoding <int> enc = RunLengthEncoding <int> .Encode(YieldValues <int>(length)); dataStack.Push(enc); }
public void Decode_simple() { const string input = "2A3B4C"; const string expected = "AABBBCCCC"; Assert.Equal(expected, RunLengthEncoding.Decode(input)); }
public static int LoadByteRunLengthEncoding(RunLengthEncoding <byte> enc, Stream encoder) { int result = 0; int total = 0; for (int i = enc.Count - 1; i >= 0; i--) { result = LoadByteCell(enc[i], encoder); total += result; } result = LoadInt(enc.Count, encoder); total += result; total += WriteCode((byte)41, encoder); return(total); }
private static void RunLengthEncodingTest() { string input = "AAAABBBCCDAE"; WriteLine("RunLengthEncoding"); string encodedOutput = RunLengthEncoding.Encode(input); WriteLine($"Input : {input} , Encoded : {encodedOutput}"); string decodedOutput = RunLengthEncoding.Decode(encodedOutput); WriteLine($"Input : {input} , Decoded : {decodedOutput}"); WriteLine(input == decodedOutput); }
public void Test() { //Arrange byte[] originalBytes = { 0, 4, 2, 2, 2, 3, 5, 10, 8, 2, 9, 1 }; byte[] expectedExpandedBytes = { 243, 56, 63, 240, 12, 1 }; Stream originalStream = new MemoryStream(originalBytes); MemoryStream expandedStream = new MemoryStream(); //Act RunLengthEncoding.Expand(originalStream, expandedStream); byte[] expandedBytes = expandedStream.ToArray(); originalStream.Dispose(); expandedStream.Dispose(); //Assert Assert.True(expectedExpandedBytes.SequenceEqual(expandedBytes)); }
public void StartsWithZero_Compressed() { //Arrange byte[] originalBytes = { 16, 243, 56, 63, 240, 12, 1 }; byte[] expectedCompressedBytes = { 3, 1, 4, 4, 2, 2, 2, 3, 5, 10, 8, 2, 9, 1 }; Stream originalStream = new MemoryStream(originalBytes); MemoryStream compressedStream = new MemoryStream(); //Act RunLengthEncoding.Compress(originalStream, compressedStream); byte[] compressedBytes = compressedStream.ToArray(); originalStream.Dispose(); compressedStream.Dispose(); //Assert Assert.True(expectedCompressedBytes.SequenceEqual(compressedBytes)); }
public static Histogram[] MakeColorHistogram(RunLengthEncoding <int> i) { Histogram[] grams = new Histogram[4]; var q = (from x in (IEnumerable <RunLengthEncodingEntry <int> >) i let binds = ImageExtensions.Decode32(x.Value) select new { Alpha = binds[0], Red = binds[1], Green = binds[2], Blue = binds[3], }); //alpha grams[0] = new Histogram(from r in q select r.Alpha); grams[1] = new Histogram(from r in q select r.Red); grams[2] = new Histogram(from r in q select r.Green); grams[3] = new Histogram(from r in q select r.Blue); return(grams); }
public void Run_length_encode_a_string_empty_string() { Assert.Equal("", RunLengthEncoding.Encode("")); }
public void Run_length_decode_a_string_multiple_whitespace_mixed_in_string() { Assert.Equal(" hsqq qww ", RunLengthEncoding.Decode("2 hs2q q2w2 ")); }
public void Run_length_decode_a_string_single_characters_with_repeated_characters() { Assert.Equal("WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB", RunLengthEncoding.Decode("12WB12W3B24WB")); }
public void Run_length_decode_a_string_string_with_no_single_characters() { Assert.Equal("AABBBCCCC", RunLengthEncoding.Decode("2A3B4C")); }
public void Run_length_decode_a_string_single_characters_only() { Assert.Equal("XYZ", RunLengthEncoding.Decode("XYZ")); }
public void Run_length_encode_a_string_lowercase_characters() { Assert.Equal("2a3b4c", RunLengthEncoding.Encode("aabbbcccc")); }
public void Encode_empty_string() { Assert.Equal("", RunLengthEncoding.Encode("")); }
public void Encode_multiple_whitespace_mixed_in_string() { Assert.Equal("2 hs2q q2w2 ", RunLengthEncoding.Encode(" hsqq qww ")); }
public void Decode_single_characters_only() { Assert.Equal("XYZ", RunLengthEncoding.Decode("XYZ")); }
public void Encode_single_characters_mixed_with_repeated_characters() { Assert.Equal("12WB12W3B24WB", RunLengthEncoding.Encode("WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB")); }
public static Histogram[] MakeColorHistogram(RunLengthEncoding<int> i) { Histogram[] grams = new Histogram[4]; var q = (from x in (IEnumerable<RunLengthEncodingEntry<int>>)i let binds = ImageExtensions.Decode32(x.Value) select new { Alpha = binds[0], Red = binds[1], Green = binds[2], Blue = binds[3], }); //alpha grams[0] = new Histogram(from r in q select r.Alpha); grams[1] = new Histogram(from r in q select r.Red); grams[2] = new Histogram(from r in q select r.Green); grams[3] = new Histogram(from r in q select r.Blue); return grams; }
public static Histogram MakeHistogram(RunLengthEncoding<byte> b) { return new Histogram(from r in (IEnumerable<RunLengthEncodingEntry<byte>>)b select r.Value); }
public void Run_length_decode_a_string_lower_case_string() { Assert.Equal("aabbbcccc", RunLengthEncoding.Decode("2a3b4c")); }
public void Run_length_encode_a_string_single_characters_only_are_encoded_without_count() { Assert.Equal("XYZ", RunLengthEncoding.Encode("XYZ")); }
public void Encode_and_then_decode_encode_followed_by_decode_gives_original_string() { Assert.Equal("zzz ZZ zZ", RunLengthEncoding.Decode(RunLengthEncoding.Encode("zzz ZZ zZ"))); }
public void test_combination() { Assert.AreEqual("zzz ZZ zZ", RunLengthEncoding.Decode(RunLengthEncoding.Encode("zzz ZZ zZ"))); }