Exemple #1
0
        public AppEnvironment(ILogger logger, IConsoleManager consoleManager)
        {
            this.logger         = logger;
            this.consoleManager = consoleManager;

            triangleParser = new TriangleParser();
        }
        public void handle_invalid_sides_in_string()
        {
            var input          = "1 2 a";
            var triangleParser = new TriangleParser();

            Assert.Throws <FormatException>(() => triangleParser.ParseSingle(input));
        }
        public void handle_too_few_sides_in_string()
        {
            var input          = "1 2";
            var triangleParser = new TriangleParser();

            Assert.Throws <ArgumentException>(() => triangleParser.ParseSingle(input));
        }
        public void parse_input_string_to_sides()
        {
            var input    = " 330  143  338";
            var triangle = new TriangleParser().ParseSingle(input);

            Assert.AreEqual(143, triangle.Sides[0]);
            Assert.AreEqual(330, triangle.Sides[1]);
            Assert.AreEqual(338, triangle.Sides[2]);
        }
        public void convert_from_vertical_to_horizontal()
        {
            var input = new[]
            { " 101 301 501",
              "102 302 502",
              "103 303 503",
              "201 401 601",
              "202 402 602",
              "203 403 603" };
            var converted = new TriangleParser().ParseInputSet(input);

            Assert.AreEqual("501 502 503", converted[2]);
            Assert.AreEqual("401 402 403", converted[4]);
        }
Exemple #6
0
        static void Main(string[] args)
        {
            string      path           = string.Format("{0}\\..\\..\\Files\\", Environment.CurrentDirectory);
            string      inputFile      = string.Format("{0}input.csv", path);
            string      outputFile     = string.Format("{0}output.csv", path);
            IDataSource textDataSource = new TextDataSource(inputFile, outputFile);

            try
            {
                Console.WriteLine("Input Data:");
                Console.WriteLine("===========");
                Console.WriteLine(File.ReadAllText(inputFile));

                IEnumerable <string> inputData = textDataSource.Read();
                textDataSource.Data = inputData;

                IDataFormatter  csvDataFormatter = new CsvDataFormatter(',', true);
                IDataReadResult dataReadResult   = new DataReadResult();

                IParser triangleParser = new TriangleParser(textDataSource, csvDataFormatter, dataReadResult);
                dataReadResult = triangleParser.ReadDataSource();
                triangleParser.PopulateData(dataReadResult.Products, dataReadResult.FirstYear, dataReadResult.LastYear);

                IEnumerable <string> dataToWrite = triangleParser.GetDataForOutput(dataReadResult.Products, csvDataFormatter);

                textDataSource.Write(dataToWrite, dataReadResult.FirstYear, dataReadResult.NumberOfYears);

                Console.WriteLine();
                Console.WriteLine("File processed");
                Console.WriteLine();
                Console.WriteLine("Output Data:");
                Console.WriteLine("===========");
                Console.WriteLine(File.ReadAllText(outputFile));
            }
            catch (Exception ex)
            {
                Console.Write("Error processing file");
            }

            Console.ReadLine();
        }
Exemple #7
0
 public TriangleParserTests()
 {
     triangleParser = new TriangleParser();
 }