first unit test

This commit is contained in:
2019-10-25 03:16:17 -06:00
parent 6901925c69
commit 93b22ef2ec
21 changed files with 275 additions and 254 deletions

View File

@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
@@ -9,22 +8,21 @@ namespace Shapes
{
public class CompositeShape : Shape
{
private List<Shape> thisShapesList = new List<Shape>();
private readonly List<Shape> thisShapesList = new List<Shape>();
public override Color Fill { get; set; }
public override Color Stroke { get; set; }
public void Add(Shape shape)
{
if(shape.CompositeShape)
throw new ShapeException($"This shape has already been added to a composite");
if(shape == this)
throw new ShapeException($"You cant add a shape to itself");
if (shape.CompositeShape)
throw new ShapeException("This shape has already been added to a composite");
if (shape == this)
throw new ShapeException("You cant add a shape to itself");
thisShapesList.Add(shape);
shape.CompositeShape = true;
}
public override double ComputeArea()
{
@@ -33,32 +31,27 @@ namespace Shapes
public override void Scale(double scaleFactor)
{
foreach (var shape in thisShapesList)
{
shape.Scale(scaleFactor);
}
foreach (var shape in thisShapesList) shape.Scale(scaleFactor);
}
public override void Save(Stream stream)
{
var fileWriter = new FileIO();
fileWriter.SaveShape(stream, this);
fileWriter.SaveShape(stream, this);
}
public override void Draw(Stream stream)
{
var tmp = new Bitmap(1000, 1000);
Pen blackPen = new Pen(Stroke, 3);
var blackPen = new Pen(Stroke, 3);
// Draw line to screen.
using (var graphics = Graphics.FromImage(tmp))
{
foreach (var shape in thisShapesList)
{
for (int i = 1; i < shape.Points.Count; i++)
graphics.DrawLine(blackPen, (float) shape.Points[i - 1].X, (float) shape.Points[i - 1].Y, (float) shape.Points[i].X,
for (var i = 1; i < shape.Points.Count; i++)
graphics.DrawLine(blackPen, (float) shape.Points[i - 1].X, (float) shape.Points[i - 1].Y,
(float) shape.Points[i].X,
(float) shape.Points[i].Y);
}
}
tmp.Save(stream, ImageFormat.Jpeg);
@@ -67,11 +60,10 @@ namespace Shapes
public void RemoveShape(Shape shape)
{
if(!thisShapesList.Contains(shape))
if (!thisShapesList.Contains(shape))
throw new ShapeException($"{shape.GetType().Name} is not part of the composite shape.");
thisShapesList.Remove(shape);
shape.CompositeShape = false;
}
public void RemoveAllShapes()
@@ -82,6 +74,5 @@ namespace Shapes
thisShapesList.Remove(thisShapesList[0]);
}
}
}
}