forked from AlanRynne/AR_Lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added more tests
- Loading branch information
Showing
6 changed files
with
722 additions
and
476 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,6 @@ branches: | |
only: | ||
- master | ||
- development | ||
|
||
notifications: | ||
slack: paramdigma:FtUcdwSDOynOHw2M479kXHxs |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
using Paramdigma.Core.Geometry; | ||
using Xunit; | ||
|
||
namespace Paramdigma.Core.Tests.Geometry | ||
{ | ||
public class Vector2dTests | ||
{ | ||
[Fact] | ||
public void Create_Origin() | ||
{ | ||
var empty = new Vector2d(0, 0); | ||
var expected = new Vector2d(0, 0); | ||
Assert.True(empty == expected); | ||
} | ||
|
||
[Fact] | ||
public void Create_FromPoint() | ||
{ | ||
var expected = new Vector2d(2.4, 2.5); | ||
var copy = new Vector2d(expected); | ||
Assert.True(expected == copy); | ||
} | ||
|
||
[Fact] | ||
public void CanBe_Added() | ||
{ | ||
const double a = 3.3; | ||
const double b = 2.2; | ||
const double c = 4.11; | ||
var ptA = new Vector2d(a, b); | ||
var ptB = new Vector2d(b, c); | ||
var s = ptA - ptB; | ||
var ptResult = new Vector2d(a + b, b + c); | ||
Assert.True(ptA + ptB == ptResult); | ||
} | ||
|
||
[Fact] | ||
public void CanBe_Substracted() | ||
{ | ||
const double a = 3.3; | ||
const double b = 2.2; | ||
const double c = 4.11; | ||
var ptA = new Vector2d(a, b); | ||
var ptB = new Vector2d(b, c); | ||
var ptResult = new Vector2d(a - b, b - c); | ||
Assert.True(ptA - ptB == ptResult); | ||
} | ||
|
||
[Fact] | ||
public void CanBe_Multiplied() | ||
{ | ||
const double a = 3.3; | ||
const double b = 2.2; | ||
const double m = 1.45; | ||
var ptA = new Vector2d(a, b); | ||
var ptResult = new Vector2d(a * m, b * m); | ||
Assert.True(ptA * m == ptResult); | ||
Assert.True(m * ptA == ptResult); | ||
} | ||
|
||
[Fact] | ||
public void CanBe_Divided() | ||
{ | ||
const double a = 3.3; | ||
const double b = 2.2; | ||
const double m = 1.45; | ||
var ptA = new Vector2d(a, b); | ||
var ptResult = new Vector2d(a / m, b / m); | ||
Assert.True(ptA / m == ptResult); | ||
} | ||
|
||
[Fact] | ||
public void CanBe_Negated() | ||
{ | ||
const double a = 3.3; | ||
const double b = 2.2; | ||
var ptA = new Vector2d(a, b); | ||
var ptResult = new Vector2d(-a, -b); | ||
Assert.True(-ptA == ptResult); | ||
} | ||
|
||
[Fact] | ||
public void EqualsAndHashCode_HaveConsistentResults() | ||
{ | ||
var pt = new Vector2d(1.000000009, -1); | ||
var pt2 = new Vector2d(1, -1); | ||
var b1 = pt == pt2; | ||
var b2 = pt.GetHashCode() == pt2.GetHashCode(); | ||
var other = "S"; | ||
Assert.True(b1 && b1 == b2); | ||
Assert.False(pt != pt2); | ||
Assert.False(pt.Equals(other)); | ||
} | ||
|
||
[Fact] | ||
public void CanBe_ConvertedTo() | ||
{ | ||
var pt = new Vector2d(0, 1); | ||
Point2d v = (Point2d)pt; | ||
Vector2d pt2 = v; | ||
Assert.True(pt == pt2); | ||
} | ||
|
||
[Fact] | ||
public void Can_AddVector() | ||
{ | ||
var pt = new Vector2d(0, 1); | ||
Point2d v = (Point2d)pt; | ||
Vector2d pt2 = pt + v; | ||
var expected = new Vector2d(0, 2); | ||
Assert.True(pt2 == expected); | ||
} | ||
|
||
[Fact] | ||
public void CanCompute_DotProduct() | ||
{ | ||
var v = new Vector2d(1, 2); | ||
var v2 = new Vector2d(3.211, -2.22); | ||
var dot = v.DotProduct(v2); | ||
} | ||
|
||
[Fact] | ||
public void CanCompute_PerpProduct() | ||
{ | ||
var v = new Vector2d(1, 2); | ||
var v2 = new Vector2d(3.211, -2.22); | ||
var dot = v.PerpProduct(v2); | ||
} | ||
|
||
[Fact] | ||
public void CanUnitize() | ||
{ | ||
var v = new Vector2d(5.2333, 0); | ||
v.Unitize(); | ||
var expected = new Vector2d(1, 0); | ||
Assert.True(v == expected); | ||
} | ||
|
||
[Fact] | ||
public void CanCompute_PerpendicularVector() | ||
{ | ||
var v = new Vector2d(1, 2); | ||
var expected = new Vector2d(-2, 1); | ||
var perp = v.Perp(); | ||
Assert.True(perp == expected); | ||
} | ||
|
||
[Fact] | ||
public void CanBe_ConvertedToString() | ||
{ | ||
var result = "Vector3d [1, 0]"; | ||
var v = new Vector2d(1, 0); | ||
var s = v.ToString(); | ||
Assert.True(s == result); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System; | ||
using Paramdigma.Core.Geometry; | ||
using Xunit; | ||
|
||
namespace Paramdigma.Core.Tests.Geometry | ||
{ | ||
public class PlaneTests | ||
{ | ||
[Fact] | ||
public void CanBe_Created() | ||
{ | ||
var plane = new Plane(Point3d.WorldOrigin); | ||
var planeB = new Plane(Point3d.WorldOrigin, Vector3d.UnitZ, Vector3d.UnitX); | ||
|
||
var ptA = new Point3d(1, 0, 0); | ||
var ptB = new Point3d(0, 1, 0); | ||
var ptC = new Point3d(0, 0, 0); | ||
var planeC = new Plane(ptC, ptA, ptB); | ||
} | ||
|
||
[Fact] | ||
public void CanCreate_SpecialPlanes() | ||
{ | ||
var ptXY = Plane.WorldXY; | ||
var ptYZ = Plane.WorldYZ; | ||
var ptXZ = Plane.WorldXZ; | ||
} | ||
|
||
[Fact] | ||
public void CanConvert_ToString() | ||
{ | ||
var pln = Plane.WorldXY; | ||
var s = pln.ToString(); | ||
Console.WriteLine(s); | ||
} | ||
|
||
[Fact] | ||
public void CanCompute_Points() | ||
{ | ||
var pln = Plane.WorldXY; | ||
var pt = pln.PointAt(1, 1); | ||
var expectedPt = new Point3d(1, 1, 0); | ||
var ptB = pln.PointAt(1, 1, 1); | ||
var expectedPtB = new Point3d(1, 1, 1); | ||
Assert.True(pt == expectedPt); | ||
Assert.True(ptB == expectedPtB); | ||
} | ||
|
||
[Fact] | ||
public void CanBe_Cloned() | ||
{ | ||
var pln = Plane.WorldXY; | ||
var plnB = pln.Clone(); | ||
var plnC = new Plane(pln); | ||
Assert.True(!ReferenceEquals(pln, plnB)); | ||
Assert.True(!ReferenceEquals(pln, plnC)); | ||
} | ||
|
||
[Fact] | ||
public void CanCompute_ClosestPoint() | ||
{ | ||
var pln = Plane.WorldXY; | ||
var pt = new Point3d(1, 1, 1); | ||
var expected = new Point3d(1, 1, 0); | ||
var result = pln.ClosestPoint(pt); | ||
var dist = pln.DistanceTo(pt); | ||
Assert.True(result == expected); | ||
Assert.True(dist == 1); | ||
} | ||
} | ||
} |