public static void TestDecode() { RunLengthCodec dec = new RunLengthCodec(4, 2, 2, 0); // 0, 1, 2 - data symbols // 3, 4 - run of 0, stage 0 and 1 Assert.IsTrue(dec.Decode(new int[] { 0, 0, 0, 1, 1, 2, 2, 2 }) .SequenceEqual(new int[] { 0, 0, 0, 1, 1, 2, 2, 2 })); Assert.IsTrue(dec.Decode(new int[] { 3, 2 }) .SequenceEqual(new int[] { 0, 0, 0 })); Assert.IsTrue(dec.Decode(new int[] { 3, 0, 3, 2, 1, 3, 4, 2, 3, 0, 4, 0, 0 }) .SequenceEqual(new int[] { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0 })); }
public static void TestEncode() { RunLengthCodec enc = new RunLengthCodec(4, 2, 2, 0); // 0, 1, 2 - data symbols // 3, 4 - run of 0, stage 0 and 1 Assert.IsTrue(enc.Encode(new int[] { 0, 1, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0 }) .SequenceEqual(new int[] { 0, 1, 2, 2, 2, 4, 1, 0 })); enc = new RunLengthCodec(9, 2, 3, 0); // 0, 1 - data // 2, 3, 4 - run of 0, stage 0, 1, 2 Assert.IsTrue(enc.Encode(new int[] { 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }) .SequenceEqual(new int[] { 0, 1, 1, 0, 1, 4, 5, 0 })); enc = new RunLengthCodec(5, 2, 3, 0); // 0, 1 - data // 2, 3, 4 - run of 0, stage 0, 1, 2 Assert.IsTrue(enc.Encode(new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }) .SequenceEqual(new int[] { 4, 3, 5 })); }