コード例 #1
0
        public void TestMaxStepsCounterException()
        {
            int find    = 149;
            int counter = 0;

            Container a = new Container('a', 1);
            Container b = new Container('b', 150);

            counter = ContainerSolver.NextStep(b, a, find, counter);
        }
コード例 #2
0
        public void ABitTougherSolution()
        {
            int find    = 4;
            int counter = 0;

            Container a = new Container('a', 3);
            Container b = new Container('b', 5);

            counter = ContainerSolver.NextStep(a, b, find, counter);

            Assert.IsTrue(b.Units == find);
            Assert.IsTrue(counter == 6);
            Trace.TraceInformation("Solution Successful in {0} steps", counter);
        }
コード例 #3
0
        public void TestOneHundredVariationsWithExceptions()
        {
            Random rand = new Random();

            List <Exception> exceptions = new List <Exception>();

            for (int i = 0; i < 100; i++)
            {
                int min     = 0;
                int max     = 25;
                int find    = rand.Next(min, max);
                int aC      = rand.Next(min, max);
                int bC      = rand.Next(min, max);
                int counter = 0;

                try
                {
                    if (ContainerSolver.ValidateProblemVariables(find, aC, bC))
                    {
                        Trace.TraceInformation("Starting: {0} : {1} / {2}", find, aC, bC);
                        Container a = new Container('a', aC < bC ? aC : bC);
                        Container b = new Container('b', aC < bC ? bC : aC); // Container "b" should be the largest

                        if (find % a.Capacity == 0)
                        {
                            counter = ContainerSolver.NextStep(b, a, find, counter);
                        }
                        else
                        {
                            counter = ContainerSolver.NextStep(a, b, find, counter);
                        }

                        Assert.IsTrue(a.Units == find || b.Units == find);
                        Trace.TraceInformation("Finished: {0} : {1} / {2} in {3} steps", find, aC, bC, counter);
                    }
                }
                catch (Exception e)
                {
                    exceptions.Add(e);
                }
            }

            Trace.TraceWarning("Execptions caught:{0}", exceptions.Count);
            exceptions.ForEach(x => Trace.TraceWarning(x.Message));
        }
コード例 #4
0
        public void FindBucketSixModThree()
        {
            int find    = 6;
            int counter = 0;

            Container a = new Container('a', 3);
            Container b = new Container('b', 9);

            if (find % a.Capacity == 0)
            {
                counter = ContainerSolver.NextStep(b, a, find, counter);
            }
            else
            {
                counter = ContainerSolver.NextStep(a, b, find, counter);
            }

            Assert.IsTrue(b.Units == find);
            Assert.IsTrue(counter == 4);
            Trace.TraceInformation("Solution Successful in {0} steps", counter);
        }
コード例 #5
0
 public void TestFindLargerThanBucketsValidation()
 {
     ContainerSolver.ValidateProblemVariables(10, 2, 4);
 }
コード例 #6
0
 public void TestEvenEvenOddValidation()
 {
     ContainerSolver.ValidateProblemVariables(3, 2, 4);
 }
コード例 #7
0
 public void TestZeroBucketCapacityException()
 {
     ContainerSolver.ValidateProblemVariables(4, 0, 5);
 }
コード例 #8
0
 public void TestZeroFindValueException()
 {
     ContainerSolver.ValidateProblemVariables(0, 3, 5);
 }
コード例 #9
0
        public void TestBucketsDivisibleEvenlyException()
        {
            Assert.IsTrue(ContainerSolver.ValidateProblemVariables(15, 3, 18));

            ContainerSolver.ValidateProblemVariables(14, 3, 18);
        }