Skip to content

Commit

Permalink
x10 to packer testing to accomodate wiggle room in Rect.canFit
Browse files Browse the repository at this point in the history
  • Loading branch information
desandro committed Dec 18, 2014
1 parent bbeaf93 commit 78cb312
Showing 1 changed file with 41 additions and 41 deletions.
82 changes: 41 additions & 41 deletions test/test-packer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ test( 'basics', function() {
});

test( 'packing', function() {
var packr = new Packer( 3, 10 );
var packr = new Packer( 30, 100 );

// 112
// 352
// 344
// xxx
// xxx

var rect1 = new Rect({ width: 2, height: 1 });
var rect2 = new Rect({ width: 1, height: 2 });
var rect3 = new Rect({ width: 1, height: 2 });
var rect4 = new Rect({ width: 2, height: 1 });
var rect5 = new Rect({ width: 1, height: 1 });
var rect1 = new Rect({ width: 20, height: 10 });
var rect2 = new Rect({ width: 10, height: 20 });
var rect3 = new Rect({ width: 10, height: 20 });
var rect4 = new Rect({ width: 20, height: 10 });
var rect5 = new Rect({ width: 10, height: 10 });

packr.pack( rect1 );
packr.pack( rect2 );
Expand All @@ -40,26 +40,26 @@ test( 'packing', function() {

equal( rect1.x, 0, 'rect1.x top left' );
equal( rect1.y, 0, 'rect1.y top left' );
equal( rect2.x, 2, 'rect2.x top right' );
equal( rect2.x, 20, 'rect2.x top right' );
equal( rect2.y, 0, 'rect2.y top right' );
equal( rect3.x, 0, 'rect3.x bottom left' );
equal( rect3.y, 1, 'rect3.y bottom left' );
equal( rect4.x, 1, 'rect4.x bottom right' );
equal( rect4.y, 2, 'rect4.y bottom right' );
equal( rect5.x, 1, 'rect5.x packed in center' );
equal( rect5.y, 1, 'rect5.y packed in center' );
equal( rect3.y, 10, 'rect3.y bottom left' );
equal( rect4.x, 10, 'rect4.x bottom right' );
equal( rect4.y, 20, 'rect4.y bottom right' );
equal( rect5.x, 10, 'rect5.x packed in center' );
equal( rect5.y, 10, 'rect5.y packed in center' );

// bottom space is open
equal( packr.spaces.length, 1, 'one space open' );
var space = packr.spaces[0];
equal( space.width, 3, 'space.width' );
equal( space.height, 7, 'space.height' );
equal( space.width, 30, 'space.width' );
equal( space.height, 70, 'space.height' );
equal( space.x, 0, 'space.x' );
equal( space.y, 3, 'space.y' );
equal( space.y, 30, 'space.y' );

});
test( 'packing with a placed', function() {
var packr = new Packer( 3, 10 );
var packr = new Packer( 30, 100 );

// 225
// 311
Expand All @@ -69,15 +69,15 @@ test( 'packing with a placed', function() {
// xxx

var rect1 = new Rect({
width: 2,
height: 1,
x: 1,
y: 1
width: 20,
height: 10,
x: 10,
y: 10
});
var rect2 = new Rect({ width: 2, height: 1 });
var rect3 = new Rect({ width: 1, height: 2 });
var rect4 = new Rect({ width: 1, height: 2 });
var rect5 = new Rect({ width: 1, height: 1 });
var rect2 = new Rect({ width: 20, height: 10 });
var rect3 = new Rect({ width: 10, height: 20 });
var rect4 = new Rect({ width: 10, height: 20 });
var rect5 = new Rect({ width: 10, height: 10 });

packr.placed( rect1 );
packr.pack( rect2 );
Expand All @@ -88,10 +88,10 @@ test( 'packing with a placed', function() {
equal( rect2.x, 0, 'rect2.x top left' );
equal( rect2.y, 0, 'rect2.y top left' );
equal( rect3.x, 0, 'rect3.x left side' );
equal( rect3.y, 1, 'rect3.y left side' );
equal( rect4.x, 1, 'rect4.x bottom center' );
equal( rect4.y, 2, 'rect4.y bottom center' );
equal( rect5.x, 2, 'rect5.x packed in top right' );
equal( rect3.y, 10, 'rect3.y left side' );
equal( rect4.x, 10, 'rect4.x bottom center' );
equal( rect4.y, 20, 'rect4.y bottom center' );
equal( rect5.x, 20, 'rect5.x packed in top right' );
equal( rect5.y, 0, 'rect5.y packed in top right' );

equal( packr.spaces.length, 3, '3 spaces left' );
Expand All @@ -105,17 +105,17 @@ test( 'packing horizontal', function() {
equal( rect.y, y, 'y: ' + y );
}

var packr = new Packer( 10, 3, 'rightwardTopToBottom' );
var packr = new Packer( 100, 30, 'rightwardTopToBottom' );

// 133xx
// 154xx
// 224xx

var rect1 = new Rect({ width: 1, height: 2 });
var rect2 = new Rect({ width: 2, height: 1 });
var rect3 = new Rect({ width: 2, height: 1 });
var rect4 = new Rect({ width: 1, height: 2 });
var rect5 = new Rect({ width: 1, height: 1 });
var rect1 = new Rect({ width: 10, height: 20 });
var rect2 = new Rect({ width: 20, height: 10 });
var rect3 = new Rect({ width: 20, height: 10 });
var rect4 = new Rect({ width: 10, height: 20 });
var rect5 = new Rect({ width: 10, height: 10 });

packr.pack( rect1 );
packr.pack( rect2 );
Expand All @@ -124,17 +124,17 @@ test( 'packing horizontal', function() {
packr.pack( rect5 );

checkRect( rect1, 0, 0 );
checkRect( rect2, 0, 2 );
checkRect( rect3, 1, 0 );
checkRect( rect4, 2, 1 );
checkRect( rect5, 1, 1 );
checkRect( rect2, 0, 20 );
checkRect( rect3, 10, 0 );
checkRect( rect4, 20, 10 );
checkRect( rect5, 10, 10 );

// bottom space is open
equal( packr.spaces.length, 1, 'one space open' );
var space = packr.spaces[0];
equal( space.width, 7, 'space.width' );
equal( space.height, 3, 'space.height' );
checkRect( space, 3, 0 );
equal( space.width, 70, 'space.width' );
equal( space.height, 30, 'space.height' );
checkRect( space, 30, 0 );

});

Expand Down

0 comments on commit 78cb312

Please sign in to comment.