Skip to content

Commit

Permalink
add tests for vec3.direction
Browse files Browse the repository at this point in the history
  • Loading branch information
sinisterchipmunk committed Nov 29, 2011
1 parent be41d2d commit e22d887
Showing 1 changed file with 40 additions and 9 deletions.
49 changes: 40 additions & 9 deletions spec/javascripts/vec3_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe("vec3", function() {
var vec, dest;
var vec, vecB, dest;

describe("when Float32Array is not supported", function() {
beforeEach(function() { setMatrixArrayType(Array); });
Expand Down Expand Up @@ -124,7 +124,7 @@ describe("vec3", function() {
});

describe("normalize", function() {
var NORMAL = [0.2672612419124244, 0.5345224838248488, 0.8017837257372732];
var NORMAL = [0.267261, 0.534522, 0.801783];
beforeEach(function() { vec = vec3.create([1,2,3]); });

it("should return [0,0,0] if vector magnitude is 0", function() {
Expand Down Expand Up @@ -153,28 +153,28 @@ describe("vec3", function() {
var CROSS = [-3, 6, -3];
beforeEach(function() {
vec = vec3.create([1,2,3]);
vec2 = vec3.create([4,5,6]);
vecB = vec3.create([4,5,6]);
});

it("should modify original vector if dest not given", function() {
vec3.cross(vec, vec2);
vec3.cross(vec, vecB);
expect(vec).toBeEqualish(CROSS);
});

it("should not modify vec2", function() {
expect(vec2).toBeEqualish([4,5,6]);
it("should not modify vecB", function() {
expect(vecB).toBeEqualish([4,5,6]);
});

it("should modify original mvector if dest is original vector", function() {
vec3.cross(vec, vec2, vec);
vec3.cross(vec, vecB, vec);
expect(vec).toBeEqualish(CROSS);
});

describe("if dest vector is given", function() {
beforeEach(function() { vec3.cross(vec, vec2, dest = vec3.create()); });
beforeEach(function() { vec3.cross(vec, vecB, dest = vec3.create()); });

it("should not modify original vector", function() { expect(vec).toBeEqualish([1,2,3]); });
it("should not modify vec2", function() { expect(vec2).toBeEqualish([4,5,6]); });
it("should not modify vecB", function() { expect(vecB).toBeEqualish([4,5,6]); });
it("should modify dest vector", function() { expect(dest).toBeEqualish(CROSS); });
});
});
Expand All @@ -188,4 +188,35 @@ describe("vec3", function() {
describe("dot", function() {
it("should return dot product", function() { expect(vec3.dot([1,2,3], [-4,5,6])).toBeEqualish(24); });
});

describe("direction", function() {
var DIR = [0.267261, 0.534522, 0.801783];

beforeEach(function() {
vec = vec3.create([1,2,3]);
vecB = vec3.create([-1,-2,-3]);
});

it("should modify original vector if dest not given", function() {
vec3.direction(vec, vecB);
expect(vec).toBeEqualish(DIR);
});

it("should modify original vector if dest is original vector", function() {
vec3.direction(vec, vecB, vec);
expect(vec).toBeEqualish(DIR);
});

it("should not modify vecB", function() {
vec3.direction(vec, vecB);
expect(vecB).toBeEqualish([-1,-2,-3]);
});

describe("if dest vector is given", function() {
beforeEach(function() { vec3.direction(vec, vecB, dest = vec3.create()); });
it("should not modify vec", function() { expect(vec).toBeEqualish([1,2,3]); });
it("should not modify vecB", function() { expect(vecB).toBeEqualish([-1,-2,-3]); });
it("should modify dest", function() { expect(dest).toBeEqualish(DIR); });
});
});
});

0 comments on commit e22d887

Please sign in to comment.