예제 #1
0
        public void StrGeneratorLengthTests(int numOfWords, int minLength, int maxLength, int resLength)
        {
            var generator = new Lab2Main();
            var res       = generator.generateStrings(numOfWords, minLength, maxLength);

            Assert.AreEqual(res.Count, resLength);
        }
예제 #2
0
        public static void Main(string[] args)
        {
            var         test = new Lab2Main();
            XmlDocument xDoc = new XmlDocument();

            xDoc.Load("C:\\Users\\1\\source\\repos\\Lab2\\Lab2\\XMLFile1.xml");
            var root        = xDoc.DocumentElement;
            var experiments = root.SelectNodes("experiment").Item(0).ChildNodes;

            using (StreamWriter writer = new StreamWriter("C:\\Users\\1\\source\\repos\\Lab2\\Lab2\\results.txt"))
            {
                foreach (XmlNode experiment in experiments)
                {
                    var name        = experiment.Attributes["name"].Value;
                    var type        = name.Split(" ")[0];
                    var repeat      = Int32.Parse(experiment.Attributes["repeat"].Value);
                    var minElement  = Int32.Parse(experiment.Attributes["minElement"].Value);
                    var maxElement  = Int32.Parse(experiment.Attributes["maxElement"].Value);
                    var startLength = Int32.Parse(experiment.Attributes["startLength"].Value);
                    var maxLength   = Int32.Parse(experiment.Attributes["maxLength"].Value);
                    if (type.Equals("Arithmetic"))
                    {
                        var diff = Int32.Parse(experiment.Attributes["diff"].Value);
                        for (var j = startLength; j <= maxLength; j += diff)
                        {
                            var operationsOnLength = "" + j.ToString();
                            for (var i = 0; i < repeat; i++)
                            {
                                var           arr      = test.generateStrings(j, minElement, maxElement).ToArray();
                                var           comparer = StringComparer.Ordinal;
                                Heap <string> heap     = new Heap <string>(arr, comparer);
                                heap.HeapSort();
                                writer.WriteLine(operationsOnLength + " " + heap.operationsCount.ToString());
                            }
                        }
                    }
                    else
                    {
                        var diff = Double.Parse(experiment.Attributes["diff"].Value);
                        for (var j = (double)startLength; j <= maxLength; j *= diff)
                        {
                            var convertedLength    = (int)j;
                            var operationsOnLength = "" + convertedLength.ToString();
                            for (var i = 0; i < repeat; i++)
                            {
                                var           arr      = test.generateStrings(convertedLength, minElement, maxElement).ToArray();
                                var           comparer = StringComparer.Ordinal;
                                Heap <string> heap     = new Heap <string>(arr, comparer);
                                heap.HeapSort();
                                writer.WriteLine(operationsOnLength + " " + heap.operationsCount.ToString());
                            }
                        }
                    }
                }
            }
            Console.WriteLine("Результаты вычислений в виде .txt файла можно найти в папке с программой, для выхода нажмите любую кнопку");
            Console.ReadLine();
        }
예제 #3
0
        public void StrGeneratorCharactersTest(int numOfWords, int minLength, int maxLength, string chars)
        {
            var generator = new Lab2Main();
            var res       = generator.generateStrings(numOfWords, minLength, maxLength);
            var flag      = true;

            foreach (var word in res)
            {
                flag = word.All(c => chars.Contains(c));
                if (!flag)
                {
                    break;
                }
            }
            Assert.AreEqual(flag, true);
        }