diff options
Diffstat (limited to 'test/01-test-vec2.js')
| -rw-r--r-- | test/01-test-vec2.js | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/test/01-test-vec2.js b/test/01-test-vec2.js new file mode 100644 index 0000000..6104f92 --- /dev/null +++ b/test/01-test-vec2.js @@ -0,0 +1,102 @@ +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(){ + + it('intersects itself', function(){ + assert.equal(true, vec.intersects( new vec2(0, 10) )); + }) + it('intersects w/ same startpoint (shorter)', function(){ + assert.equal(true, vec.intersects( new vec2(0, 5) )); + }) + it('intersects w/ same startpoint (longer)', function(){ + assert.equal(true, vec.intersects( new vec2(0, 15) )); + }) + it('intersects w/ same endpoint (shorter)', function(){ + assert.equal(true, vec.intersects( new vec2(5, 10) )); + }) + it('intersects w/ same endpoint (longer)', function(){ + assert.equal(true, vec.intersects( new vec2(-5, 10) )); + }) + it('intersects when contained', function(){ + assert.equal(true, vec.intersects( new vec2(-5, 15) )); + }) + it('does not intersect when before', function(){ + assert.equal(false, vec.intersects( new vec2(-10, -5) )); + }) + 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 )); + assert.equal(true, vec.contains( 10 )); + }) + it('does not contain before or after', 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 )); + }) + it('does not containsCenter its endpoints', function(){ + assert.equal(false, vec.containsCenter( 0 )); + assert.equal(false, vec.containsCenter( 10 )); + }) + }) + + 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('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 )); + }) + }) +}) + |
