public async Task GeneticMinimumBoundingBoxFinderTestRunAfterCancellation()
        {
            //Arrange
            var inputSequence = (TestUtil.Shuffle(TestUtil.GetIncreasingSquares(50)));
            var packer        = new GeneticMinimumBoundingBoxFinder(1000, 100);
            var source        = new CancellationTokenSource();
            var token         = source.Token;

            //Act
            var resultTask = Task.Run(() => packer.FindMinimumBoundingBox(inputSequence, token));
            //Wait some time so that some iteration has completed
            await Task.Delay(3000).ConfigureAwait(false);

            source.Cancel();
            source.Dispose();
            var result = await resultTask.ConfigureAwait(false);

            source = new CancellationTokenSource();
            token  = source.Token;
            result = packer.FindMinimumBoundingBox(inputSequence, token);

            source.Dispose();

            //Assert
            Assert.AreNotEqual(null, result);
            Assert.AreEqual(true, TestUtil.IsPackingResultValid(result));
            Assert.IsTrue(packer.Progress > 0);
        }
        public void GeneticMinimumBoundingBoxFinderTestInstanceReusability()
        {
            //Arrange
            var inputSequence = (TestUtil.Shuffle(TestUtil.GetIncreasingSquares(1)));
            var packer        = new GeneticMinimumBoundingBoxFinder(10, 10);

            //Results might be different because of the random factor
            //Act
            packer.FindMinimumBoundingBox(inputSequence);
            packer.FindMinimumBoundingBox(inputSequence);
            packer.FindMinimumBoundingBox(inputSequence);

            //Assert -> no exception
        }
        public void GeneticMinimumBoundingBoxFinderTestLessThanTwoPopulation()
        {
            //Arrange
            var inputSequence = (TestUtil.Shuffle(TestUtil.GetIncreasingSquares(1)));
            var packer        = new GeneticMinimumBoundingBoxFinder(100, 1);

            //Act
            packer.FindMinimumBoundingBox(inputSequence);
        }
        public void GeneticMinimumBoundingBoxFinderTestNegativeIterations()
        {
            //Arrange
            var inputSequence = (TestUtil.Shuffle(TestUtil.GetIncreasingSquares(1)));
            var packer        = new GeneticMinimumBoundingBoxFinder(-10, 100);

            //Act
            var result = packer.FindMinimumBoundingBox(inputSequence);

            //Assert
            Assert.AreEqual(null, result);
        }
        public void GeneticMinimumBoundingBoxFinderTestZeroIterations()
        {
            //Arrange
            var inputSequence = (TestUtil.Shuffle(TestUtil.GetIncreasingSquares(1)));
            var packer        = new GeneticMinimumBoundingBoxFinder(0, 2);

            //Act
            var result = packer.FindMinimumBoundingBox(inputSequence);

            //Assert
            Assert.AreEqual(true, TestUtil.IsPackingResultValid(result));
        }
        public void GeneticMinimumBoundingBoxFinderTestArgumentNull()
        {
            //Arrange
            IEnumerable <PPRect> inputSequence = null;
            var packer = new GeneticMinimumBoundingBoxFinder(100, 100);

            //Act
            var result = packer.FindMinimumBoundingBox(inputSequence);

            //Assert
            Assert.AreNotEqual(null, result);
            Assert.AreEqual(true, TestUtil.IsPackingResultValid(result));
        }
        public void GeneticMinimumBoundingBoxFinderTestValidSquares50()
        {
            //Arrange
            var inputSequence = (TestUtil.Shuffle(TestUtil.GetIncreasingSquares(50)));
            var packer        = new GeneticMinimumBoundingBoxFinder(100, 100);

            //Act
            var result = packer.FindMinimumBoundingBox(inputSequence);

            //Assert
            Assert.AreNotEqual(null, result);
            Assert.AreEqual(true, TestUtil.IsPackingResultValid(result));
        }
        public void GeneticMinimumBoundingBoxFinderTestEmptyInput()
        {
            //Arrange
            var inputSequence = Enumerable.Empty <PPRect>();
            var packer        = new GeneticMinimumBoundingBoxFinder(100, 100);

            //Act
            var result = packer.FindMinimumBoundingBox(inputSequence);

            //Assert
            Assert.AreNotEqual(null, result);
            Assert.AreEqual(0, result.Width);
            Assert.AreEqual(0, result.Height);
            Assert.AreEqual(0, result.Rects.Count());
        }