using Chernobyl.Mathematics.Movement;
using NUnit.Framework;
namespace Chernobyl.Mathematics.Geometry
{
///
/// A test fixture base helper class that is used to test types that
/// implement the interface. This class also implements
/// so that the portion
/// of the interface can be tested as well.
///
public abstract class ShapeTests : TransformTests
{
[Test, Description("Ensures the width of the IShape created by " +
"CreateShape() is the width that was expected.")]
public void WidthIsCorrect()
{
IShape shape = CreateShape();
Assert.AreEqual(ExpectedWidth, shape.Width, "The width of the IShape " +
"is not correct.");
}
[Test, Description("Ensures the height of the IShape created by " +
"CreateShape() is the height that was expected.")]
public void HeightIsCorrect()
{
IShape shape = CreateShape();
Assert.AreEqual(ExpectedHeight, shape.Height, "The height of the " +
"IShape is not correct.");
}
[Test, Description("Ensures the depth of the IShape created by " +
"CreateShape() is the depth that was expected.")]
public void DepthIsCorrect()
{
IShape shape = CreateShape();
Assert.AreEqual(ExpectedDepth, shape.Depth, "The depth of the " +
"IShape is not correct.");
}
[Test, Description("Ensures the IsConvex of the IShape created by " +
"CreateShape() is the IsConvex that was expected.")]
public void IsConvexIsCorrect()
{
IShape shape = CreateShape();
Assert.AreEqual(ExpectedIsConvex, shape.IsConvex, "The IsConvex " +
"property of the IShape is not correct.");
}
[Test, Description("Ensures the area of the IShape created by " +
"CreateShape() is the area that was expected.")]
public void AreaIsCorrect()
{
IShape shape = CreateShape();
Assert.AreEqual(ExpectedArea, shape.Area, "The area of the " +
"IShape is not correct.");
}
[Test, Description("Ensures the volume of the IShape created by " +
"CreateShape() is the volume that was expected.")]
public void VolumeIsCorrect()
{
IShape shape = CreateShape();
Assert.AreEqual(ExpectedVolume, shape.Volume, "The volume of the " +
"IShape is not correct.");
}
[Test, Description("Ensures the perimeter of the IShape created by " +
"CreateShape() is the perimeter that was expected.")]
public void PerimeterIsCorrect()
{
IShape shape = CreateShape();
Assert.AreEqual(ExpectedPerimeter, shape.Perimeter, "The perimeter" +
" of the IShape is not correct.");
}
[Test, Description("Ensures the dimensions of the IShape created by " +
"CreateShape() is the dimensions that was expected.")]
public void DimensionsIsCorrect()
{
IShape shape = CreateShape();
Assert.AreEqual(ExpectedDimensions, shape.Dimensions, "The dimensions " +
" of the IShape is not correct.");
}
[Test, Description("Ensures the width is properly magnified after the " +
"shape has been scaled in the X.")]
public void ScalesWidthProperly()
{
const float scale = 2;
IShape shape = CreateShape();
float expectedWidth = shape.Width * scale;
shape.ScaleX(scale);
Assert.AreEqual(expectedWidth, shape.Width, "The shape's Width " +
"property does not report a value that has been scaled by 2 " +
"even though the Shape that has been scaled by 2 in the X.");
}
[Test, Description("Ensures the width is properly magnified after the " +
"shape has been scaled in the Y.")]
public void ScalesHeightProperly()
{
const float scale = 2;
IShape shape = CreateShape();
float expectedHeight = shape.Height * scale;
shape.ScaleY(scale);
Assert.AreEqual(expectedHeight, shape.Height, "The shape's Height " +
"property does not report a value that has been scaled by 2 " +
"even though the Shape that has been scaled by 2 in the Y.");
}
[Test, Description("Ensures the depth is properly magnified after the " +
"shape has been scaled in the Z.")]
public void ScalesDepthProperly()
{
const float scale = 2;
IShape shape = CreateShape();
float expectedDepth = shape.Depth * scale;
shape.ScaleZ(scale);
Assert.AreEqual(expectedDepth, shape.Depth, "The shape's Depth " +
"property does not report a value that has been scaled by 2 " +
"even though the Shape that has been scaled by 2 in the Z.");
}
///
/// Creates the interface that is to be tested.
/// This method should always create a new instance and never reuse
/// instances.
///
/// The to test.
protected abstract IShape CreateShape();
///
/// The expected value of the property of
/// the that is created by the
/// method.
///
protected abstract float ExpectedWidth { get; }
///
/// The expected value of the property of
/// the that is created by the
/// method.
///
protected abstract float ExpectedHeight { get; }
///
/// The expected value of the property of
/// the that is created by the
/// method.
///
protected abstract float ExpectedDepth { get; }
///
/// The expected value of the property of
/// the that is created by the
/// method.
///
protected abstract bool ExpectedIsConvex { get; }
///
/// The expected value of the property of
/// the that is created by the
/// method.
///
protected abstract float ExpectedArea { get; }
///
/// The expected value of the property of
/// the that is created by the
/// method.
///
protected abstract float ExpectedVolume { get; }
///
/// The expected value of the property of
/// the that is created by the
/// method.
///
protected abstract float ExpectedPerimeter { get; }
///
/// The expected value of the property of
/// the that is created by the
/// method.
///
protected abstract uint ExpectedDimensions { get; }
///
/// Creates the that is to be tested. This
/// method should always be create a new when
/// it is invoked and never reuse instances.
///
///
/// The instance that is to be tested.
///
protected override ITransform CreateTransform()
{
return CreateShape();
}
}
}