Test4() { // Room for exactly one bin. RectangleBinner oRectangleBinner = new RectangleBinner( new Rectangle(new Point(10, 20), new Size(10, 10)), 10); Rectangle oReturnedBin; foreach (Rectangle oExpectedBin in new Rectangle[] { new Rectangle(new Point(10, 20), new Size(10, 10)), }) { Assert.IsTrue(oRectangleBinner.TryGetNextBin(out oReturnedBin)); Assert.AreEqual(oExpectedBin, oReturnedBin); } Assert.IsFalse(oRectangleBinner.TryGetNextBin(out oReturnedBin)); Rectangle oRemainingRectangle; Assert.IsFalse(oRectangleBinner.TryGetRemainingRectangle( out oRemainingRectangle)); }
Test1() { // 2 rows of 3 bins each, space left over at top. RectangleBinner oRectangleBinner = new RectangleBinner( new Rectangle(new Point(1, 1), new Size(6, 5)), 2); Rectangle oReturnedBin; foreach (Rectangle oExpectedBin in new Rectangle[] { new Rectangle(new Point(1, 4), new Size(2, 2)), new Rectangle(new Point(3, 4), new Size(2, 2)), new Rectangle(new Point(5, 4), new Size(2, 2)), new Rectangle(new Point(1, 2), new Size(2, 2)), new Rectangle(new Point(3, 2), new Size(2, 2)), new Rectangle(new Point(5, 2), new Size(2, 2)), }) { Assert.IsTrue(oRectangleBinner.TryGetNextBin(out oReturnedBin)); Assert.AreEqual(oExpectedBin, oReturnedBin); } Assert.IsFalse(oRectangleBinner.TryGetNextBin(out oReturnedBin)); Assert.IsFalse(oRectangleBinner.TryGetNextBin(out oReturnedBin)); Rectangle oRemainingRectangle; Assert.IsTrue(oRectangleBinner.TryGetRemainingRectangle( out oRemainingRectangle)); Assert.AreEqual(new Rectangle(new Point(1, 1), new Size(6, 1)), oRemainingRectangle); }
Test11() { // Weird case: 2 rows of 3 bins each, no space left over at top, top // row only partially filled. RectangleBinner oRectangleBinner = new RectangleBinner( new Rectangle(new Point(1, 2), new Size(6, 4)), 2); Rectangle oReturnedBin; foreach (Rectangle oExpectedBin in new Rectangle[] { new Rectangle(new Point(1, 4), new Size(2, 2)), new Rectangle(new Point(3, 4), new Size(2, 2)), new Rectangle(new Point(5, 4), new Size(2, 2)), new Rectangle(new Point(1, 2), new Size(2, 2)), new Rectangle(new Point(3, 2), new Size(2, 2)), }) { Assert.IsTrue(oRectangleBinner.TryGetNextBin(out oReturnedBin)); Assert.AreEqual(oExpectedBin, oReturnedBin); } Rectangle oRemainingRectangle; Assert.IsTrue(oRectangleBinner.TryGetRemainingRectangle( out oRemainingRectangle)); Assert.AreEqual(new Rectangle(new Point(5, 2), new Size(2, 2)), oRemainingRectangle); }
Test9() { // 2 rows of 3 bins each, space left over at top, but only 1 bin asked // for. RectangleBinner oRectangleBinner = new RectangleBinner( new Rectangle(new Point(1, 1), new Size(6, 5)), 2); Rectangle oReturnedBin; foreach (Rectangle oExpectedBin in new Rectangle[] { new Rectangle(new Point(1, 4), new Size(2, 2)), }) { Assert.IsTrue(oRectangleBinner.TryGetNextBin(out oReturnedBin)); Assert.AreEqual(oExpectedBin, oReturnedBin); } Rectangle oRemainingRectangle; Assert.IsTrue(oRectangleBinner.TryGetRemainingRectangle( out oRemainingRectangle)); Assert.AreEqual(new Rectangle(new Point(1, 1), new Size(6, 3)), oRemainingRectangle); }
Test5() { // Too small for even one bin. RectangleBinner oRectangleBinner = new RectangleBinner( new Rectangle(new Point(10, 20), new Size(5, 5)), 6); Rectangle oReturnedBin; Assert.IsFalse(oRectangleBinner.TryGetNextBin(out oReturnedBin)); Rectangle oRemainingRectangle; Assert.IsTrue(oRectangleBinner.TryGetRemainingRectangle( out oRemainingRectangle)); Assert.AreEqual(new Rectangle(new Point(10, 20), new Size(5, 5)), oRemainingRectangle); }
public void Test1() { // 2 rows of 3 bins each, space left over at top. RectangleBinner oRectangleBinner = new RectangleBinner( new Rectangle( new Point(1, 1), new Size(6, 5) ), 2); Rectangle oReturnedBin; foreach (Rectangle oExpectedBin in new Rectangle[] { new Rectangle( new Point(1, 4), new Size(2, 2) ), new Rectangle( new Point(3, 4), new Size(2, 2) ), new Rectangle( new Point(5, 4), new Size(2, 2) ), new Rectangle( new Point(1, 2), new Size(2, 2) ), new Rectangle( new Point(3, 2), new Size(2, 2) ), new Rectangle( new Point(5, 2), new Size(2, 2) ), } ) { Assert.IsTrue( oRectangleBinner.TryGetNextBin(out oReturnedBin) ); Assert.AreEqual(oExpectedBin, oReturnedBin); } Assert.IsFalse( oRectangleBinner.TryGetNextBin(out oReturnedBin) ); Assert.IsFalse( oRectangleBinner.TryGetNextBin(out oReturnedBin) ); Rectangle oRemainingRectangle; Assert.IsTrue( oRectangleBinner.TryGetRemainingRectangle( out oRemainingRectangle) ); Assert.AreEqual(new Rectangle( new Point(1, 1), new Size(6, 1) ), oRemainingRectangle); }
public void Test5() { // Too small for even one bin. RectangleBinner oRectangleBinner = new RectangleBinner( new Rectangle( new Point(10, 20), new Size(5, 5) ), 6); Rectangle oReturnedBin; Assert.IsFalse( oRectangleBinner.TryGetNextBin(out oReturnedBin) ); Rectangle oRemainingRectangle; Assert.IsTrue( oRectangleBinner.TryGetRemainingRectangle( out oRemainingRectangle) ); Assert.AreEqual(new Rectangle( new Point(10, 20), new Size(5, 5) ), oRemainingRectangle); }
public void Test4() { // Room for exactly one bin. RectangleBinner oRectangleBinner = new RectangleBinner( new Rectangle( new Point(10, 20), new Size(10, 10) ), 10); Rectangle oReturnedBin; foreach (Rectangle oExpectedBin in new Rectangle[] { new Rectangle( new Point(10, 20), new Size(10, 10) ), } ) { Assert.IsTrue( oRectangleBinner.TryGetNextBin(out oReturnedBin) ); Assert.AreEqual(oExpectedBin, oReturnedBin); } Assert.IsFalse( oRectangleBinner.TryGetNextBin(out oReturnedBin) ); Rectangle oRemainingRectangle; Assert.IsFalse( oRectangleBinner.TryGetRemainingRectangle( out oRemainingRectangle) ); }
public void Test11() { // Weird case: 2 rows of 3 bins each, no space left over at top, top // row only partially filled. RectangleBinner oRectangleBinner = new RectangleBinner( new Rectangle( new Point(1, 2), new Size(6, 4) ), 2); Rectangle oReturnedBin; foreach (Rectangle oExpectedBin in new Rectangle[] { new Rectangle( new Point(1, 4), new Size(2, 2) ), new Rectangle( new Point(3, 4), new Size(2, 2) ), new Rectangle( new Point(5, 4), new Size(2, 2) ), new Rectangle( new Point(1, 2), new Size(2, 2) ), new Rectangle( new Point(3, 2), new Size(2, 2) ), } ) { Assert.IsTrue( oRectangleBinner.TryGetNextBin(out oReturnedBin) ); Assert.AreEqual(oExpectedBin, oReturnedBin); } Rectangle oRemainingRectangle; Assert.IsTrue( oRectangleBinner.TryGetRemainingRectangle( out oRemainingRectangle) ); Assert.AreEqual(new Rectangle( new Point(5, 2), new Size(2, 2) ), oRemainingRectangle); }