Skip to content

Commit

Permalink
Added script test directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
luciusDXL committed Dec 14, 2024
1 parent 97932a8 commit 444054e
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions TheForceEngine/ScriptTests/Test_VectorMath.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/////////////////////////////////////////////////////////////
// Vector Math Tests
/////////////////////////////////////////////////////////////

// Swizzle
void test_float2_swizzle()
{
test.beginTest("float2_swizzle");
float2 a = float2(1, 2);
// float2 -> float2 swizzles.
test.expectEq(a.xy, float2(1,2));
test.expectEq(a.yx, float2(2,1));
test.expectEq(a.xx, float2(1,1));
test.expectEq(a.yy, float2(2,2));
// float2 -> scalar swizzles.
test.expectEq(a.x, 1.0f);
test.expectEq(a.y, 2.0f);
}

// float2 x float2 math
void test_float2_float2_math()
{
test.beginTest("float2_float2_math");
float2 a = float2(1, 2);
float2 b = float2(3, 4);
float2 c = float2(0, 1);
test.expectEq(a + b, float2(4, 6));
test.expectEq(a - b, float2(-2, -2));
test.expectEq(a * b, float2(3, 8));
test.expectEq(a / b, float2(1.0/3.0, 2.0/4.0));

const float neg45 = math.radians(-45.0); // -45 degrees in radians.
// Only concern ourselves with math functions that effect vector types,
// scalar/per-component functions should be tested separately.
test.expectEq(math.distance(a, b), 2.828427125f);
test.expectEq(math.dot(a, b), 11.0f);
test.expectEq(math.length(a), 2.2360679775f);
test.expectEq(math.normalize(a), float2(0.4472135955, 0.894427191));
test.expectEq(math.perp(a, b), -2.0f);
test.expectEq(math.sincos(neg45), float2(-0.7071067812, 0.7071067812));

test.expectTrue(math.all(a));
test.expectTrue(math.any(a));
test.expectFalse(math.all(c));
test.expectTrue(math.any(c));
}

// float2 x scalar math
void test_float2_scalar_math()
{
test.beginTest("float2_scalar_math");
float2 a = float2(3, 4);
test.expectEq(a * 0.0, float2(0));
test.expectEq(a * 1.0, float2(3, 4));
test.expectEq(a.yx * 0.5, float2(2.0, 1.5));

test.expectEq(a / 2.0, float2(1.5, 2));
test.expectEq(a + 2.0, float2(5, 6));
test.expectEq(a - 2.0, float2(1, 2));
test.expectEq(a * 2.0, float2(6, 8));
}

void main()
{
test.beginSystem("Vector Math");
{
test_float2_swizzle();
test_float2_float2_math();
test_float2_scalar_math();
}
test.report();
}

0 comments on commit 444054e

Please sign in to comment.