Coverage Report - net.sourceforge.combean.test.samples.mathprog.lp.TestMatrixRounding
 
Classes in this File Line Coverage Branch Coverage Complexity
TestMatrixRounding
92%
23/25
N/A
1
 
 1  
 /*
 2  
     This file is part of Combean.
 3  
 
 4  
     Combean is free software; you can redistribute it and/or modify
 5  
     it under the terms of the GNU General Public License as published by
 6  
     the Free Software Foundation; either version 2 of the License, or
 7  
     (at your option) any later version.
 8  
 
 9  
     Combean is distributed in the hope that it will be useful,
 10  
     but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12  
     GNU General Public License for more details.
 13  
 
 14  
     You should have received a copy of the GNU General Public License
 15  
     along with Combean; if not, write to the Free Software
 16  
     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 17  
 */
 18  
 /*
 19  
  * Created on 04.08.2006
 20  
  *
 21  
  */
 22  
 package net.sourceforge.combean.test.samples.mathprog.lp;
 23  
 
 24  
 import java.io.StringReader;
 25  
 
 26  
 import junit.framework.TestCase;
 27  
 import net.sourceforge.combean.interfaces.mathprog.lp.LPSolver;
 28  
 import net.sourceforge.combean.samples.mathprog.lp.matrixrounding.MatrixRoundingMain;
 29  
 import net.sourceforge.combean.test.helpers.checks.Check;
 30  
 
 31  
 public class TestMatrixRounding extends TestCase {
 32  
     
 33  6
     MatrixRoundingMain rounder = null;
 34  
     
 35  6
     String sequentialRep =
 36  
         "3 3 " +
 37  
         "3.1 6.8 7.3 " +
 38  
         "9.6 2.4 0.7 " +
 39  
         "3.6 1.2 6.5 ";
 40  
     
 41  3
     private final static double[][] expRoundedMin = {
 42  
         { 3.0, 6.0, 8.0 },
 43  
         { 9.0, 3.0, 0.0 },
 44  
         { 4.0, 1.0, 6.0 }
 45  
     };
 46  
     private final static double minVal = 30224.0;
 47  
 
 48  3
     private final static double[][] expRoundedMax = {
 49  
         { 4.0, 7.0, 7.0 },
 50  
         { 10.0, 2.0, 1.0 },
 51  
         { 3.0, 2.0, 7.0 }
 52  
     };
 53  
     private final static double maxVal = 32530.0;
 54  
 
 55  
     public static void main(String[] args) {
 56  0
         junit.textui.TestRunner.run(TestMatrixRounding.class);
 57  0
     }
 58  
 
 59  
     public TestMatrixRounding(String arg0) {
 60  6
         super(arg0);
 61  6
     }
 62  
 
 63  
     protected void setUp() throws Exception {
 64  6
         super.setUp();
 65  
         
 66  6
         this.rounder = new MatrixRoundingMain();
 67  6
     }
 68  
 
 69  
     protected void tearDown() throws Exception {
 70  6
         super.tearDown();
 71  6
     }
 72  
     
 73  
     public final void testMatrixRoundingMin() {
 74  3
         this.rounder.getLpSolver().setObjective(LPSolver.LPOBJ_MIN);
 75  3
         this.rounder.roundMatrix(new StringReader(this.sequentialRep));
 76  
         
 77  3
         double[][] result = this.rounder.getResult();
 78  
         
 79  3
         assertEquals(minVal, this.rounder.getLpSolver().getSolutionValue(), 0.1);
 80  3
         Check.compareTwoDimDoubleArrays(expRoundedMin, result, 0.1);
 81  3
     }
 82  
 
 83  
     public final void testMatrixRoundingMax() {
 84  3
         this.rounder.getLpSolver().setObjective(LPSolver.LPOBJ_MAX);
 85  3
         this.rounder.roundMatrix(new StringReader(this.sequentialRep));
 86  
         
 87  3
         double[][] result = this.rounder.getResult();
 88  
         
 89  3
         assertEquals(maxVal, this.rounder.getLpSolver().getSolutionValue(), 0.1);
 90  3
         Check.compareTwoDimDoubleArrays(expRoundedMax, result, 0.1);
 91  3
     }
 92  
 }