Пример #1
0
        public void CanvasService_CreateCanvas_Test()
        {
            //Given
            const int width = 2;
            const int height = 2;

            // When 
            var result = _canvasService.CreateCanvas(width, height);

            //Then
            Assert.AreEqual('-', result.Matrix[0, 0]);
            Assert.AreEqual('-', result.Matrix[0, 1]);
            Assert.AreEqual('-', result.Matrix[0, 2]);
            Assert.AreEqual('-', result.Matrix[0, 3]);
            Assert.AreEqual('-', result.Matrix[3, 0]);
            Assert.AreEqual('-', result.Matrix[3, 1]);
            Assert.AreEqual('-', result.Matrix[3, 2]);
            Assert.AreEqual('-', result.Matrix[3, 3]);
            Assert.AreEqual('|', result.Matrix[1, 0]);
            Assert.AreEqual('|', result.Matrix[2, 0]);          
            Assert.AreEqual('|', result.Matrix[1, 3]);
            Assert.AreEqual('|', result.Matrix[2, 3]);
            Assert.AreEqual('\0', result.Matrix[1, 1]);
            Assert.AreEqual('\0', result.Matrix[1, 2]);
            Assert.AreEqual('\0', result.Matrix[2, 1]);
            Assert.AreEqual('\0', result.Matrix[2, 2]);
        }
Пример #2
0
        public bool ProcessFile(string fileInputPath, string fileOutputPath)
        {
            Canvas canvas;
            List <Tuple <char, string[]> > parameters = _fileReader.ReadFile(fileInputPath);

            if (!parameters.Any(p => p.Item1 == 'C'))
            {
                Console.WriteLine("There is no canvas in the input file");
                return(false);
            }
            else
            {
                var canvasParameter = parameters.FirstOrDefault(p => p.Item1 == 'C');
                canvas = _canvasService.CreateCanvas(int.Parse(canvasParameter.Item2[0]), int.Parse(canvasParameter.Item2[1]));
                parameters.Remove(canvasParameter);
                _fileWriter.ClearFile(fileOutputPath);
                _fileWriter.DrawShapeIntoFile(canvas, fileOutputPath);
            }

            foreach (var parameter in parameters)
            {
                switch (parameter.Item1)
                {
                case 'L':
                {
                    Line line = new Line(new Point(int.Parse(parameter.Item2[0]), int.Parse(parameter.Item2[1])),
                                         new Point(int.Parse(parameter.Item2[2]), int.Parse(parameter.Item2[3])));
                    _lineService.CreateShape(ref canvas, line);
                    _fileWriter.DrawShapeIntoFile(canvas, fileOutputPath);
                }
                break;

                case 'R':
                {
                    Rectangle rectangle = new Rectangle(new Point(int.Parse(parameter.Item2[0]), int.Parse(parameter.Item2[1])),
                                                        new Point(int.Parse(parameter.Item2[2]), int.Parse(parameter.Item2[3])));
                    _rectangleService.CreateShape(ref canvas, rectangle);
                    _fileWriter.DrawShapeIntoFile(canvas, fileOutputPath);
                }
                break;

                case 'B':
                {
                    _bucketFillService.FillCanvas(ref canvas,
                                                  new Point(int.Parse(parameter.Item2[0]), int.Parse(parameter.Item2[1])),
                                                  char.Parse(parameter.Item2[2]));
                    _fileWriter.DrawShapeIntoFile(canvas, fileOutputPath);
                }
                break;
                }
            }
            return(true);
        }