public void AverageWordsLengthTest(TestData <string> testData)
        {
            InputPlanner planner = new InputPlanner();

            using var console = new ConsoleMock();
            planner.ScheduleLines(testData.Input);
            console.Schedule(planner);
            ReflectionHelper.ExecuteMain(subjectType);
            string actual = console.ReadOutputLines().Last();

            Assert.AreEqual(testData.Expected, actual, testData.GetErrorMessage(actual));
        }
예제 #2
0
        public void PrintArrayTest()
        {
            using ConsoleMock consoleMock = new ConsoleMock();
            int[] array = { -4, 6, 0, -10, 45, 2, -7 };
            ReflectionHelper.ExecuteStaticMethod(subjectType, "PrintArray", array);
            var output = consoleMock.ReadOutputLines();

            Assert.AreEqual(array.Length, output.Length, $"Число строк в выводе: ожидалось - {array.Length}, было - {output.Length}");

            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(array[i].ToString(), output[i], $"Вывод элемента массива: ожидалось - {array[i]}, было {output[i]}");
            }
        }
        public void SpruceShouldBeInOutput(int count)
        {
            InputPlanner planner = new InputPlanner();

            planner.ScheduleLine(count.ToString());
            using ConsoleMock console = new ConsoleMock();
            console.Schedule(planner);
            ReflectionHelper.ExecuteMain(subjectType);

            string[] consoleOutput   = console.ReadOutputLines();
            int      spruceFirstLine = consoleOutput
                                       .IndexOf(line => line.Count(ch => ch.Equals('*')) == 1);

            Assert.AreNotEqual(spruceFirstLine, -1, $"Вершина пирамидки не найдена");
            string[] spruceActual = consoleOutput[spruceFirstLine..];
예제 #4
0
        public void ProgramShouldHaveCorrectOutput(TestData <string> testData)
        {
            InputPlanner inputPlanner = new InputPlanner();

            inputPlanner.ScheduleRead(testData.Input[0].ToCharArray());
            using var console = new ConsoleMock();
            console.Schedule(inputPlanner);

            ReflectionHelper.ExecuteMain(subjectType);

            string[] output = console.ReadOutputLines();
            string   actual = output.Last();

            Assert.AreEqual(testData.Expected, actual, testData.GetErrorMessage(actual));
        }
        public void SpruceShouldBeInOutput(int count)
        {
            InputPlanner planner = new InputPlanner();

            planner.ScheduleLine(count.ToString());
            using ConsoleMock console = new ConsoleMock();
            console.Schedule(planner);

            ReflectionHelper.ExecuteMain(subjectType);

            string[] consoleOutput   = console.ReadOutputLines();
            int      spruceFirstLine = Array.IndexOf(consoleOutput, "*");

            Assert.AreNotEqual(spruceFirstLine, -1, "Вершина треугольника не найдена");
            string[] spruceActual = consoleOutput[spruceFirstLine..];
예제 #6
0
        public void ProgramShouldHaveCorrectOutput(object dummy)
        {
            using var console = new ConsoleMock();
            ReflectionHelper.ExecuteMain(subjectType);

            string expectedOutput = $"String: [number]{Environment.NewLine}StringBuilder: [number]";

            string[] lines = console.ReadOutputLines();

            Assert.Greater(lines.Length, 1, $"Ожидаемый вывод:{Environment.NewLine}{expectedOutput}");
            Assert.IsTrue(lines[0].StartsWith("String: "), $"Ожидаемый вывод:{Environment.NewLine}{expectedOutput}");
            Assert.IsTrue(lines[1].StartsWith("StringBuilder: "), $"Ожидаемый вывод:{Environment.NewLine}{expectedOutput}");

            double stringDuration        = double.Parse(lines[0].Split(' ', StringSplitOptions.RemoveEmptyEntries).Last());
            double stringBuilderDuration = double.Parse(lines[1].Split(' ', StringSplitOptions.RemoveEmptyEntries).Last());

            Assert.Greater(stringDuration, stringBuilderDuration, "Конкатенация строки не может быть эффективнее класса StringBuilder");
        }