| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 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 | |
} |