コード例 #1
0
        public void Given2Matrices_CostIsNot0()
        {
            Assert.AreEqual(6000, MatrixChain.GetOptimalMatrixChainMultipliactionCost(new int[] { 10, 20, 30 }));
            Assert.AreEqual(6000, MatrixChain.GetOptimalMatrixChainMultipliactionCostRecursive(new int[] { 10, 20, 30 }));

            /*
             *  There are only two matrices of dimensions 10x20 and 20x30. So there
             *  is only one way to multiply the matrices, cost of which is 10*20*30
             */
        }
コード例 #2
0
        public void GivenMatricesOfSize3_OptimalChainIsSelected()
        {
            Assert.AreEqual(26000, MatrixChain.GetOptimalMatrixChainMultipliactionCost(new int[] { 40, 20, 30, 10, 30 }));
            Assert.AreEqual(26000, MatrixChain.GetOptimalMatrixChainMultipliactionCostRecursive(new int[] { 40, 20, 30, 10, 30 }));

            /*
             *  There are 4 matrices of dimensions 40x20, 20x30, 30x10 and 10x30.
             *  Let the input 4 matrices be A, B, C and D.The minimum number of
             *  multiplications are obtained by putting parenthesis in following way
             *  (A(BC))D-- > 20 * 30 * 10 + 40 * 20 * 10 + 40 * 10 * 30
             *
             */

            Assert.AreEqual(30000, MatrixChain.GetOptimalMatrixChainMultipliactionCost(new int[] { 10, 20, 30, 40, 30 }));
            Assert.AreEqual(30000, MatrixChain.GetOptimalMatrixChainMultipliactionCostRecursive(new int[] { 10, 20, 30, 40, 30 }));


            /*
             *  There are 4 matrices of dimensions 10x20, 20x30, 30x40 and 40x30.
             *  Let the input 4 matrices be A, B, C and D.The minimum number of
             *  multiplications are obtained by putting parenthesis in following way
             *  ((AB) C)D-- > 10 * 20 * 30 + 10 * 30 * 40 + 10 * 40 * 30
             */
        }
コード例 #3
0
 public void GivenSingleMatrix_CostIs0()
 {
     Assert.AreEqual(0, MatrixChain.GetOptimalMatrixChainMultipliactionCost(new int[] { 10, 20 }));
     Assert.AreEqual(0, MatrixChain.GetOptimalMatrixChainMultipliactionCostRecursive(new int[] { 10, 20 }));
 }
コード例 #4
0
 public void GivenNullImput_CostIs0()
 {
     Assert.AreEqual(0, MatrixChain.GetOptimalMatrixChainMultipliactionCost(null));
     Assert.AreEqual(0, MatrixChain.GetOptimalMatrixChainMultipliactionCostRecursive(null));
 }