예제 #1
0
        public void ShouldNotAllowIfYIsOutOfCanvas()
        {
            var canvas = new string[5, 5];
            BucketFill bucket = new BucketFill(1, 10);

            Assert.IsFalse(bucket.IsValid(canvas));
        }
예제 #2
0
        public void ShouldNotAllowIfXIsOutOfCanvas()
        {
            string[,] canvas = new string[5, 5];
            BucketFill bucket = new BucketFill(6, 3);

            Assert.IsFalse(bucket.IsValid(canvas));
        }
예제 #3
0
        public void ShouldDrawABucket()
        {
            var canvas = new string[5, 5];
            BucketFill bucket = new BucketFill(1, 1);

            Assert.IsTrue(bucket.IsValid(canvas));

            var drawnCanvas = bucket.DrawToCanvas(canvas);

            Assert.IsNotNull(drawnCanvas);
            Assert.AreEqual("o", drawnCanvas.GetValue(1, 1));
            Assert.AreEqual("o", drawnCanvas.GetValue(1, 2));
            Assert.AreEqual("o", drawnCanvas.GetValue(1, 3));
            Assert.AreEqual("o", drawnCanvas.GetValue(1, 4));

            Assert.AreEqual("o", drawnCanvas.GetValue(2, 1));
            Assert.AreEqual("o", drawnCanvas.GetValue(2, 2));
            Assert.AreEqual("o", drawnCanvas.GetValue(2, 3));
            Assert.AreEqual("o", drawnCanvas.GetValue(2, 4));

            Assert.AreEqual("o", drawnCanvas.GetValue(3, 1));
            Assert.AreEqual("o", drawnCanvas.GetValue(3, 2));
            Assert.AreEqual("o", drawnCanvas.GetValue(3, 3));
            Assert.AreEqual("o", drawnCanvas.GetValue(3, 4));

            Assert.AreEqual("o", drawnCanvas.GetValue(4, 1));
            Assert.AreEqual("o", drawnCanvas.GetValue(4, 2));
            Assert.AreEqual("o", drawnCanvas.GetValue(4, 3));
            Assert.AreEqual("o", drawnCanvas.GetValue(4, 4));
        }
예제 #4
0
        static void ProcessCommands(string input)
        {
            try
            {
                var allowedCommands = new string[] { "C", "L", "R", "B", "FILE" };
                string[] commands = input.Trim().Split(' ');
                string elementComand = commands.Length > 0 ? commands[0].ToUpper() : " ";

                if (allowedCommands.Contains(elementComand))
                {
                    if (elementComand == "FILE")
                    {
                        ProcessFromFile(commands[1]);
                    }
                    else if (elementComand == "C")
                    {
                        workingCanvas = new Canvas(int.Parse(commands[1]), int.Parse(commands[2]));
                    }
                    else if (workingCanvas != null)
                    {
                        switch (elementComand)
                        {
                            case "L":
                                Line line = new Line(int.Parse(commands[1]), int.Parse(commands[2]), int.Parse(commands[3]), int.Parse(commands[4]));
                                workingCanvas.Elements.Add(line);
                                break;
                            case "R":
                                Rectangle rectangle = new Rectangle(int.Parse(commands[1]), int.Parse(commands[2]), int.Parse(commands[3]), int.Parse(commands[4]));
                                workingCanvas.Elements.Add(rectangle);
                                break;
                            case "B":
                                BucketFill bucket = new BucketFill(int.Parse(commands[1]), int.Parse(commands[2]), commands[3]);
                                workingCanvas.Elements.Add(bucket);
                                break;
                        }
                    }
                    else
                    {
                        WriteErrorLine(string.Concat("Sorry, you need to create a canvas first, enter ? for help."));
                    }

                    if (workingCanvas != null && elementComand != "FILE")
                    {
                        WriteResultLine(workingCanvas.Draw(Environment.NewLine));
                    }
                }
                else
                {
                    WriteErrorLine(string.Concat("Sorry, command: ", elementComand, " is not allowed, enter ? for help."));
                }
            }
            catch (Exception ex)
            {
                WriteErrorLine(string.Concat("Sorry, something is wrong with the command input, enter ? for help."));
            }
        }
예제 #5
0
        public void ShouldFillPropertiesFromConstructor()
        {
            BucketFill bucket = new BucketFill(1, 2, "+");

            Assert.IsNotNull(bucket.Properties);
            Assert.AreEqual(bucket.Properties.X1, 1);
            Assert.AreEqual(bucket.Properties.Y1, 2);

            Assert.AreEqual("+", bucket.Properties.BrushChar);
        }
예제 #6
0
 public void ShouldHaveADefaultBrush()
 {
     BucketFill bucket = new BucketFill(1, 2);
     Assert.AreEqual("o", bucket.Properties.BrushChar);
 }