mirror of
https://github.com/Facepunch/sbox-public.git
synced 2025-12-23 22:48:07 -05:00
- Added Sandbox.Test.Unit project (contains independent tests that can run in parallel) - Modify some slow/stress tests (e.g. instead of doing a million iterations settle for 10k). Tests run almost twice as fast now.
50 lines
1.3 KiB
C#
50 lines
1.3 KiB
C#
namespace SystemTest;
|
|
|
|
[TestClass]
|
|
public class TriangleTest
|
|
{
|
|
[TestMethod]
|
|
public void TestTrianglePerimeter()
|
|
{
|
|
Triangle triangle = new Triangle( new Vector3( 0, 0, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 1, 0, 0 ) );
|
|
|
|
Assert.AreEqual( 3.4142137f, triangle.Perimeter );
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestTriangleArea()
|
|
{
|
|
Triangle triangle = new Triangle( new Vector3( 0, 0, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 1, 0, 0 ) );
|
|
|
|
Assert.AreEqual( triangle.Area, 0.5f );
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestTriangleIsRight()
|
|
{
|
|
Triangle triangle = new Triangle( new Vector3( 0, 0, 0 ), new Vector3( 0, 3, 0 ), new Vector3( 4, 0, 0 ) );
|
|
|
|
Assert.IsTrue( triangle.IsRight );
|
|
}
|
|
|
|
|
|
[TestMethod]
|
|
public void TestClosestPointWithPointOutsideTriangle()
|
|
{
|
|
Triangle triangle = new Triangle( new Vector3( -1, 0, 0 ), new Vector3( 0, 2, 0 ), new Vector3( 1, 0, 0 ) );
|
|
Vector3 closestPoint = triangle.ClosestPoint( new Vector3( -1000, 0, 0 ) );
|
|
|
|
Assert.AreEqual( closestPoint, new Vector3( -1, 0, 0 ) );
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestClosestPointWithPointInsideTriangle()
|
|
{
|
|
Triangle triangle = new Triangle( new Vector3( -100, 0, 0 ), new Vector3( 0, 100, 0 ), new Vector3( 100, 0, 0 ) );
|
|
Vector3 closestPoint = triangle.ClosestPoint( new Vector3( 10, 15, 0 ) );
|
|
|
|
Assert.IsTrue( closestPoint == new Vector3( 10, 15, 0 ) );
|
|
}
|
|
|
|
}
|