Split vector test scopes to make it easier to add tests in between, refs 99494251a1
.
This was SVN commit r20454.
This commit is contained in:
parent
260c78cc1a
commit
57e547bd32
@ -2,7 +2,7 @@ var brokenVector = {
|
||||
"lengthSquared": () => "incompatible vector"
|
||||
};
|
||||
|
||||
// Test Vector2D
|
||||
// Test Vector2D add, mult, distance
|
||||
{
|
||||
let v1 = new Vector2D();
|
||||
TS_ASSERT_EQUALS(v1.x, 0);
|
||||
@ -18,7 +18,10 @@ var brokenVector = {
|
||||
v2.add(new Vector2D(1, 2));
|
||||
TS_ASSERT_EQUALS(v2.x, 10);
|
||||
TS_ASSERT_EQUALS(v2.y, 14);
|
||||
}
|
||||
|
||||
// Test Vector2D normalization
|
||||
{
|
||||
let v3 = new Vector2D(0, 5).normalize();
|
||||
TS_ASSERT_EQUALS(v3.x, 0);
|
||||
TS_ASSERT_EQUALS(v3.y, 1);
|
||||
@ -26,7 +29,10 @@ var brokenVector = {
|
||||
v3.set(-8, 0).normalize();
|
||||
TS_ASSERT_EQUALS(v3.x, -1);
|
||||
TS_ASSERT_EQUALS(v3.y, 0);
|
||||
}
|
||||
|
||||
// Test Vector2D rotation
|
||||
{
|
||||
let v4 = new Vector2D(2, -5).rotate(4 * Math.PI);
|
||||
TS_ASSERT_EQUALS(v4.x, 2);
|
||||
TS_ASSERT_EQUALS(v4.y, -5);
|
||||
@ -60,7 +66,6 @@ var brokenVector = {
|
||||
];
|
||||
|
||||
let epsilon = 0.00000001;
|
||||
|
||||
for (let expectedVector of unitCircle)
|
||||
{
|
||||
let computedVector = new Vector2D(1, 0).rotate(-expectedVector.angle);
|
||||
@ -71,9 +76,20 @@ var brokenVector = {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test Vector2D dot product
|
||||
{
|
||||
TS_ASSERT_EQUALS(new Vector2D(2, 3).dot(new Vector2D(4, 5)), 23);
|
||||
}
|
||||
|
||||
// Test Vector2D cross product
|
||||
{
|
||||
TS_ASSERT_EQUALS(new Vector2D(3, 5).cross(new Vector2D(-4, -1/3)), 19);
|
||||
}
|
||||
|
||||
// Test Vector2D length and compareLength
|
||||
{
|
||||
TS_ASSERT_EQUALS(new Vector2D(20, 21).length(), 29);
|
||||
|
||||
let v5 = new Vector2D(10, 20);
|
||||
@ -81,12 +97,20 @@ var brokenVector = {
|
||||
TS_ASSERT_EQUALS(v5.compareLength(new Vector2D(500, 800)), -1);
|
||||
TS_ASSERT_EQUALS(v5.compareLength(new Vector2D(10, 20)), 0);
|
||||
TS_ASSERT(isNaN(v5.compareLength(brokenVector)));
|
||||
}
|
||||
|
||||
// Test Vector2D rotation furthermore
|
||||
{
|
||||
let epsilon = 0.00000001;
|
||||
let v5 = new Vector2D(10, 20);
|
||||
let v6 = v5.clone();
|
||||
TS_ASSERT_EQUALS(v5.x, v6.x);
|
||||
TS_ASSERT_EQUALS(v5.y, v6.y);
|
||||
TS_ASSERT(Math.abs(v5.dot(v6.rotate(Math.PI / 2))) < epsilon);
|
||||
}
|
||||
|
||||
// Test Vector2D perpendicular
|
||||
{
|
||||
let v7 = new Vector2D(4, 5).perpendicular();
|
||||
TS_ASSERT_EQUALS(v7.x, -5);
|
||||
TS_ASSERT_EQUALS(v7.y, 4);
|
||||
@ -96,25 +120,37 @@ var brokenVector = {
|
||||
TS_ASSERT_EQUALS(v8.y, 0);
|
||||
}
|
||||
|
||||
// Test Vector3D
|
||||
// Test Vector3D distance and compareLength
|
||||
{
|
||||
let v1 = new Vector3D(2, 5, 14);
|
||||
TS_ASSERT_EQUALS(v1.distanceTo(new Vector3D()), 15);
|
||||
TS_ASSERT(isNaN(v1.compareLength(brokenVector)));
|
||||
}
|
||||
|
||||
let v2 = v1.mult(3);
|
||||
// Test Vector3D mult
|
||||
{
|
||||
let v2 = new Vector3D(2, 5, 14).mult(3);
|
||||
TS_ASSERT_EQUALS(v2.x, 6);
|
||||
TS_ASSERT_EQUALS(v2.y, 15);
|
||||
TS_ASSERT_EQUALS(v2.z, 42);
|
||||
}
|
||||
|
||||
// Test Vector3D dot product
|
||||
{
|
||||
TS_ASSERT_EQUALS(new Vector3D(1, 2, 3).dot(new Vector3D(4, 5, 6)), 32);
|
||||
}
|
||||
|
||||
// Test Vector3D clone
|
||||
{
|
||||
let v3 = new Vector3D(9, 10, 11);
|
||||
let v4 = v3.clone();
|
||||
TS_ASSERT_EQUALS(v3.x, v4.x);
|
||||
TS_ASSERT_EQUALS(v3.y, v4.y);
|
||||
TS_ASSERT_EQUALS(v3.z, v4.z);
|
||||
}
|
||||
|
||||
// Test Vector3D cross product
|
||||
{
|
||||
let v5 = new Vector3D(1, 2, 3).cross(new Vector3D(4, 5, 6));
|
||||
TS_ASSERT_EQUALS(v5.x, -3);
|
||||
TS_ASSERT_EQUALS(v5.y, 6);
|
||||
|
Loading…
Reference in New Issue
Block a user