public void ShouldNotAllowIfYIsOutOfCanvas() { var canvas = new string[5, 5]; Rectangle rectangle = new Rectangle(1, 8, 1, 4); Assert.IsFalse(rectangle.IsValid(canvas)); }
public void ShouldNotAllowIfXIsOutOfCanvas() { string[,] canvas = new string[5, 5]; Rectangle rectangle = new Rectangle(6, 3, 6, 4); Assert.IsFalse(rectangle.IsValid(canvas)); }
public void ShouldDrawARectangle() { var canvas = new string[5, 5]; Rectangle rectangle = new Rectangle(1, 1, 3, 3); Assert.IsTrue(rectangle.IsValid(canvas)); var drawnCanvas = rectangle.DrawToCanvas(canvas); Assert.IsNotNull(drawnCanvas); Assert.AreEqual(null, drawnCanvas.GetValue(0, 0)); Assert.AreEqual("x", drawnCanvas.GetValue(1, 1)); Assert.AreEqual("x", drawnCanvas.GetValue(1, 2)); Assert.AreEqual("x", drawnCanvas.GetValue(1, 3)); Assert.AreEqual(null, drawnCanvas.GetValue(1, 4)); Assert.AreEqual(null, drawnCanvas.GetValue(2, 0)); Assert.AreEqual("x", drawnCanvas.GetValue(2, 1)); Assert.AreEqual(null, drawnCanvas.GetValue(2, 2)); Assert.AreEqual("x", drawnCanvas.GetValue(2, 3)); Assert.AreEqual(null, drawnCanvas.GetValue(2, 4)); Assert.AreEqual(null, drawnCanvas.GetValue(3, 0)); Assert.AreEqual("x", drawnCanvas.GetValue(3, 1)); Assert.AreEqual("x", drawnCanvas.GetValue(3, 2)); Assert.AreEqual("x", drawnCanvas.GetValue(3, 3)); Assert.AreEqual(null, drawnCanvas.GetValue(3, 4)); }
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.")); } }
public void ShouldFillPropertiesFromConstructor() { Rectangle rectangle = new Rectangle(1, 2, 3, 4); Assert.IsNotNull(rectangle.Properties); Assert.AreEqual(rectangle.Properties.X1, 1); Assert.AreEqual(rectangle.Properties.Y1, 2); Assert.AreEqual(rectangle.Properties.X2, 3); Assert.AreEqual(rectangle.Properties.Y2, 4); }
public void ShouldHaveADefaultBrush() { Rectangle rectangle = new Rectangle(1, 2, 3, 4); Assert.AreEqual(rectangle.Properties.BrushChar, "x"); }