public void CompDecomp_v_1_3()
        {
            var generator = new AsciimationDataGenerator(File.ReadAllText(Path.Combine(QuineTests.PatternsFolder, "Asciimation.txt")));

            List<CompressedFrame> compressedFrames;
            var str = generator.Compress_v_1_3(out compressedFrames);
            File.WriteAllText("CompDecomp_v_1_3.txt", str);

            for (int i = 0; i < generator.Frames.Length; i++)
            {
                var expectedStr = "\r\n\r\n" + string.Join("\r\n", generator.Frames[i].Lines.Select(l => "//  " + l)) + "\r\n";
                var acturalStr = AsciimationDataGenerator.Decompress_v_1_3(str, i);
                Assert.AreEqual(expectedStr, acturalStr);
            }
        }
Exemplo n.º 2
0
        public void HuffmanRleFull()
        {
            var generator = new AsciimationDataGenerator(AsciimationData);
            var bytesFreqs = generator.GetBytesFreqs(false);
            var bytes = AsciimationDataGenerator.SerializeByteCount(bytesFreqs);
            var huffmanTable = Convert.ToBase64String(bytes);
            var tree = new HuffmanTree(bytesFreqs);

            var encodedTable = Convert.ToBase64String(bytes);
            var encodedFrames = new List<string>();
            for (int i = 0; i < generator.Frames.Length; i++)
            {
                var frame = generator.Frames[i];
                encodedFrames.Add(Convert.ToBase64String(HuffmanRle.Encode(tree, frame.Bytes)));
            }

            var decodedTree = new HuffmanTree(AsciimationDataGenerator.DeserializeByteCount(Base64.DecodeBase64(encodedTable)));
            var decodedFrames = new List<string>();
            for (int i = 0; i < encodedFrames.Count; i++)
            {
                var frame = HuffmanRle.Decode(decodedTree, Base64.DecodeBase64(encodedFrames[i]));
                CollectionAssert.AreEqual(generator.Frames[i].Bytes, frame);
            }
        }
Exemplo n.º 3
0
        public void RleHuffmanEncodeDecodeWithDifferentLengths()
        {
            var generator = new AsciimationDataGenerator(AsciimationData);
            var bytesFreqs = generator.GetBytesFreqs();
            var tree = new HuffmanTree(bytesFreqs);

            for (int i = 0; i < generator.Frames.Length; i++)
            {
                var frame = generator.Frames[i];
                var orig = frame.Bytes;

                int curBit = 0;
                byte[] bytes = new byte[frame.Bytes.Length * 2];
                HuffmanRle.Encode(tree, orig, ref curBit, bytes, 8, 4);
                bytes = bytes.Take((curBit + 7) / 8).ToArray();

                curBit = 0;
                var decoded = HuffmanRle2.Decode(tree, bytes, ref curBit, frame.Bytes.Length, 8, 4);
                CollectionAssert.AreEqual(orig, decoded);
            }
        }
Exemplo n.º 4
0
        public void RleHuffmanEncodeDecode()
        {
            var generator = new AsciimationDataGenerator(AsciimationData);
            var bytesFreqs = generator.GetBytesFreqs();
            var tree = new HuffmanTree(bytesFreqs);

            for (int i = 0; i < generator.Frames.Length; i++)
            {
                var frame = generator.Frames[i];
                var orig = frame.Bytes;
                var encoded = HuffmanRle.Encode(tree, orig);
                var decoded = HuffmanRle.Decode(tree, encoded);
                CollectionAssert.AreEqual(orig, decoded);
            }
        }
Exemplo n.º 5
0
        private void btnGenerateData_Click(object sender, EventArgs e)
        {
            var selectedItemText = cmbPattern.SelectedItem.ToString();
            var codeDataGenerator = new CodeDataGenerator(GetPlatformSpecificPath(tbSourceCodeFilesFolder.Text));
            switch (selectedItemText)
            {
                case "Asciimation_1_3.cs":
                    List<CompressedFrame> compressedFrames;
                    var asciimationGenerator13 = new AsciimationDataGenerator(File.ReadAllText(Path.Combine(tbPatternsFolder.Text, "Asciimation.txt")));
                    tbInput.Text = codeDataGenerator.SubstituteData(tbInput.Text, new List<CodeDataGeneratorParam>()
                    {
                        new CodeDataGeneratorParam {
                            KeyBegin = "/*%Data_1_3*/",
                            KeyEnd = "/*Data_1_3%*/",
                            Value = '"' + asciimationGenerator13.Compress_v_1_3(out compressedFrames) + '"'
                        }
                    });
                    break;

                case "QuineClock.cs":
                    var quineClock3Generator = new QuineClockDataGenerator(File.ReadAllText(Path.Combine(tbPatternsFolder.Text, "QuineClockDigits.txt")));
                    tbInput.Text = codeDataGenerator.SubstituteData(tbInput.Text, new List<CodeDataGeneratorParam>()
                        {
                            new CodeDataGeneratorParam
                            {
                                KeyBegin = "/*%Digits*/",
                                KeyEnd = "/*Digits%*/",
                                Value = '"' + string.Join("\",\"", quineClock3Generator.GetDigits().Select(s => s.Replace("\\", "\\\\"))) + '"'
                            }
                        });
                    break;

                case "QuineSnake.cs":
                    var quineSnakeGenerator = new QuineSnakeGenerator();
                    tbInput.Text = codeDataGenerator.SubstituteData(tbInput.Text, new List<CodeDataGeneratorParam>()
                        {
                            new CodeDataGeneratorParam
                            {
                                KeyBegin = "/*$FieldWidth*/",
                                KeyEnd = "/*FieldWidth$*/",
                                Value = QuineSnakeGenerator.FieldWidth.ToString(),
                                SaveKey = false
                            },
                            new CodeDataGeneratorParam
                            {
                                KeyBegin = "/*$FieldHeight*/",
                                KeyEnd = "/*FieldHeight$*/",
                                Value = QuineSnakeGenerator.FieldHeight.ToString(),
                                SaveKey = false
                            },
                            new CodeDataGeneratorParam
                            {
                                KeyBegin = "/*$HeadRow*/",
                                KeyEnd = "/*HeadRow$*/",
                                Value = QuineSnakeGenerator.HeadRow.ToString(),
                            },
                            new CodeDataGeneratorParam
                            {
                                KeyBegin = "/*$HeadColumn*/",
                                KeyEnd = "/*HeadColumn$*/",
                                Value = QuineSnakeGenerator.HeadColumn.ToString(),
                            },
                            new CodeDataGeneratorParam
                            {
                                KeyBegin = "/*$FoodRow*/",
                                KeyEnd = "/*FoodRow$*/",
                                Value = QuineSnakeGenerator.FoodRow.ToString(),
                            },
                            new CodeDataGeneratorParam
                            {
                                KeyBegin = "/*$FoodColumn*/",
                                KeyEnd = "/*FoodColumn$*/",
                                Value = QuineSnakeGenerator.FoodColumn.ToString(),
                            },
                            new CodeDataGeneratorParam
                            {
                                KeyBegin = "/*$NewDir*/",
                                KeyEnd = "/*NewDir$*/",
                                Value = QuineSnakeGenerator.NewDirString.ToString()
                            },
                            new CodeDataGeneratorParam
                            {
                                KeyBegin = "/*$Dirs*/",
                                KeyEnd = "/*Dirs$*/",
                                Value = QuineSnakeGenerator.DirsString
                            }
                        });
                    break;
            }
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            var generator = new AsciimationDataGenerator(File.ReadAllText(@"..\..\..\Patterns and Data\Asciimation.txt"));

            List<CompressedFrame> compressedFrames;
            var compressedStr = generator.Compress_v_1_3(out compressedFrames, true);
            File.WriteAllText(DateTime.Now.Ticks.ToString() + ".txt", compressedStr);

            Console.WriteLine("Global frames count: " + generator.Frames.Length);
            Console.WriteLine("Compressed frames count: " + compressedFrames.Where(f => f.FrameType != FrameType.Basic).Count());

            var repeatedLengths = new List<int>();
            var notrepeatedLengths = new List<int>();
            var changeLengths = new List<int>();
            var changeCounts = new List<int>();
            int maxReducedLineLength = 0;

            var frameTypesCount = new Dictionary<FrameType, int>()
            {
                { FrameType.Basic, 0 },
                { FrameType.Transitional, 0 },
                { FrameType.TransitionalLeft, 0 },
                { FrameType.TransitionalRight, 0 },
                { FrameType.TransitionalTop, 0 },
                { FrameType.TransitionalBottom, 0 }
            };

            for (int i = 0; i < compressedFrames.Count; i++)
            {
                var compressedFrame = compressedFrames[i];
                switch (compressedFrame.FrameType)
                {
                    case FrameType.Basic:
                        GetRepeatedCount(generator.Frames[i].ReducedLine, repeatedLengths, notrepeatedLengths);
                        if (generator.Frames[i].ReducedLine.Length > maxReducedLineLength)
                            maxReducedLineLength = generator.Frames[i].ReducedLine.Length;
                        break;
                    case FrameType.Transitional:
                    case FrameType.TransitionalLeft:
                    case FrameType.TransitionalRight:
                    case FrameType.TransitionalTop:
                    case FrameType.TransitionalBottom:
                        foreach (var change in compressedFrame.FrameChanges)
                        {
                            //GetRepeatedCount(new string(change.Chars.ToArray()), repeatedLengths, notrepeatedLengths);
                            changeLengths.Add(change.Chars.Count);
                        }
                        changeCounts.Add(compressedFrame.FrameChanges.Count);
                        break;
                }
                frameTypesCount[compressedFrame.FrameType]++;
            }

            Console.WriteLine("Basic count: " + frameTypesCount[FrameType.Basic]);
            Console.WriteLine("Trans count: " + frameTypesCount[FrameType.Transitional]);
            Console.WriteLine("Trans left count: " + frameTypesCount[FrameType.TransitionalLeft]);
            Console.WriteLine("Trans right count: " + frameTypesCount[FrameType.TransitionalRight]);
            Console.WriteLine("Trans top count: " + frameTypesCount[FrameType.TransitionalTop]);
            Console.WriteLine("Trans bottom count: " + frameTypesCount[FrameType.TransitionalBottom]);

            Console.WriteLine("Avg repeated chars length: " + repeatedLengths.Average());
            Console.WriteLine("Avg not repeated chars length: " + notrepeatedLengths.Average());
            Console.WriteLine("Avg change length: " + changeLengths.Average());
            Console.WriteLine("Max change length: " + changeLengths.Max());
            Console.WriteLine("Max change count: " + changeCounts.Max());
            Console.WriteLine("Max reduced line length: " + maxReducedLineLength);

            Console.ReadLine();
        }