Added some tests for known expected interpolation positions.

This commit is contained in:
Michael L Smith 2016-02-15 20:30:46 -08:00
parent 1be343fadc
commit 12eb89adbb
3 changed files with 121 additions and 1 deletions

View File

@ -13,7 +13,7 @@ namespace OSCADSharp.ConsoleTests
{
static void Main(string[] args)
{
var cube = new Cube(50, 50, 50, true).Translate(30, 30, 30).Rotate(25, 45, -90);
var cube = new Cube(13, 13, 13).Rotate(90, 37.5, -180);
var pos = cube.Position();
var cyl1 = new Cylinder(1, 100, true).Translate(pos);

View File

@ -0,0 +1,119 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OSCADSharp.Solids;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OSCADSharp.UnitTests
{
[TestClass]
public class InterpolationTests
{
//Positive X rotation
[TestMethod]
public void Interpolation_RotateOnXAxis()
{
var cube = new Cube(9, 9, 9).Rotate(90, 0, 0);
//Rotating on X axis by 90 should shift the center of the cube on the negative Y quadrant
Assert.AreEqual(new Vector3(4.5, -4.5, 4.5), cube.Position());
}
//Negative X rotation
[TestMethod]
public void Interpolation_NegativeRotationOnXAxis()
{
var cube = new Cube(11, 11, 11).Rotate(-90, 0, 0);
//Rotating on X axis by -90 should shift the center of the cube on the negative Z quadrant
Assert.AreEqual(new Vector3(5.5, 5.5, -5.5), cube.Position());
}
//Y Rotation
[TestMethod]
public void Interpolation_PositiveYRotationWithTallCube()
{
var cube = new Cube(10, 12, 23).Rotate(0, 90, 0);
//Rotating on Y axis by 90 should shift the center of the cube on the negative Z quadrant
Assert.AreEqual(new Vector3(11.5, 6, -5), cube.Position());
}
//Negative Y rotation
[TestMethod]
public void Interpolation_NegativeYRotationWithWideCube()
{
var cube = new Cube(10, 30, 15).Rotate(0, -90, 0);
//Rotating on Y axis by -90 should shift the center of the cube on the negative X quadrant
Assert.AreEqual(new Vector3(-7.5, 15, 5), cube.Position());
}
//Z Rotation
[TestMethod]
public void Interpolation_ZRotationWithLongCube()
{
var cube = new Cube(10, 5, 2).Rotate(0, 0, 115);
//Rotating on Z axis by 90 should shift the center of the cube on the negative X quadrant
Assert.AreEqual(new Vector3(-4.37886077629512, 3.4749932808315, 1), cube.Position());
}
//Negative Z rotation
[TestMethod]
public void Interpolation_NegativeZRotation()
{
var cube = new Cube(10, 5, 2).Rotate(0, 0, -95);
//Rotating on Z axis by 90 should shift the center of the cube on the negative Y quadrant
Assert.AreEqual(new Vector3(2.05470803149107, -5.19886284732787, 1), cube.Position());
}
//Centered rotation (no change)
[TestMethod]
public void Interpolation_CenteredCubePositionNotUpdatedWhenRotated()
{
var cube = new Cube(5, 20, 20, true).Rotate(15, -120, 270);
Assert.AreEqual(new Vector3(), cube.Position());
}
//X and Y rotation
[TestMethod]
public void Interpolation_XAndYRotation()
{
var cube = new Cube(5, 5, 5).Rotate(120, 45, 0);
Assert.AreEqual(new Vector3(2.41481456572267, -3.4150635094611, -1.12071934021007), cube.Position());
}
//Y and Z rotation
[TestMethod]
public void Interpolation_YandZRotation()
{
var cube = new Cube(13, 13, 13).Rotate(0, 270, -35);
Assert.AreEqual(new Vector3(-1.59624145159665, 9.05273512416025, 6.5), cube.Position());
}
//X and Z rotation
[TestMethod]
public void Interpolation_XandZRotation()
{
var cube = new Cube(13, 13, 13).Rotate(-145, 0, 190);
Assert.AreEqual(new Vector3(-6.67843481376553, 0.443277802376793, -9.05273512416025), cube.Position());
}
//X, Y and Z rotation
[TestMethod]
public void Interpolation_XYZRotation()
{
var cube = new Cube(13, 13, 13).Rotate(90, 37.5, -180);
Assert.AreEqual(new Vector3(-9.11374600044971, 6.5, 1.19984742333634), cube.Position());
}
}
}

View File

@ -55,6 +55,7 @@
<Compile Include="CubeTests.cs" />
<Compile Include="CylinderTests.cs" />
<Compile Include="HullTests.cs" />
<Compile Include="InterpolationTests.cs" />
<Compile Include="OSCADObjectTests.cs" />
<Compile Include="SphereTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />