Пример #1
0
        public void Test()
        {
            /// Example:
            /// Input: "3 1,56 1,cat"
            /// Returns: { (StackCommand.Top, null),
            /// (StackCommand.Push, 56), (StackCommand.Push, "cat") }
            StackOperationsParser op = new StackOperationsParser();

            string[] input = new string[] { "3 1,56 1,cat" };
            List <StackOperation> expected = new List <StackOperation>
            {
                new StackOperation(StackCommand.Top, null),
                new StackOperation(StackCommand.Push, 56),
                new StackOperation(StackCommand.Push, "cat")
            };
            List <StackOperation> actual = op.Parse(input);

            Assert.AreEqual(1, 1);
        }
Пример #2
0
        public void Test2()
        {
            StackOperationsParser op = new StackOperationsParser();

            string[] input = new string[]
            {
                "4 1,432.543",
                "3 2 1,joska 4 5"
            };
            List <StackOperation> expected = new List <StackOperation>
            {
                new StackOperation(StackCommand.isEmpty, null),
                new StackOperation(StackCommand.Push, 432.543),
                new StackOperation(StackCommand.Top, null),
                new StackOperation(StackCommand.Pop, null),
                new StackOperation(StackCommand.Push, "joska"),
                new StackOperation(StackCommand.isEmpty, null),
                new StackOperation(StackCommand.Print, null)
            };
            List <StackOperation> actual = op.Parse(input);

            Assert.AreEqual(1, 1);
        }
Пример #3
0
        public static void Show()
        {
            string pathToFolder = Directory.GetCurrentDirectory()
                                  .Replace(@"bin\Debug", "") + @"Files\";
            var countFiles = new DirectoryInfo(pathToFolder).GetFiles().Length;

            Console.WriteLine("---------------------------------------------------");
            for (int i = 1; i <= countFiles; i++)
            {
                string[] text                    = File.ReadAllLines(pathToFolder + "input" + i + ".txt");
                StackOperationsParser sop        = new StackOperationsParser();
                List <StackOperation> operations = sop.Parse(text);
                Console.WriteLine("input" + i + ".txt");
                Console.WriteLine("Время на считывание - " + ActionTimeMeasurer.Measure
                                      (new Action(() => sop.Parse(text))));
                Console.WriteLine();
                StackRealization <object> stack = new StackRealization <object>();
                var watch = new Stopwatch();
                foreach (StackOperation operation in operations)
                {
                    switch (operation.Command)
                    {
                    case StackCommand.Push:
                        watch.Start();
                        long executionTime = ActionTimeMeasurer.Measure
                                                 (new Action(() => stack.Push(operation.Object)));
                        watch.Stop();
                        Console.WriteLine("Команда: Push(" + operation.Object + ")");
                        Console.WriteLine("Время выполнения: " + executionTime);
                        break;

                    case StackCommand.Pop:
                        var saveElement = stack.Top();
                        watch.Start();
                        long executionTime2 = ActionTimeMeasurer.Measure
                                                  (new Action(() => stack.Pop()));
                        watch.Stop();
                        Console.WriteLine("Команда: Pop()");
                        Console.WriteLine("Возвращенное значeние: " + saveElement);
                        Console.WriteLine("Время выполнения: " + executionTime2);
                        break;

                    case StackCommand.Top:
                        watch.Start();
                        long executionTime3 = ActionTimeMeasurer.Measure
                                                  (new Action(() => stack.Top()));
                        watch.Stop();
                        Console.WriteLine("Команда: Top()");
                        Console.WriteLine("Возвращенное значeние: " + stack.Top());
                        Console.WriteLine("Время выполнения: " + executionTime3);
                        break;

                    case StackCommand.isEmpty:
                        watch.Start();
                        long executionTime4 = ActionTimeMeasurer.Measure
                                                  (new Action(() => stack.IsEmpty()));
                        watch.Stop();
                        Console.WriteLine("Команда: IsEmpty()");
                        Console.WriteLine("Возвращенное значeние: " + stack.IsEmpty());
                        Console.WriteLine("Время выполнения: " + executionTime4);
                        break;

                    case StackCommand.Print:
                        watch.Start();
                        long executionTime5 = ActionTimeMeasurer.Measure
                                                  (new Action(() => stack.Print()));
                        watch.Stop();
                        Console.WriteLine("Команда: Print()");
                        Console.WriteLine("Время выполнения: " + executionTime5);
                        break;

                    default:
                        throw new Exception();
                    }
                    string stackСondition = ObjectsToString(stack.Print());
                    Console.WriteLine("Состояние стека: " + stackСondition);
                    Console.WriteLine();
                }
                Console.WriteLine("Время на выполнение - " + watch.ElapsedMilliseconds);
                Console.WriteLine("---------------------------------------------------");
            }
        }