Coverage Report - net.sourceforge.combean.test.mathprog.grooml.TestGLPModel
 
Classes in this File Line Coverage Branch Coverage Complexity
TestGLPModel
100%
18/18
62%
15/24
0
TestGLPModel$_setUp_closure1
100%
2/2
83%
5/6
0
TestGLPModel$_setUp_closure2
100%
2/2
75%
3/4
0
 
 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 Foobar; if not, write to the Free Software
 16  
     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 17  
 */
 18  
 package net.sourceforge.combean.test.mathprog.grooml;
 19  
 
 20  
 import net.sourceforge.combean.mathprog.grooml.GLPModel;
 21  
 import net.sourceforge.combean.mathprog.grooml.GVariables;
 22  
 import net.sourceforge.combean.mathprog.grooml.GRows;
 23  
 import net.sourceforge.combean.mathprog.grooml.GSet;
 24  
 
 25  
 class TestGLPModel extends GroovyTestCase {
 26  
     
 27  
     private GLPModel lpModel;
 28  
     private GVariables lpVars;
 29  
     private GRows lpRows;
 30  
     
 31  
     private static final double[] coeff = [4.0, 10.0];
 32  
     private static final double[] rhs = [2.0, 2.0, 10.0];
 33  
     
 34  
     void setUp() {
 35  12
         this.lpModel = new GLPModel();
 36  12
         this.lpVars = new GVariables("x", 0..(coeff.length-1), [:]) {
 37  6
             [coeff[it], 0..Double.POSITIVE_INFINITY]
 38  
         }
 39  12
         this.lpRows = new GRows("row", 0..2, this.lpModel, [:]) {
 40  9
             ["x[${it % 2}]", "<= ${rhs[it]}"]
 41  
         }
 42  
     }
 43  
 
 44  
         void testAddAndGetVariables() {
 45  3
             assertEquals(0, this.lpModel.numColumns);
 46  3
                 this.lpModel.addVariables(this.lpVars);
 47  3
             assertEquals(coeff.length, this.lpModel.numColumns);
 48  3
             GVariables vars = this.lpModel.getVariables("x");
 49  3
             assertEquals(this.lpVars, vars);
 50  
         }
 51  
 
 52  
         void testAddConstraints() {
 53  3
             assertEquals(0, this.lpModel.numRows);
 54  3
                 this.lpModel.addConstraints(this.lpRows);
 55  3
             assertEquals(rhs.length, this.lpModel.numRows);
 56  
         }
 57  
 
 58  
         void testAddRows() {
 59  3
             assertEquals(0, this.lpModel.numRows);
 60  3
                 this.lpModel.addRows(this.lpRows);
 61  3
             assertEquals(rhs.length, this.lpModel.numRows);
 62  
         }
 63  
         
 64  
         void testSummaryString() {
 65  3
                 this.lpModel.addVariables(this.lpVars);
 66  3
                 this.lpModel.addRows(this.lpRows);
 67  3
             assertEquals("""
 68  
 vars  x[4.0, 10.0]
 69  
 row:
 70  
   1.0 x[0] <= 2.0
 71  
   1.0 x[1] <= 2.0
 72  
   1.0 x[0] <= 10.0
 73  3
 """, this.lpModel.toSummaryString());
 74  
         }
 75  
 }