From 12eb89adbb07289f0182dcd3c1d3c8cb9788d94f Mon Sep 17 00:00:00 2001 From: Michael L Smith Date: Mon, 15 Feb 2016 20:30:46 -0800 Subject: [PATCH] Added some tests for known expected interpolation positions. --- OSCADSharp/OSCADSharp.ConsoleTests/Program.cs | 2 +- .../InterpolationTests.cs | 119 ++++++++++++++++++ .../OSCADSharp.UnitTests.csproj | 1 + 3 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 OSCADSharp/OSCADSharp.UnitTests/InterpolationTests.cs diff --git a/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs b/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs index 535df3f..024607b 100644 --- a/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs +++ b/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs @@ -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); diff --git a/OSCADSharp/OSCADSharp.UnitTests/InterpolationTests.cs b/OSCADSharp/OSCADSharp.UnitTests/InterpolationTests.cs new file mode 100644 index 0000000..396369a --- /dev/null +++ b/OSCADSharp/OSCADSharp.UnitTests/InterpolationTests.cs @@ -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()); + } + } +} diff --git a/OSCADSharp/OSCADSharp.UnitTests/OSCADSharp.UnitTests.csproj b/OSCADSharp/OSCADSharp.UnitTests/OSCADSharp.UnitTests.csproj index 31cac6c..bdc0d30 100644 --- a/OSCADSharp/OSCADSharp.UnitTests/OSCADSharp.UnitTests.csproj +++ b/OSCADSharp/OSCADSharp.UnitTests/OSCADSharp.UnitTests.csproj @@ -55,6 +55,7 @@ +