< Summary

Class:Coordinates3Tests
Assembly:bamlab.test.editmode
File(s):/github/workspace/Assets/Tests/EditMode/CoordinatesTests.cs
Covered lines:0
Uncovered lines:56
Coverable lines:56
Total lines:158
Line coverage:0% (0 of 56)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:8
Method coverage:0% (0 of 8)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
TestCartesianToSphericalOrigin()0%2100%
TestCartesianToSpherical()0%2100%
TestSphericalToCartesianOrigin()0%2100%
TestSphericalToCartesian()0%2100%
TestCylindricalToCartesianOrigin()0%2100%
TestCylindricalToCartesian()0%2100%
TestCartesianToCylindricalOrigin()0%2100%
TestCartesianToCylindrical()0%2100%

File(s)

/github/workspace/Assets/Tests/EditMode/CoordinatesTests.cs

#LineLine coverage
 1using NUnit.Framework;
 2using UnityEngine;
 3using UnityEngine.TestTools;
 4
 5public class Coordinates2Tests {
 6  private const float Epsilon = 0.0001f;
 7
 8  [Test]
 9  public void TestCartesianToPolarOrigin() {
 10    Vector2 cartesian = Vector2.zero;
 11    Assert.That(Coordinates2.ConvertCartesianToPolar(cartesian).x, Is.EqualTo(0).Within(Epsilon));
 12  }
 13
 14  [Test]
 15  public void TestCartesianToPolarXAxis() {
 16    Vector2 cartesian = new Vector2(5, 0);
 17    Vector2 expectedPolar = new Vector2(5.0f, 0.0f);
 18    Vector2 actualPolar = Coordinates2.ConvertCartesianToPolar(cartesian);
 19    Assert.That(actualPolar.x, Is.EqualTo(expectedPolar.x).Within(Epsilon));
 20    Assert.That(actualPolar.y, Is.EqualTo(expectedPolar.y).Within(Epsilon));
 21  }
 22
 23  [Test]
 24  public void TestCartesianToPolarYAxis() {
 25    Vector2 cartesian = new Vector2(0, 5);
 26    Vector2 expectedPolar = new Vector2(5.0f, 90.0f);
 27    Vector2 actualPolar = Coordinates2.ConvertCartesianToPolar(cartesian);
 28    Assert.That(actualPolar.x, Is.EqualTo(expectedPolar.x).Within(Epsilon));
 29    Assert.That(actualPolar.y, Is.EqualTo(expectedPolar.y).Within(Epsilon));
 30  }
 31
 32  [Test]
 33  public void TestPolarToCartesianOrigin() {
 34    Vector2 expectedCartesian = Vector2.zero;
 35    Vector2[] polarInputs = new[] { new Vector2(0, 0), new Vector2(0, 45), new Vector2(0, 90),
 36                                    new Vector2(0, 180), new Vector2(0, 360) };
 37
 38    foreach (var polar in polarInputs) {
 39      Vector2 actualCartesian = Coordinates2.ConvertPolarToCartesian(polar);
 40      Assert.That(actualCartesian.x, Is.EqualTo(expectedCartesian.x).Within(Epsilon));
 41      Assert.That(actualCartesian.y, Is.EqualTo(expectedCartesian.y).Within(Epsilon));
 42    }
 43  }
 44
 45  [Test]
 46  public void TestPolarToCartesianXAxis() {
 47    Vector2 polar = new Vector2(10, 0);
 48    Vector2 expectedCartesian = new Vector2(10.0f, 0.0f);
 49    Vector2 actualCartesian = Coordinates2.ConvertPolarToCartesian(polar);
 50    Assert.That(actualCartesian.x, Is.EqualTo(expectedCartesian.x).Within(Epsilon));
 51    Assert.That(actualCartesian.y, Is.EqualTo(expectedCartesian.y).Within(Epsilon));
 52  }
 53
 54  [Test]
 55  public void TestPolarToCartesianYAxis() {
 56    Vector2 polar = new Vector2(10, 90);
 57    Vector2 expectedCartesian = new Vector2(0.0f, 10.0f);
 58    Vector2 actualCartesian = Coordinates2.ConvertPolarToCartesian(polar);
 59    Assert.That(actualCartesian.x, Is.EqualTo(expectedCartesian.x).Within(Epsilon));
 60    Assert.That(actualCartesian.y, Is.EqualTo(expectedCartesian.y).Within(Epsilon));
 61  }
 62
 63  [Test]
 64  public void TestPolarToCartesian30() {
 65    Vector2 polar = new Vector2(20, 30);
 66    Vector2 expectedCartesian = new Vector2(10 * Mathf.Sqrt(3), 10);
 67    Vector2 actualCartesian = Coordinates2.ConvertPolarToCartesian(polar);
 68    Assert.That(actualCartesian.x, Is.EqualTo(expectedCartesian.x).Within(Epsilon));
 69    Assert.That(actualCartesian.y, Is.EqualTo(expectedCartesian.y).Within(Epsilon));
 70  }
 71
 72  [Test]
 73  public void TestPolarToCartesian45() {
 74    Vector2 polar = new Vector2(10 * Mathf.Sqrt(2), 45);
 75    Vector2 expectedCartesian = new Vector2(10.0f, 10.0f);
 76    Vector2 actualCartesian = Coordinates2.ConvertPolarToCartesian(polar);
 77    Assert.That(actualCartesian.x, Is.EqualTo(expectedCartesian.x).Within(Epsilon));
 78    Assert.That(actualCartesian.y, Is.EqualTo(expectedCartesian.y).Within(Epsilon));
 79  }
 80}
 81
 82public class Coordinates3Tests {
 83  private const float Epsilon = 0.0001f;
 84
 85  [Test]
 086  public void TestCartesianToSphericalOrigin() {
 087    Vector3 cartesian = Vector3.zero;
 088    Assert.That(Coordinates3.ConvertCartesianToSpherical(cartesian).x,
 89                Is.EqualTo(0).Within(Epsilon));
 090  }
 91
 92  [Test]
 093  public void TestCartesianToSpherical() {
 094    Vector3 cartesian = new Vector3(2, -1, 3);
 095    Vector3 expectedSpherical = new Vector3(Mathf.Sqrt(14), 33.690068f, -15.501360f);
 096    Vector3 actualSpherical = Coordinates3.ConvertCartesianToSpherical(cartesian);
 097    Assert.That(actualSpherical.x, Is.EqualTo(expectedSpherical.x).Within(Epsilon));
 098    Assert.That(actualSpherical.y, Is.EqualTo(expectedSpherical.y).Within(Epsilon));
 099    Assert.That(actualSpherical.z, Is.EqualTo(expectedSpherical.z).Within(Epsilon));
 0100  }
 101
 102  [Test]
 0103  public void TestSphericalToCartesianOrigin() {
 0104    Vector3 spherical = new Vector3(0, 45, 90);
 0105    Vector3 expectedCartesian = Vector3.zero;
 0106    Vector3 actualCartesian = Coordinates3.ConvertSphericalToCartesian(spherical);
 0107    Assert.That(actualCartesian.x, Is.EqualTo(expectedCartesian.x).Within(Epsilon));
 0108    Assert.That(actualCartesian.y, Is.EqualTo(expectedCartesian.y).Within(Epsilon));
 0109    Assert.That(actualCartesian.z, Is.EqualTo(expectedCartesian.z).Within(Epsilon));
 0110  }
 111
 112  [Test]
 0113  public void TestSphericalToCartesian() {
 0114    Vector3 spherical = new Vector3(10, 60, 30);
 0115    Vector3 expectedCartesian = new Vector3(7.5f, 5.0f, 4.3301270189221945f);
 0116    Vector3 actualCartesian = Coordinates3.ConvertSphericalToCartesian(spherical);
 0117    Assert.That(actualCartesian.x, Is.EqualTo(expectedCartesian.x).Within(Epsilon));
 0118    Assert.That(actualCartesian.y, Is.EqualTo(expectedCartesian.y).Within(Epsilon));
 0119    Assert.That(actualCartesian.z, Is.EqualTo(expectedCartesian.z).Within(Epsilon));
 0120  }
 121
 122  [Test]
 0123  public void TestCylindricalToCartesianOrigin() {
 0124    Vector3 cylindrical = new Vector3(0, 45, 0);
 0125    Vector3 expectedCartesian = Vector3.zero;
 0126    Vector3 actualCartesian = Coordinates3.ConvertCylindricalToCartesian(cylindrical);
 0127    Assert.That(actualCartesian.x, Is.EqualTo(expectedCartesian.x).Within(Epsilon));
 0128    Assert.That(actualCartesian.y, Is.EqualTo(expectedCartesian.y).Within(Epsilon));
 0129    Assert.That(actualCartesian.z, Is.EqualTo(expectedCartesian.z).Within(Epsilon));
 0130  }
 131
 132  [Test]
 0133  public void TestCylindricalToCartesian() {
 0134    Vector3 cylindrical = new Vector3(10, 60, 2);
 0135    Vector3 expectedCartesian = new Vector3(8.660254f, 2.0f, 5.0f);
 0136    Vector3 actualCartesian = Coordinates3.ConvertCylindricalToCartesian(cylindrical);
 0137    Assert.That(actualCartesian.x, Is.EqualTo(expectedCartesian.x).Within(Epsilon));
 0138    Assert.That(actualCartesian.y, Is.EqualTo(expectedCartesian.y).Within(Epsilon));
 0139    Assert.That(actualCartesian.z, Is.EqualTo(expectedCartesian.z).Within(Epsilon));
 0140  }
 141
 142  [Test]
 0143  public void TestCartesianToCylindricalOrigin() {
 0144    Vector3 cartesian = Vector3.zero;
 0145    Assert.That(Coordinates3.ConvertCartesianToCylindrical(cartesian).x,
 146                Is.EqualTo(0).Within(Epsilon));
 0147  }
 148
 149  [Test]
 0150  public void TestCartesianToCylindrical() {
 0151    Vector3 cartesian = new Vector3(2, -1, 3);
 0152    Vector3 expectedCylindrical = new Vector3(Mathf.Sqrt(13), 33.6900675f, -1);
 0153    Vector3 actualCylindrical = Coordinates3.ConvertCartesianToCylindrical(cartesian);
 0154    Assert.That(actualCylindrical.x, Is.EqualTo(expectedCylindrical.x).Within(Epsilon));
 0155    Assert.That(actualCylindrical.y, Is.EqualTo(expectedCylindrical.y).Within(Epsilon));
 0156    Assert.That(actualCylindrical.z, Is.EqualTo(expectedCylindrical.z).Within(Epsilon));
 0157  }
 158}