public void Add_SameElementTwice() { ShapeGroup shapeGroup = new ShapeGroup(); shapeGroup.SetReadOnly(false); Circle circle = new Circle(0, 0, 0); shapeGroup.Add(circle); shapeGroup.Add(circle); Assert.That(shapeGroup.size, Is.EqualTo(1)); }
public void Contains_PointInGroup() { ShapeGroup shapeGroup = new ShapeGroup(); shapeGroup.Add(new Circle(0, 0, 0)); Assert.That(shapeGroup.Contains(0, 0), Is.True); }
public void Contains_ShapeInGroup() { ShapeGroup shapeGroup = new ShapeGroup(); Circle c = new Circle(0, 0, 0); shapeGroup.Add(c); Assert.That(shapeGroup.Contains(c), Is.True); }
public void Add_WithoutReadOnly() { ShapeGroup shapeGroup = new ShapeGroup(); shapeGroup.SetReadOnly(false); shapeGroup.Add(new Circle(0, 0, 0)); Assert.That(shapeGroup.size, Is.EqualTo(1)); }
public void TooXml() { ShapeGroup shapeGroup = new ShapeGroup(); shapeGroup.Add(new Rectangle(0, 0, 2, 1)); string xml = shapeGroup.ToXml(); Assert.That( xml, Is.EqualTo( "<shapegroup>\n<rectangle x=\"0\" y=\"0\" width=\"2\" height=\"1\" />\n</shapegroup>\n")); }
public void Add_InternalArraySizeExceeded() { ShapeGroup shapeGroup = new ShapeGroup(); shapeGroup.SetReadOnly(false); for (int i = 0; i < 11; i++) { shapeGroup.Add(new Circle(0, 0, 0)); } Assert.That(shapeGroup.size, Is.EqualTo(11)); }
public void CreateGroupAndFindMeasure() { var rand = _rand.Next(1, 50) + _rand.NextDouble(); var rand2 = _rand.Next(1, 50) + _rand.NextDouble(); var ellipse = new Ellipse(new Point(0, 0), rand, rand2, new Perimeter()); var tryangle = new Tryangle(new Point(0, 0), rand, rand2, new Perimeter()); var square = new Square(new Point(0, 0), rand, new Perimeter()); ShapeGroup <IMeasurable> sg = new ShapeGroup <IMeasurable>(new GroupMeasure(new AddOperator())); sg.Add(ellipse); sg.Add(tryangle); sg.Add(square); var groupMeasure = sg.GetMeasure(); Assert.AreEqual(ellipse.GetMeasure() + tryangle.GetMeasure() + square.GetMeasure(), groupMeasure); var anotherGroup = new ShapeGroup <IMeasurable>(new GroupMeasure(new AddOperator())); anotherGroup.Add(ellipse); anotherGroup.Add(tryangle); anotherGroup.Add(square); sg.Add(anotherGroup); Assert.AreEqual(groupMeasure + anotherGroup.GetMeasure(), sg.GetMeasure()); }
static void Main(string[] args) { var sm = new ShapeManager(); var cmdMgr = new CommandManager(); sm.Add(new Rectangle(10, 3, ConsoleColor.Green)); sm.Add(new Circle(5, ConsoleColor.Red)); sm.Add(new Square(8, ConsoleColor.Blue)); var group = new ShapeGroup(); group.Add(new Circle(10)); group.Add(new Rectangle(6, 8, ConsoleColor.Cyan)); sm.Add(group); var group2 = new ShapeGroup(); group2.Add(new Square(12, ConsoleColor.DarkGray)); group2.Add(new Circle(6)); group.Add(group2); var rnd = new Random(); bool done = false; while (!done) { int n; Console.WriteLine(); Console.Write("A=Add, E=Remove, D=Display, M=Move, U=Undo, R=Redo, Q=Quit: "); switch (Console.ReadLine().ToUpper()) { case "D": sm.Display(Console.Out); break; case "Q": done = true; break; case "M": n = GetShapeNumber(); Console.Write("X Offset: "); int dx = int.Parse(Console.ReadLine()); Console.Write("Y Offset: "); int dy = int.Parse(Console.ReadLine()); var cmd = new MoveCommand(sm[n], dx, dy); cmdMgr.Add(cmd); break; case "U": if (!cmdMgr.CanUndo) { Console.WriteLine("Cannot undo!"); } else { cmdMgr.Undo(); } break; case "R": if (!cmdMgr.CanRedo) { Console.WriteLine("Cannot redo!"); } else { cmdMgr.Redo(); } break; case "A": Shape shape = null; switch (rnd.Next(3)) { case 0: shape = new Square(rnd.Next(10) + 5); break; case 1: shape = new Circle(rnd.Next(10) + 2); break; case 2: shape = new Rectangle(rnd.Next(10) + 1, rnd.Next(10) + 3); break; } cmdMgr.Add(new AddShapeCommand(sm, shape)); break; case "E": n = GetShapeNumber(); cmdMgr.Add(new RemoveShapeCommand(sm, sm[n])); break; } } }