using Azimuth; using Blacklight.Core.Drawables; using UnitTestSharp; namespace Blacklight.Core.UnitTests.Drawables { public class FillSpacePropertyTests : TestFixture { static readonly Vector[] Triangle = { new Vector(0, 0), new Vector(5, 0), new Vector(1, 4) }; static readonly Vector[] ClosedCurve = { new Vector(0, 0), new Vector(-5, 0), new Vector(-10, 10), new Vector(0, 7), new Vector(10, 10), new Vector(5, -5), }; static IDrawPrimitive[] EveryShape() { return new IDrawPrimitive[] { new Rectangle(), new Ellipse(), new LineSegment(), new QuadraticBezierTriangle(), new BorderTriangle(), new Polygon(Triangle), new BorderPolygon(Triangle), new Polyline(Triangle), new ClosedQuadraticBezierCurve(ClosedCurve), }; } public class DefaultTests : TestFixture { public void EveryShape_IsScreenSpace() { foreach (IDrawPrimitive primitive in EveryShape()) { CheckEqual(FillSpace.Screen, primitive.ShellFillSpace); CheckEqual(FillSpace.Screen, primitive.InsideFillSpace); } } public void Sprite_IsScreenSpace() { CheckEqual(FillSpace.Screen, new Sprite().TintSpace); CheckEqual(FillSpace.Screen, default(Sprite).TintSpace); } public void ScreenIsTheZeroValueSoAnUnsetStructDefaultsToIt() { CheckEqual(0, (int)FillSpace.Screen); } } public class SetTests : TestFixture { public void EveryShape_KeepsBothSpaces() { foreach (IDrawPrimitive primitive in EveryShape()) { primitive.ShellFillSpace = FillSpace.Model; primitive.InsideFillSpace = FillSpace.Model; CheckEqual(FillSpace.Model, primitive.ShellFillSpace); CheckEqual(FillSpace.Model, primitive.InsideFillSpace); } } public void TheShellAndInsideAreIndependent() { var rectangle = new Rectangle { InsideFillSpace = FillSpace.Model }; CheckEqual(FillSpace.Screen, rectangle.ShellFillSpace); } public void TheSpaceAndTheTransformAreIndependent() { var rectangle = new Rectangle { InsideFillSpace = FillSpace.Model }; CheckEqual(Azimuth.AffineMatrix.Identity, rectangle.InsideFillTransform); } public void Sprite_KeepsTheTintSpace() { var sprite = new Sprite { TintSpace = FillSpace.Model }; CheckEqual(FillSpace.Model, sprite.TintSpace); } } public class CopyFromTests : TestFixture { public void StructToStruct_CopiesBothSpaces() { var source = new Rectangle { ShellFillSpace = FillSpace.Model }; var destination = new Rectangle { InsideFillSpace = FillSpace.Model }; destination.CopyFrom(ref source); CheckEqual(FillSpace.Model, destination.ShellFillSpace); CheckEqual(FillSpace.Screen, destination.InsideFillSpace); } public void ClassToStruct_CopiesBothSpaces() { var source = new Polygon(Triangle) { InsideFillSpace = FillSpace.Model }; var destination = new Rectangle { ShellFillSpace = FillSpace.Model }; destination.CopyFrom(source); CheckEqual(FillSpace.Screen, destination.ShellFillSpace); CheckEqual(FillSpace.Model, destination.InsideFillSpace); } public void ClassToClass_CopiesBothSpaces() { var source = new Polygon(Triangle) { ShellFillSpace = FillSpace.Model, InsideFillSpace = FillSpace.Model, }; var destination = new BorderPolygon(Triangle); destination.CopyFrom(source); CheckEqual(FillSpace.Model, destination.ShellFillSpace); CheckEqual(FillSpace.Model, destination.InsideFillSpace); } } } }