using System; using Azimuth; using Blacklight.Core.Drawables; using UnitTestSharp; namespace Blacklight.Core.UnitTests.Drawables { public class FillTransformsTests : TestFixture { static readonly AffineMatrix Skewed = new AffineMatrix(2, 0.5, 5, 0.25, 3, 7); public class ReadTests : TestFixture { public void TheAllZeroMatrix_IsTheIdentity() { CheckEqual(AffineMatrix.Identity, FillTransforms.Read(default)); } public void AnyOtherMatrix_PassesThrough() { CheckEqual(Skewed, FillTransforms.Read(Skewed)); } public void TheIdentity_StaysTheIdentity() { CheckEqual(AffineMatrix.Identity, FillTransforms.Read(AffineMatrix.Identity)); } public void AMatrixWithOnlyOneNonZeroElement_PassesThrough() { var onlyTranslated = new AffineMatrix(0, 0, 3, 0, 0, 0); CheckEqual(onlyTranslated, FillTransforms.Read(onlyTranslated)); } } public class CheckTests : TestFixture { public void ReturnsAnInvertibleMatrixUnchanged() { CheckEqual(Skewed, FillTransforms.Check(Skewed)); } public void AcceptsAMirror() { var mirror = new AffineMatrix(-1, 0, 0, 0, 1, 0); CheckEqual(mirror, FillTransforms.Check(mirror)); } public void ThrowsForASingularMatrix() { CheckThrow(typeof(ArgumentException)); FillTransforms.Check(new AffineMatrix(1, 2, 0, 2, 4, 0)); } public void ThrowsForTheAllZeroMatrix() { CheckThrow(typeof(ArgumentException)); FillTransforms.Check(default); } public void ThrowsForANaNElement() { CheckThrow(typeof(ArgumentException)); FillTransforms.Check(new AffineMatrix(1, 0, double.NaN, 0, 1, 0)); } public void ThrowsForAnInfiniteElement() { CheckThrow(typeof(ArgumentException)); FillTransforms.Check(new AffineMatrix(1, 0, 0, 0, 1, double.PositiveInfinity)); } public void ThrowsWhenTheDeterminantOverflows() { CheckThrow(typeof(ArgumentException)); FillTransforms.Check(new AffineMatrix(1e200, 0, 0, 0, 1e200, 0)); } } } }