Add unit tests for Geometry.Rotate(Vector2).
Fixes #20. GitOrigin-RevId: 45cd5e99a2c841235e2d9ed29744fe22900ce167
This commit is contained in:
parent
1ffe1444b2
commit
a32ef2a0eb
@ -5,6 +5,41 @@ using System;
|
|||||||
namespace SemiColinGames.Tests {
|
namespace SemiColinGames.Tests {
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class GeometryTests {
|
public class GeometryTests {
|
||||||
|
|
||||||
|
public void AssertVectorsAreEqual(Vector2 v1, Vector2 v2) {
|
||||||
|
Assert.AreEqual(v1.X, v2.X, 1e-5);
|
||||||
|
Assert.AreEqual(v1.Y, v2.Y, 1e-5);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void TestVector2Rotate() {
|
||||||
|
Vector2 v = new Vector2(10, 0);
|
||||||
|
AssertVectorsAreEqual(new Vector2(10, 0), v.Rotate(FMath.DegToRad(0)));
|
||||||
|
AssertVectorsAreEqual(new Vector2(0, 10), v.Rotate(FMath.DegToRad(90)));
|
||||||
|
AssertVectorsAreEqual(new Vector2(-10, 0), v.Rotate(FMath.DegToRad(180)));
|
||||||
|
AssertVectorsAreEqual(new Vector2(0, -10), v.Rotate(FMath.DegToRad(270)));
|
||||||
|
AssertVectorsAreEqual(new Vector2(10, 0), v.Rotate(FMath.DegToRad(360)));
|
||||||
|
AssertVectorsAreEqual(new Vector2(0, 10), v.Rotate(FMath.DegToRad(450)));
|
||||||
|
|
||||||
|
AssertVectorsAreEqual(new Vector2(0, -10), v.Rotate(FMath.DegToRad(-90)));
|
||||||
|
AssertVectorsAreEqual(new Vector2(-10, 0), v.Rotate(FMath.DegToRad(-180)));
|
||||||
|
AssertVectorsAreEqual(new Vector2(0, 10), v.Rotate(FMath.DegToRad(-270)));
|
||||||
|
AssertVectorsAreEqual(new Vector2(10, 0), v.Rotate(FMath.DegToRad(-360)));
|
||||||
|
AssertVectorsAreEqual(new Vector2(0, -10), v.Rotate(FMath.DegToRad(-450)));
|
||||||
|
|
||||||
|
AssertVectorsAreEqual(new Vector2(7.0710678f, 7.0710678f), v.Rotate(FMath.DegToRad(45)));
|
||||||
|
AssertVectorsAreEqual(new Vector2(8.6602540f, 5f), v.Rotate(FMath.DegToRad(30)));
|
||||||
|
AssertVectorsAreEqual(new Vector2(5f, 8.6602540f), v.Rotate(FMath.DegToRad(60)));
|
||||||
|
AssertVectorsAreEqual(new Vector2(-5f, 8.6602540f), v.Rotate(FMath.DegToRad(120)));
|
||||||
|
AssertVectorsAreEqual(new Vector2(-8.6602540f, 5f), v.Rotate(FMath.DegToRad(150)));
|
||||||
|
|
||||||
|
AssertVectorsAreEqual(new Vector2(7.0710678f, -7.0710678f), v.Rotate(FMath.DegToRad(-45)));
|
||||||
|
AssertVectorsAreEqual(new Vector2(8.6602540f, -5f), v.Rotate(FMath.DegToRad(-30)));
|
||||||
|
AssertVectorsAreEqual(new Vector2(5f, -8.6602540f), v.Rotate(FMath.DegToRad(-60)));
|
||||||
|
AssertVectorsAreEqual(new Vector2(-5f, -8.6602540f), v.Rotate(FMath.DegToRad(-120)));
|
||||||
|
AssertVectorsAreEqual(new Vector2(-8.6602540f, -5f), v.Rotate(FMath.DegToRad(-150)));
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void TestIntersectSegmentNotColliding() {
|
public void TestIntersectSegmentNotColliding() {
|
||||||
AABB box = new AABB(new Vector2(0, 0), new Vector2(8, 8));
|
AABB box = new AABB(new Vector2(0, 0), new Vector2(8, 8));
|
||||||
|
Loading…
Reference in New Issue
Block a user