diff options
| author | Julie Lala <jules@okfoc.us> | 2014-07-23 01:38:17 -0400 |
|---|---|---|
| committer | Julie Lala <jules@okfoc.us> | 2014-07-23 01:38:17 -0400 |
| commit | 52d18ddb211a7f4ee814ef23ff09656134810519 (patch) | |
| tree | 05632d53f9580274fc90455183b19f2fccbee746 /test/01-test-vec2.js | |
| parent | 725cc3cd23890d5369ae20c27c97465c34168913 (diff) | |
making things intersect more greedily
Diffstat (limited to 'test/01-test-vec2.js')
| -rw-r--r-- | test/01-test-vec2.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/test/01-test-vec2.js b/test/01-test-vec2.js new file mode 100644 index 0000000..054d37b --- /dev/null +++ b/test/01-test-vec2.js @@ -0,0 +1,48 @@ +var assert = require("assert") +var vec2 = require("../public/assets/javascripts/rectangles/models/vec2.js") + +describe('vec2', function(){ + describe('#intersects()', function(){ + var vec = new vec2(0, 10) + + 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('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 )); + }) + 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) )); + }) + }) +}) |
