Files
sbox-public/engine/Tests/Sandbox.Test.Unit/Math/TriangleTest.cs
Garry Newman d95169d8fa Unit Test Cleanup (#5064)
* Move all unit tests to Engine/Tests
* Fix Margin.EdgeSubtract
* Fix Capsule.Contains
* EnvironmentVariables.Remove if it's null
* Fixed ray trace never returning startedsolid
* Fix HistoryList.Navigate on empty list
* Fix GameObject.WorldPosition accepting NaNs
* Fix flex: initial expanding to the wrong grow/shrink
* Translation.TryConvert shouldn't throw on invalid enum strings
* Skip sound file tests on machines with no audio device
2026-06-12 13:23:50 +01:00

52 lines
1.4 KiB
C#

using System;
namespace MathTests;
[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( 2.0f + MathF.Sqrt( 2.0f ), triangle.Perimeter, 0.0001f );
}
[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 ) );
}
}