Ejemplo n.º 1
0
        private static void TestRodCutting()
        {
            RodCutting ks = new RodCutting();

            int[] lengths = { 1, 2, 3, 4, 5 };
            int[] prices  = { 2, 6, 7, 10, 13 };
            Console.WriteLine(ks.SolveRodCutting(lengths, prices, 5));
            Console.WriteLine(ks.SolveRodCutting(lengths, prices, 6));
        }
Ejemplo n.º 2
0
        public void DP_ShallNot_BeCalled_MoreThenOnce()
        {
            var prices          = new int[] { 0, 1, 1, 1, 1, 5 };
            var resultRecursive = RodCutting.Cut_Recurcive(5, prices, true);

            var resultDP = RodCutting.Cut_DP1(5, prices, true);;

            for (var i = 0; i < 6; i++)
            {
                Assert.IsTrue(resultRecursive.Item2[i] >= resultDP.Item2[i]);
                Assert.IsTrue(resultDP.Item2[i] <= 1);
            }
        }
Ejemplo n.º 3
0
        private static void RodCuttingTest(int[] prices)
        {
            int[] expected = RodCuttingTests.MaximumRevenues(prices);
            int[] actual   = RodCutting.MaximumRevenues(prices);

            Assert.AreEqual(expected.Length, actual.Length);
            for (int i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected[i], actual[i]);
            }

            return;
        }