Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions tests/vector-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ var v = require('../').vector;
var should = require('should');

describe('Creating vectors: ', function () {
it('truly creates a vector', function () {
var a = new v(1);
a.isVector.should.eql(true);
});

it('Should pass with 3 arguments', function () {
var a = new v(1,0,0);
a.v.length.should.eql(3);
Expand Down Expand Up @@ -29,28 +34,54 @@ describe('Creating vectors: ', function () {

var a = new v(1,0,0);
var b = new v(1,1,0);
var d = new v(0,1,1);

describe('Between two vectors: ', function () {
it('should add two vectors easily', function () {
var c = a.add(b);
c.v.length.should.eql(3);
c.v.should.eql([ 2, 1, 0 ]);

var c = a.add(d);
c.v.length.should.eql(3);
c.v.should.eql([ 1, 1, 1 ]);
});

it('should calculate the dot product', function () {
var c = a.dot(b);
c.should.eql(1);

var c = a.dot(d);
c.should.eql(0);
});

it('should calculate the cross product', function () {
var c = a.cross(b);
c.v.length.should.eql(3);
c.v.should.eql([0,0,1]);

var c = b.cross(a);
c.v.length.should.eql(3);
c.v.should.eql([0,0,-1]);

var c = a.cross(d);
c.v.length.should.eql(3);
c.v.should.eql([0,-1,1]);

var c = d.cross(b);
c.v.length.should.eql(3);
c.v.should.eql([-1,1,-1]);
});

it('should calculate the distance between the two', function () {
var c = a.distanceFrom(b);
c.should.eql(1);

var c = a.distanceFrom(a);
c.should.eql(0);

var c = b.distanceFrom(d);
c.should.eql(Math.sqrt(2));
});

it('should calculate the length of the vector', function () {
Expand Down