diff options
| author | Julie Lala <jules@okfoc.us> | 2014-08-18 23:57:34 -0400 |
|---|---|---|
| committer | Julie Lala <jules@okfoc.us> | 2014-08-18 23:57:34 -0400 |
| commit | ca54810c810e8dd08b20dce5e901630d0d36fe25 (patch) | |
| tree | ab5a1dfbd60363d44ed4a75c735b99c1fdaf5cc7 /test | |
| parent | 056d78d21aa3ae3985f5711fbfe0c14d3e3d4791 (diff) | |
| parent | 559799f707a8c7fbd0d6296dfbce81ac6f9b376a (diff) | |
ok
Diffstat (limited to 'test')
| -rw-r--r-- | test/01-test-vec2.js | 19 | ||||
| -rw-r--r-- | test/07-test-surface.js | 333 |
2 files changed, 297 insertions, 55 deletions
diff --git a/test/01-test-vec2.js b/test/01-test-vec2.js index 6104f92..429c537 100644 --- a/test/01-test-vec2.js +++ b/test/01-test-vec2.js @@ -37,6 +37,25 @@ describe('vec2', function(){ }) }) + describe('#intersection()', function(){ + it('intersects from left', function(){ + var inter = vec.intersection( new vec2( 5, 15 ) ) + assert.equal(true, inter.eq( new vec2(5, 10) )) + }) + it('intersects from right', function(){ + var inter = vec.intersection( new vec2( -5, 5 ) ) + assert.equal(true, inter.eq( new vec2(0, 5) )) + }) + it('intersects inner', function(){ + var inter = vec.intersection( new vec2( 2, 5 ) ) + assert.equal(true, inter.eq( new vec2(2, 5) )) + }) + it('intersects outer', function(){ + var inter = vec.intersection( new vec2( -5, 15 ) ) + assert.equal(true, inter.eq( new vec2(0, 10) )) + }) + }) + describe('#contains()', function(){ it('contains itself', function(){ assert.equal(true, vec.contains( 0 )); diff --git a/test/07-test-surface.js b/test/07-test-surface.js index 26a90e7..92ec982 100644 --- a/test/07-test-surface.js +++ b/test/07-test-surface.js @@ -7,15 +7,19 @@ var Surface = require("../public/assets/javascripts/rectangles/models/surface.js // [[3 4] [2 4]] front back left right // [[4 5] [0 4]] front back left right +var small = new vec2(2, 2) +var wide = new vec2(5, 1) +var tall = new vec2(1, 5) +var large = new vec2(7, 7) +var position = new vec2(2, 1) + describe('basic surface', function(){ var surface = new Surface () surface.add( new Rect( new vec2(1, 6), new vec2(0, 4) ) ) - var small = new vec2(2, 2) - var oblong = new vec2(4, 1) + var position = new vec2(2, 1) describe('#clamp_delta()', function(){ - var position = new vec2(2,1) it("does not alter a zero delta", function(){ var delta = new vec2(0,0) surface.clamp_delta(surface.bounds, small, position, delta) @@ -48,37 +52,55 @@ describe('basic surface', function(){ }) }) - describe('#place()', function(){ - it("fits a small element on the top left", function(){ - var bounds = surface.place(small, new vec2(1,3)) -// console.log(bounds) + describe('#bounds_at_index_with_dimensions()', function(){ + it("generates proper bounds from left", function(){ + var bounds = surface.bounds_at_index_with_dimensions(0, small) + assert.notEqual(false, bounds) + assert.equal(true, bounds.eq(new Rect(1,0, 6,4))) + }) + it("generates proper bounds with wide", function(){ + var bounds = surface.bounds_at_index_with_dimensions(0, wide) + assert.notEqual(false, bounds) + assert.equal(true, bounds.eq(new Rect(1,0, 6,4))) }) - it("places a small element on the right", function(){ - var bounds = surface.place(small, new vec2(4,6)) -// console.log(bounds) + it("returns false for large image", function(){ + var bounds = surface.bounds_at_index_with_dimensions(0, large) + assert.equal(false, bounds) }) }) - - // describe placement - // describe dragging up (clamp at top edge) - // describe dragging down (clamp at bottom edge) - // describe dragging left (clamp at left edge) - // describe dragging right (clamp at right edge) }) describe('double surface', function(){ var surface = new Surface () - surface.add( new Rect( new vec2(0, 3), new vec2(0, 4) ) ) - surface.add( new Rect( new vec2(3, 5), new vec2(0, 4) ) ) - - var small = new vec2(2, 2) - var oblong = new vec2(4, 1) + surface.add( new Rect( new vec2(1, 3), new vec2(0, 4) ) ) + surface.add( new Rect( new vec2(3, 6), new vec2(0, 4) ) ) - // describe placement - // describe dragging up (clamp at top edge) - // describe dragging down (clamp at bottom edge) - // describe dragging left (clamp at left edge) - // describe dragging right (clamp at right edge) + describe('#bounds_at_index_with_dimensions()', function(){ + it("generates proper bounds from left", function(){ + var bounds = surface.bounds_at_index_with_dimensions(0, small) + assert.notEqual(false, bounds) + assert.equal(true, bounds.eq(new Rect(1,0, 6,4))) + }) + it("generates proper bounds from right", function(){ + var bounds = surface.bounds_at_index_with_dimensions(1, small) + assert.notEqual(false, bounds) + assert.equal(true, bounds.eq(new Rect(1,0, 6,4))) + }) + it("generates proper bounds with wide", function(){ + var bounds = surface.bounds_at_index_with_dimensions(0, wide) + assert.notEqual(false, bounds) + assert.equal(true, bounds.eq(new Rect(1,0, 6,4))) + }) + it("generates proper bounds with wide from right", function(){ + var bounds = surface.bounds_at_index_with_dimensions(1, wide) + assert.notEqual(false, bounds) + assert.equal(true, bounds.eq(new Rect(1,0, 6,4))) + }) + it("returns false for large image", function(){ + var bounds = surface.bounds_at_index_with_dimensions(0, large) + assert.equal(false, bounds) + }) + }) }) describe('triple surface', function(){ @@ -98,29 +120,99 @@ describe('triple surface', function(){ describe('two-level surface', function(){ var surface = new Surface () - surface.add( new Rect( new vec2(0, 3), new vec2(0, 4) ) ) - surface.add( new Rect( new vec2(3, 5), new vec2(0, 6) ) ) + surface.add( new Rect( new vec2(1, 3), new vec2(0, 4) ) ) + surface.add( new Rect( new vec2(3, 6), new vec2(0, 6) ) ) - var small = new vec2(2, 2) - var oblong = new vec2(4, 1) + describe('#bounds_at_index_with_dimensions()', function(){ + it("generates proper bounds from left", function(){ + var bounds = surface.bounds_at_index_with_dimensions(0, small) + assert.notEqual(false, bounds) + assert.equal(true, bounds.eq(new Rect(1,0, 6,4))) + }) + it("generates proper bounds from right", function(){ + var bounds = surface.bounds_at_index_with_dimensions(1, small) + assert.notEqual(false, bounds) + assert.equal(true, bounds.eq(new Rect(3,0, 6,6))) + }) + it("generates proper bounds with wide", function(){ + var bounds = surface.bounds_at_index_with_dimensions(0, wide) + assert.notEqual(false, bounds) + assert.equal(true, bounds.eq(new Rect(1,0, 6,4))) + }) + it("generates proper bounds with wide from right", function(){ + var bounds = surface.bounds_at_index_with_dimensions(1, wide) + assert.notEqual(false, bounds) + assert.equal(true, bounds.eq(new Rect(1,0, 6,4))) + }) + it("generates proper bounds with tall", function(){ + var bounds = surface.bounds_at_index_with_dimensions(0, tall) + assert.notEqual(false, bounds) + assert.equal(true, bounds.eq(new Rect(3,0, 6,6))) + }) + it("generates the same bounds with tall from right", function(){ + var bounds = surface.bounds_at_index_with_dimensions(1, tall) + assert.notEqual(false, bounds) + assert.equal(true, bounds.eq(new Rect(3,0, 6,6))) + }) + it("returns false for large image", function(){ + var bounds = surface.bounds_at_index_with_dimensions(0, large) + assert.equal(false, bounds) + }) + + }) - // describe placement/centering - // describe dragging up (clamp at top edge) - // describe dragging down (clamp at bottom edge) - // describe dragging left (clamp at left edge) - // describe dragging right (clamp at right edge) - // describe dragging up and right (clamp at top edge, then pop into peninsula space) }) describe('door surface', function(){ var surface = new Surface () - surface.add( new Rect( new vec2(0, 3), new vec2(0, 4) ) ) - surface.add( new Rect( new vec2(3, 4), new vec2(2, 4) ) ) - surface.add( new Rect( new vec2(4, 6), new vec2(0, 4) ) ) + surface.add( new Rect( new vec2(1, 4), new vec2(0, 4) ) ) + surface.add( new Rect( new vec2(4, 5), new vec2(2, 4) ) ) + surface.add( new Rect( new vec2(5, 8), new vec2(0, 4) ) ) - var small = new vec2(2, 2) - var large = new vec2(10, 10) - var oblong = new vec2(4, 1) + describe('#bounds_at_index_with_dimensions()', function(){ + it("generates proper bounds from left", function(){ + var bounds = surface.bounds_at_index_with_dimensions(0, small) + assert.notEqual(false, bounds) + assert.equal(true, bounds.eq(new Rect(1,0, 4,4))) + }) + it("generates proper bounds from middle", function(){ + var bounds = surface.bounds_at_index_with_dimensions(1, small) + assert.notEqual(false, bounds) + assert.equal(true, bounds.eq(new Rect(1,2, 8,4))) + }) + it("generates proper bounds from right", function(){ + var bounds = surface.bounds_at_index_with_dimensions(2, small) + assert.notEqual(false, bounds) + assert.equal(true, bounds.eq(new Rect(5,0, 8,4))) + }) + + it("generates proper bounds for wide from left", function(){ + var bounds = surface.bounds_at_index_with_dimensions(0, wide) + assert.notEqual(false, bounds) + assert.equal(true, bounds.eq(new Rect(1,2, 8,4))) + }) + it("generates proper bounds for wide from middle", function(){ + var bounds = surface.bounds_at_index_with_dimensions(1, wide) + assert.notEqual(false, bounds) + assert.equal(true, bounds.eq(new Rect(1,2, 8,4))) + }) + it("generates proper bounds for wide from right", function(){ + var bounds = surface.bounds_at_index_with_dimensions(2, wide) + assert.notEqual(false, bounds) + assert.equal(true, bounds.eq(new Rect(1,2, 8,4))) + }) + + it("returns false for tall", function(){ + assert.equal(false, surface.bounds_at_index_with_dimensions(0, tall)) + assert.equal(false, surface.bounds_at_index_with_dimensions(1, tall)) + assert.equal(false, surface.bounds_at_index_with_dimensions(2, tall)) + }) + it("returns false for large image", function(){ + assert.equal(false, surface.bounds_at_index_with_dimensions(0, large)) + assert.equal(false, surface.bounds_at_index_with_dimensions(1, large)) + assert.equal(false, surface.bounds_at_index_with_dimensions(2, large)) + }) + }) describe('#fits()', function(){ it("fits something small", function(){ @@ -129,10 +221,11 @@ describe('door surface', function(){ it("doesn't fit something large", function(){ assert.equal(false, !! surface.fits(large)) }) - it("fits something oblong", function(){ - assert.equal(true, !! surface.fits(oblong)) + it("fits something wide", function(){ + assert.equal(true, !! surface.fits(wide)) }) }) + describe('#fits_scale()', function(){ it("fits something large, scaled down", function(){ assert.equal(true, !! surface.fits_scale(large, 0.1)) @@ -140,24 +233,154 @@ describe('door surface', function(){ it("doesn't fit something small, scaled up", function(){ assert.equal(false, !! surface.fits_scale(small, 10)) }) - it("doesn't fit something oblong, scaled up", function(){ - assert.equal(false, !! surface.fits_scale(oblong, 10)) + it("doesn't fit something wide, scaled up", function(){ + assert.equal(false, !! surface.fits_scale(wide, 10)) }) }) - describe('#place()', function(){ - it("fits a small element on the top left", function(){ - var bounds = surface.place(small, new vec2(1,3)) -// console.log(bounds) + var position = new vec2(1, 2) + var bounds = surface.bounds_at_index_with_dimensions(0, small) + + describe('#translate()', function(){ + it("does not alter a zero delta", function(){ + var delta = new vec2(0,0) + var new_bounds = surface.translate(bounds, small, position, delta) + assert.equal(true, delta.eq(new vec2( 0, 0 ))) + }) + it("does not alter a minimal delta", function(){ + var delta = new vec2(1, 1) + surface.translate(bounds, small, position, delta) + assert.equal(true, delta.eq(new vec2( 1, 1 ))) + }) + it("clamps leftward delta", function(){ + var delta = new vec2(-10, 0) + surface.translate(bounds, small, position, delta) + assert.equal(true, delta.eq(new vec2( 0, 0 ))) + }) + it("clamps 2px rightward delta", function(){ + var delta = new vec2(2, 0) + surface.translate(bounds, small, position, delta) + assert.equal(true, delta.eq(new vec2( 1, 0 ))) + }) + it("clamps 3px rightward delta", function(){ + var delta = new vec2(3, 0) + var new_bounds = surface.translate(bounds, small, position, delta) + console.log(new_bounds+"") + assert.equal(true, delta.eq(new vec2( 3, 0 ))) + }) + it("clamps 4px rightward delta", function(){ + var delta = new vec2(4, 0) + var new_bounds = surface.translate(bounds, small, position, delta) + console.log(new_bounds+"") + assert.equal(true, delta.eq(new vec2( 4, 0 ))) + }) + it("clamps 5px rightward delta to new bounds", function(){ + var delta = new vec2(5, 0) + var new_bounds = surface.translate(bounds, small, position, delta) + console.log(new_bounds+"") + assert.equal(true, delta.eq(new vec2( 5, 0 ))) + }) + it("clamps 6px rightward delta", function(){ + var delta = new vec2(6, 0) + var new_bounds = surface.translate(bounds, small, position, delta) + console.log(new_bounds+"") + assert.equal(true, delta.eq(new vec2( 5, 0 ))) + }) + it("clamps 20px rightward delta", function(){ + var delta = new vec2(7, 0) + var new_bounds = surface.translate(bounds, small, position, delta) + console.log(new_bounds+"") + assert.equal(true, delta.eq(new vec2( 5, 0 ))) + }) + it("clamps upward delta", function(){ + var delta = new vec2(0, 10) + surface.translate(bounds, small, position, delta) + assert.equal(true, delta.eq(new vec2( 0, 1 ))) }) - it("places a small element on the right", function(){ - var bounds = surface.place(small, new vec2(4,6)) -// console.log(bounds) + it("clamps downward delta", function(){ + var delta = new vec2(0, -10) + surface.translate(bounds, small, position, delta) + assert.equal(true, delta.eq(new vec2( 0, -1 ))) }) + }) - describe('#clamp()', function(){ - it("", function(){ +}) + +describe('double door surface', function(){ + var surface = new Surface () + surface.add( new Rect( new vec2(1, 4), new vec2(0, 4) ) ) + surface.add( new Rect( new vec2(4, 5), new vec2(2, 4) ) ) + surface.add( new Rect( new vec2(5, 8), new vec2(0, 6) ) ) + surface.add( new Rect( new vec2(8, 10), new vec2(2, 4) ) ) + surface.add( new Rect( new vec2(10, 14), new vec2(0, 4) ) ) + + describe('#bounds_at_index_with_dimensions()', function(){ + it("generates proper bounds from left", function(){ + var bounds = surface.bounds_at_index_with_dimensions(0, small) + assert.notEqual(false, bounds) + assert.equal(true, bounds.eq(new Rect(1,0, 4,4))) + }) + it("generates proper bounds from left door", function(){ + var bounds = surface.bounds_at_index_with_dimensions(1, small) + assert.notEqual(false, bounds) + assert.equal(true, bounds.eq(new Rect(1,2, 14,4))) + }) + it("generates proper bounds from middle", function(){ + var bounds = surface.bounds_at_index_with_dimensions(2, small) + assert.notEqual(false, bounds) + assert.equal(true, bounds.eq(new Rect(5,0, 8,6))) + }) + it("generates proper bounds from right door", function(){ + var bounds = surface.bounds_at_index_with_dimensions(3, small) + assert.notEqual(false, bounds) + assert.equal(true, bounds.eq(new Rect(1,2, 14,4))) + }) + it("generates proper bounds from right", function(){ + var bounds = surface.bounds_at_index_with_dimensions(4, small) + assert.notEqual(false, bounds) + assert.equal(true, bounds.eq(new Rect(10,0, 14,4))) + }) + + it("generates proper bounds for wide from left", function(){ + var bounds = surface.bounds_at_index_with_dimensions(0, wide) + assert.notEqual(false, bounds) + assert.equal(true, bounds.eq(new Rect(1,2, 14,4))) + }) + it("generates proper bounds for wide from middle", function(){ + var bounds = surface.bounds_at_index_with_dimensions(1, wide) + assert.notEqual(false, bounds) + assert.equal(true, bounds.eq(new Rect(1,2, 14,4))) + }) + it("generates proper bounds for wide from right", function(){ + var bounds = surface.bounds_at_index_with_dimensions(4, wide) + assert.notEqual(false, bounds) + assert.equal(true, bounds.eq(new Rect(1,2, 14,4))) + }) + + it("places tall in middle", function(){ + var bounds = surface.bounds_at_index_with_dimensions(0, tall) + assert.notEqual(false, bounds) + assert.equal(true, bounds.eq(new Rect(5,0, 8,6))) + + var bounds = surface.bounds_at_index_with_dimensions(1, tall) + assert.equal(true, bounds.eq(new Rect(5,0, 8,6))) + + var bounds = surface.bounds_at_index_with_dimensions(2, tall) + assert.equal(true, bounds.eq(new Rect(5,0, 8,6))) + + var bounds = surface.bounds_at_index_with_dimensions(3, tall) + assert.equal(true, bounds.eq(new Rect(5,0, 8,6))) + + var bounds = surface.bounds_at_index_with_dimensions(4, tall) + assert.equal(true, bounds.eq(new Rect(5,0, 8,6))) + }) + it("returns false for large image", function(){ + assert.equal(false, surface.bounds_at_index_with_dimensions(0, large)) + assert.equal(false, surface.bounds_at_index_with_dimensions(1, large)) + assert.equal(false, surface.bounds_at_index_with_dimensions(2, large)) + assert.equal(false, surface.bounds_at_index_with_dimensions(3, large)) + assert.equal(false, surface.bounds_at_index_with_dimensions(4, large)) }) }) |
