summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2014-08-18 15:01:56 -0400
committerJules Laplace <jules@okfoc.us>2014-08-18 15:01:56 -0400
commita8ed33d8313b093f589a5483cb00c7163b7b8dc3 (patch)
treedc4587fcb6559d86adcecf8d68fe6672d50a0e2f /test
parent174077e0a9779f73b1b87253c8c7bae8d03400fb (diff)
surface tests
Diffstat (limited to 'test')
-rw-r--r--test/01-test-vec2.js19
-rw-r--r--test/07-test-surface.js267
2 files changed, 230 insertions, 56 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 2a51b7f..fa05d43 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,64 +52,152 @@ 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) ) )
+ surface.add( new Rect( new vec2(1, 3), new vec2(0, 4) ) )
+ surface.add( new Rect( new vec2(3, 6), new vec2(0, 4) ) )
- var small = new vec2(2, 2)
- var oblong = new vec2(4, 1)
-
- // 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('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) ) )
+
+ 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)
+ })
- var small = new vec2(2, 2)
- var oblong = new vec2(4, 1)
+ })
- // 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(){
@@ -114,8 +206,8 @@ 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(){
@@ -125,24 +217,87 @@ 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)
+})
+
+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("places a small element on the right", function(){
- var bounds = surface.place(small, new vec2(4,6))
-// console.log(bounds)
+ 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)))
})
- })
- describe('#clamp()', function(){
- it("", function(){
+ 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))
})
})