public void FixedSizePackerTestValidSquares3() { //Arrange var inputSequence = (TestUtil.Shuffle(TestUtil.GetIncreasingSquares(3))); var placementAlgorithmMock = new Mock <IPlacementAlgorithm>(); placementAlgorithmMock .Setup(x => x.PlaceRects(It.IsAny <int>(), It.IsAny <int>(), inputSequence, It.IsAny <CancellationToken>())) .Returns <int, int, IEnumerable <PPRect>, CancellationToken>((w, h, rects, _) => { //Assume "dumb" placement algorithm that simple places all the rects consecutively next to each other int maxH = rects.Max(x => x.Height); int sumW = rects.Sum(x => x.Width); if (sumW > w || maxH > h) { return(null); } int left = 0; return(new PackingResult(sumW, maxH, rects.Select(x => { left += x.Width; return new PPRect(left, 0, left, x.Height); })));; }); var packer = new FixedSizePacker(6, 6, placementAlgorithmMock.Object); //Act var result = packer.FindMinimumBoundingBox(inputSequence); //Assert Assert.AreNotEqual(null, result); Assert.AreEqual(true, TestUtil.IsPackingResultValid(result)); }
public void FixedSizePackerTestSimilarToUnknown4() { //Arrange var inputSequence = (TestUtil.Shuffle(TestUtil.GetIncreasingSquares(4))); var placementAlgorithmMock = new Mock <IPlacementAlgorithm>(); placementAlgorithmMock .Setup(x => x.PlaceRects(It.IsAny <int>(), It.IsAny <int>(), inputSequence, It.IsAny <CancellationToken>())) .Returns <int, int, IEnumerable <PPRect>, CancellationToken>((w, h, rects, _) => { //Assume "dumb" placement algorithm that simple places all the rects consecutively next to each other int maxH = rects.Max(x => x.Height); int sumW = rects.Sum(x => x.Width); if (sumW > w || maxH > h) { return(null); } int left = 0; return(new PackingResult(sumW, maxH, rects.Select(x => { left += x.Width; return new PPRect(left, 0, left, x.Height); })));; }); var packer = new FixedSizePacker(12, 12, placementAlgorithmMock.Object); var packer2 = new UnknownSizePacker(placementAlgorithmMock.Object); //Act var result = packer.FindMinimumBoundingBox(inputSequence); var unkResult = packer2.FindMinimumBoundingBox(inputSequence); //Assert (Check that for "unlimited" dimensions, it behaves same // to unknown size packer) var actualW = result.Rects.Max(x => x.Right); var actualH = result.Rects.Max(x => x.Bottom); Assert.AreEqual(unkResult.Width, actualW); Assert.AreEqual(unkResult.Height, actualH); }