Coverage Report - net.sourceforge.combean.test.samples.simplegraphs.TestCompositeNumberGraph
 
Classes in this File Line Coverage Branch Coverage Complexity
TestCompositeNumberGraph
96%
45/47
100%
2/2
1,125
 
 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 15.01.2005
 20  
  *
 21  
  */
 22  
 package net.sourceforge.combean.test.samples.simplegraphs;
 23  
 
 24  
 import java.util.BitSet;
 25  
 
 26  
 import junit.framework.TestCase;
 27  
 import net.sourceforge.combean.graph.NumberNode;
 28  
 import net.sourceforge.combean.interfaces.graph.EdgeIterator;
 29  
 import net.sourceforge.combean.interfaces.graph.NodeIterator;
 30  
 import net.sourceforge.combean.samples.simplegraphs.Clique;
 31  
 import net.sourceforge.combean.samples.simplegraphs.CompositeNumberGraph;
 32  
 import net.sourceforge.combean.samples.simplegraphs.NumberGraph;
 33  
 import net.sourceforge.combean.samples.simplegraphs.Path;
 34  
 import net.sourceforge.combean.test.helpers.checks.CheckGraph;
 35  
 
 36  
 /**
 37  
  * @author schickin
 38  
  *
 39  
  */
 40  15
 public class TestCompositeNumberGraph extends TestCase {
 41  
 
 42  
         private static final int PATHLEN = 5;
 43  
         private Path path;
 44  
 
 45  
         private static final int CLIQUESIZE = 5;
 46  
         private Clique clique;
 47  
         
 48  
         private NumberNode firstNode;
 49  
         private NumberNode lastPathNode;
 50  
         
 51  
         private CompositeNumberGraph lollypop;
 52  
         private CompositeNumberGraph mix;
 53  
 
 54  
         public static void main(String[] args) {
 55  0
                 junit.textui.TestRunner.run(TestCompositeNumberGraph.class);
 56  0
         }
 57  
 
 58  
         /*
 59  
          * @see TestCase#setUp()
 60  
          */
 61  
         protected void setUp() throws Exception {
 62  15
                 super.setUp();
 63  
                 
 64  15
                 this.path = new Path(PATHLEN);
 65  
 
 66  15
                 this.clique = new Clique(CLIQUESIZE);
 67  
 
 68  15
                 this.firstNode = new NumberNode(0);
 69  15
                 this.lastPathNode = new NumberNode(PATHLEN-1);
 70  
                 
 71  15
                 this.lollypop = new CompositeNumberGraph();
 72  15
                 this.lollypop.add(this.path);
 73  15
                 this.lollypop.add(this.clique, this.lastPathNode.getNodeNum());
 74  
 
 75  15
                 this.mix = new CompositeNumberGraph();
 76  15
                 this.mix.add(this.path);
 77  15
                 this.mix.add(this.clique);
 78  15
 }
 79  
 
 80  
         /*
 81  
          * @see TestCase#tearDown()
 82  
          */
 83  
         protected void tearDown() throws Exception {
 84  15
                 super.tearDown();
 85  15
         }
 86  
         
 87  
         public final void testGetNumGraphs() {
 88  3
                 assertEquals("two graphs have been added", 2,
 89  
                                 this.lollypop.getNumGraphs());
 90  3
                 assertEquals("two graphs have been added", 2,
 91  
                                 this.mix.getNumGraphs());
 92  3
         }
 93  
 
 94  
         public final void testGetNumNodes() {
 95  3
                 assertEquals("number of nodes in joined graphs must equal" +
 96  
                                 "the sum minus one overlapping node",
 97  
                                 PATHLEN+CLIQUESIZE-1, this.lollypop.getNumNodes());
 98  3
                 assertEquals("number of nodes in joined graphs must equal" +
 99  
                                 "the maximum of nodes in the individual graphs",
 100  
                                 Math.max(PATHLEN, CLIQUESIZE), this.mix.getNumNodes());
 101  3
         }
 102  
 
 103  
         public final void testGetAllNodesIterator() {
 104  3
                 NodeIterator itAllNodes = this.lollypop.getAllNodesIterator();
 105  3
                 BitSet nodesSeen = new BitSet(PATHLEN+CLIQUESIZE);
 106  3
                 nodesSeen.clear();
 107  30
                 while (itAllNodes.hasNext()) {
 108  27
                         NumberNode currNode = (NumberNode) itAllNodes.next();
 109  27
                         nodesSeen.set(currNode.getNodeNum());
 110  27
                 }
 111  3
                 assertEquals("all nodes must have been seen", PATHLEN+CLIQUESIZE-1,
 112  
                                 nodesSeen.nextClearBit(0));
 113  3
         }
 114  
 
 115  
         public final void testGetIncidentEdges() {
 116  3
                 EdgeIterator itNeigh = null;
 117  
                 
 118  3
                 itNeigh = this.lollypop.getIncidentEdges(this.firstNode);
 119  3
                 CheckGraph.checkNumIterations(itNeigh, 1);
 120  3
                 itNeigh = this.lollypop.getIncidentEdges(this.lastPathNode);
 121  3
                 CheckGraph.checkNumIterations(itNeigh, CLIQUESIZE-1+1);
 122  
 
 123  3
                 itNeigh = this.mix.getIncidentEdges(this.firstNode);
 124  3
                 CheckGraph.checkNumIterations(itNeigh, CLIQUESIZE-1);
 125  3
                 itNeigh = this.mix.getIncidentEdges(this.lastPathNode);
 126  3
                 CheckGraph.checkNumIterations(itNeigh, CLIQUESIZE-1);
 127  3
 }
 128  
 
 129  
         public final void testContains() {
 130  3
                 assertTrue(this.lollypop.contains(new NumberNode(0)));
 131  3
                 assertTrue(this.lollypop.contains(new NumberNode(PATHLEN+CLIQUESIZE-2)));
 132  3
                 assertFalse(this.lollypop.contains(new NumberNode(PATHLEN+CLIQUESIZE-1)));
 133  3
                 assertFalse(this.lollypop.contains(new NumberNode(NumberGraph.NOSUCHNODE)));
 134  3
         }
 135  
 
 136  
 }