public void TestPartitionForPrimeNumbersInPlace()
        {
            Func <int, bool> isPrime = (n) =>
            {
                if (n < 2)
                {
                    return(false);
                }
                if (n == 2)
                {
                    return(true);
                }

                int max = (int)Math.Pow(n, 0.5) + 1;
                for (int i = 2; i < max; i++)
                {
                    if (n % i == 0)
                    {
                        return(false);
                    }
                }

                return(true);
            };

            var arr = new int[] { 3, 50, 2, 11, 42, 8, 4 };

            var par = new PartitionItemsInArray();

            par.PartitionPolicyInPlace(arr, isPrime);

            Assert.That(arr.SequenceEqual(new int[] { 3, 2, 11, 50, 42, 8, 4 }), Is.True);
        }
        public void Test1()
        {
            var arr = new int[] { 3, 50, 2, 11, 42, 8, 4 };
            var p   = 20;

            var par    = new PartitionItemsInArray();
            var result = par.Partition(arr, p);

            Assert.That(result.SequenceEqual(new int[] { 3, 2, 11, 8, 4, 50, 42 }), Is.True);
        }
        public void PartitionInPlaceThreeWayJustLikeInDutchNationalFlagProblem()
        {
            Func <int, int> threeWay = n => n;
            var             arr      = new int[] { 1, 0, 2, 0, 0, 1, 1, 2, 1, 2 };

            var par = new PartitionItemsInArray();

            par.PartitionThreeWayInPlace(arr, threeWay);

            Assert.That(arr.SequenceEqual(new int[] { 0, 0, 0, 1, 1, 1, 1, 2, 2, 2 }), Is.True);
        }
        public void TestPartitionAccordingToAPolicy()
        {
            var arr = new int[] { 3, 50, 2, 11, 42, 8, 4 };

            Func <int, bool> policy = (n) => n % 2 == 0;

            var par    = new PartitionItemsInArray();
            var result = par.PartitionPolicy(arr, policy);

            Assert.That(result.SequenceEqual(new int[] { 50, 2, 42, 8, 4, 3, 11 }), Is.True);
        }
        public void TestPartitionInPlace()
        {
            var arr = new int[] { 3, 50, 2, 11, 42, 8, 4 };
            var p   = 20;

            var par = new PartitionItemsInArray();

            par.ParititionInPlace(arr, p);

            Assert.That(arr.SequenceEqual(new int[] { 3, 2, 11, 8, 4, 50, 42 }), Is.True);
        }