Exemplo n.º 1
0
        static void Main(string[] args)
        {
            // Read task settings from a json file
            string fileName;

            if (args.Length == 0)
            {
                Console.WriteLine("Input file not passed as a parameter, loading settings from Task1Input.json");
                fileName = "Task1Input.json";
            }
            else
            {
                fileName = args[0];
            }

            //Deserialize settings from json
            var settings = JsonConvert.DeserializeObject <StairsTaskSettings[]>(System.IO.File.ReadAllText(fileName));

            // Run solution for each case
            var solution = new StairsTaskSolution();

            for (var i = 0; i < settings.Length; i++)
            {
                var setting = settings[i];
                var result  = solution.Run(setting.Flights, setting.StepsPerStride);
                Console.WriteLine(
                    $"Case: {i + 1}, Flights: {{{string.Join(", ", setting.Flights)}}}, StepsPerStride: {setting.StepsPerStride}, Result: {result}");
            }

            Console.WriteLine("Press any key...");
            Console.ReadKey();
        }
        public void SolutionThrowsArgumentExceptionWhenStepsPerStrideIsOutOfRange(int stepsPerStride)
        {
            // Setup
            var solution = new StairsTaskSolution();

            //Run, expect ArgumentException
            Assert.Throws <ArgumentException>(() => solution.Run(new[] { 10 }, stepsPerStride), "StepsPerStride must be between 2 and 5, inclusive");
        }
        public void SolutionThrowsArgumentExceptionWhenFlightsAreOutOfRange(int numberOfFligts)
        {
            // Setup
            var flights  = new int[numberOfFligts];
            var solution = new StairsTaskSolution();

            //Run, expect ArgumentException
            Assert.Throws <ArgumentException>(() => solution.Run(flights, 2), "Staircase must contain between 1 and 50 flights of stairs");
        }
        public void SolutionThrowsArgumentExceptionWhenNumberOfStepsIsOutOfRange(int numberOfSteps)
        {
            // Setup
            var flights  = new [] { numberOfSteps };
            var solution = new StairsTaskSolution();

            //Run, expect ArgumentException
            Assert.Throws <ArgumentException>(() => solution.Run(flights, 2), "Each flight of stairs must be between 5 and 30 steps, inclusive");
        }
        public void TestSolution(int[] flights, int stepsPerStride, int expectedSteps)
        {
            // Setup
            var solution = new StairsTaskSolution();

            //Run
            var result = solution.Run(flights, stepsPerStride);

            //Assert
            Assert.AreEqual(expectedSteps, result);
        }