diff options
Diffstat (limited to 'test/01-test-vec2.js')
| -rw-r--r-- | test/01-test-vec2.js | 57 |
1 files changed, 52 insertions, 5 deletions
diff --git a/test/01-test-vec2.js b/test/01-test-vec2.js index b38f052..6104f92 100644 --- a/test/01-test-vec2.js +++ b/test/01-test-vec2.js @@ -2,8 +2,8 @@ var assert = require("assert") var vec2 = require("../public/assets/javascripts/rectangles/models/vec2.js") describe('vec2', function(){ + var vec = new vec2(0, 10) describe('#intersects()', function(){ - var vec = new vec2(0, 10) it('intersects itself', function(){ assert.equal(true, vec.intersects( new vec2(0, 10) )); @@ -29,6 +29,15 @@ describe('vec2', function(){ it('does not intersect when after', function(){ assert.equal(false, vec.intersects( new vec2(15, 20) )); }) + it('intersects when only startpoint matches', function(){ + assert.equal(true, vec.intersects( new vec2(-5, 0) )); + }) + it('intersects when only endpoint matches', function(){ + assert.equal(true, vec.intersects( new vec2(10, 15) )); + }) + }) + + describe('#contains()', function(){ it('contains itself', function(){ assert.equal(true, vec.contains( 0 )); assert.equal(true, vec.contains( 5 )); @@ -38,6 +47,9 @@ describe('vec2', function(){ assert.equal(false, vec.contains( -5 )); assert.equal(false, vec.contains( 15 )); }) + }) + + describe('#containsCenter()', function(){ it('containsCenter itself', function(){ assert.equal(true, vec.containsCenter( 5 )); }) @@ -45,11 +57,46 @@ describe('vec2', function(){ assert.equal(false, vec.containsCenter( 0 )); assert.equal(false, vec.containsCenter( 10 )); }) - it('intersects when only startpoint matches', function(){ - assert.equal(true, vec.intersects( new vec2(-5, 0) )); + }) + + describe('#containsDisc()', function(){ + it('containsDisc within a radius', function(){ + assert.equal(true, vec.containsDisc( 2, 2 )); + assert.equal(true, vec.containsDisc( 5, 2 )); + assert.equal(true, vec.containsDisc( 7, 2 )); }) - it('intersects when only endpoint matches', function(){ - assert.equal(true, vec.intersects( new vec2(10, 15) )); + it('does not containsDisc its endpoints', function(){ + assert.equal(false, vec.containsDisc( 0, 2 )); + assert.equal(false, vec.containsDisc( 1, 2 )); + assert.equal(false, vec.containsDisc( 9, 2 )); + assert.equal(false, vec.containsDisc( 10, 2 )); + }) + it('does not containsDisc outside points', function(){ + assert.equal(false, vec.containsDisc( -5, 2 )); + assert.equal(false, vec.containsDisc( -2, 2 )); + assert.equal(false, vec.containsDisc( 12, 2 )); + assert.equal(false, vec.containsDisc( 15, 2 )); + }) + }) + + describe('#clampDisc()', function(){ + it('clampDisc clamps on the left', function(){ + assert.equal(2, vec.clampDisc( -1, 2 )); + assert.equal(2, vec.clampDisc( 0, 2 )); + assert.equal(2, vec.clampDisc( 1, 2 )); + assert.equal(2, vec.clampDisc( 2, 2 )); + }) + it('clampDisc clamps on the right', function(){ + assert.equal(8, vec.clampDisc( 8, 2 )); + assert.equal(8, vec.clampDisc( 9, 2 )); + assert.equal(8, vec.clampDisc( 10, 2 )); + assert.equal(8, vec.clampDisc( 11, 2 )); + }) + it('clampDisc doesnt clamp in the middle', function(){ + assert.equal(3, vec.clampDisc( 3, 2 )); + assert.equal(4, vec.clampDisc( 4, 2 )); + assert.equal(5, vec.clampDisc( 5, 2 )); }) }) }) + |
