Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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);
        }