Example #1
0
       // static Dictionary<int, int> _CollatzLookup;

        static void Main(string[] args)
        {
            Console.WriteLine("Starting");
            IUserInputOutput userInputOutput = new FileUserInputOutput(_fileOutLocation);
            IChallengeCalculator challengeCalculator = new Computer();
            var inputs = userInputOutput.ReadInput();
            var outputs = new HashSet<Output>();

            var stopwatch = new Stopwatch();
            stopwatch.Start();
            foreach (var input in inputs)
            {
                var maxCycle = challengeCalculator.CalculateMaxCycles(input);
                outputs.Add(new Output
                {
                    Input = input,
                    MaxCycle = maxCycle
                });
            }
            stopwatch.Stop();
            Console.WriteLine(stopwatch.Elapsed);
            Console.WriteLine("Completed");
            userInputOutput.PrintOutput(outputs);

            Console.WriteLine("Completed");
            Console.ReadLine();
        }
        public void ReadFromFileInAppConfigTest()
        {
            var fileReader = new FileUserInputOutput(_fileOutLocation);

            var inputs = fileReader.ReadInput();
            IEnumerable<Input> expected = new HashSet<Input>
            {
                new Input
                {
                    Start = 1,
                    End = 10
                }
            };
            
            
            CollectionAssert.AreEqual(expected.ToList(), inputs.ToList());
        }
        public void WriteToFileTest()
        {
            var fileWriter = new FileUserInputOutput(_fileOutLocation);

            var outputs = new HashSet<Output>
            {
                new Output
                {
                    Input = new Input
                    {
                        Start = 1,
                        End = 10
                    },
                    MaxCycle = 20
                }
            };

            fileWriter.PrintOutput(outputs);

            Assert.IsTrue(File.Exists(_fileOutLocation));
            //should add additional checks that read the file and compare to expected outputs

        }