Coverage Report - net.sourceforge.combean.test.graph.containers.AbstractTestNodeSet
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractTestNodeSet
94%
47/50
N/A
1,091
 
 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 20.02.2005
 20  
  *
 21  
  */
 22  
 package net.sourceforge.combean.test.graph.containers;
 23  
 
 24  
 import junit.framework.TestCase;
 25  
 import net.sourceforge.combean.graph.NumberNode;
 26  
 import net.sourceforge.combean.interfaces.graph.NodeIterator;
 27  
 import net.sourceforge.combean.interfaces.graph.containers.NodeSet;
 28  
 import net.sourceforge.combean.test.helpers.checks.CheckGraph;
 29  
 import net.sourceforge.combean.util.except.UnsupportedMethodException;
 30  
 
 31  
 /**
 32  
  * @author schickin
 33  
  *
 34  
  */
 35  
 abstract class AbstractTestNodeSet extends TestCase {
 36  
 
 37  
     protected static final int GRAPHSIZE = 5;
 38  
     
 39  30
     private NodeSet nodeSet = null;
 40  30
     private NumberNode v = null;
 41  30
     private NumberNode otherV = null;
 42  30
     private NumberNode w = null;
 43  
 
 44  
 
 45  
     public static void main(String[] args) {
 46  0
         junit.textui.TestRunner.run(AbstractTestNodeSet.class);
 47  0
     }
 48  
 
 49  
     /* (non-Javadoc)
 50  
      * @see junit.framework.TestCase#setUp()
 51  
      */
 52  
     protected void setUp() throws Exception {
 53  
         /*
 54  
         Testcase cannot be used stand-alone.
 55  
         */
 56  0
         throw new UnsupportedMethodException();
 57  
     }
 58  
     
 59  
     /*
 60  
      * @see TestCase#setUp()
 61  
      */
 62  
     protected void setUp(NodeSet nodeSet) throws Exception {
 63  30
         super.setUp();
 64  
 
 65  30
         this.nodeSet = nodeSet;
 66  30
         this.v = new NumberNode(1);
 67  30
                 this.otherV = new NumberNode(1);
 68  30
                 this.w = new NumberNode(GRAPHSIZE-1);
 69  30
     }
 70  
 
 71  
     /*
 72  
      * @see TestCase#tearDown()
 73  
      */
 74  
     protected void tearDown() throws Exception {
 75  30
         super.tearDown();
 76  30
     }
 77  
 
 78  
     /**
 79  
      * Constructor for TestNodeSet.
 80  
      * @param name
 81  
      */
 82  
     public AbstractTestNodeSet(String name) {
 83  30
         super(name);
 84  30
     }
 85  
 
 86  
     private void checkEmptySet() {
 87  12
             assertTrue("empty set seems to be non-empty", this.nodeSet.isEmpty());
 88  12
             assertEquals("empty set has non-zero size", this.nodeSet.size(), 0);
 89  12
             assertFalse("empty set contains a node", this.nodeSet.contains(this.v));
 90  12
     }
 91  
 
 92  
     public void testAccessToEmptySet() {
 93  6
             checkEmptySet();
 94  6
     }
 95  
 
 96  
     public void testReadAndWriteAccess() {
 97  6
             this.nodeSet.add(this.v);
 98  6
             assertFalse("set is empty after adding node", this.nodeSet.isEmpty());
 99  6
             assertEquals("wrong size", this.nodeSet.size(), 1);
 100  6
             assertTrue("node not in set after adding it", this.nodeSet.contains(this.v));
 101  6
             this.nodeSet.add(this.w);
 102  6
             assertEquals("wrong size", 2, this.nodeSet.size());
 103  6
             this.nodeSet.remove(this.v);
 104  6
             assertEquals("wrong size", 1, this.nodeSet.size());
 105  6
             assertFalse("node still in set after removing it", this.nodeSet.contains(this.v));
 106  6
             this.nodeSet.remove(this.w);
 107  6
             assertTrue("set must be empty", this.nodeSet.isEmpty());
 108  6
     }
 109  
 
 110  
     public void testClear() {
 111  6
             this.nodeSet.add(this.v);
 112  6
             this.nodeSet.add(this.w);
 113  6
             this.nodeSet.clear();
 114  6
             checkEmptySet();
 115  6
     }
 116  
 
 117  
     public void testContains() {
 118  6
             this.nodeSet.add(this.v);
 119  6
             assertTrue("node not in set after adding it", this.nodeSet.contains(this.otherV));
 120  6
             this.nodeSet.remove(this.otherV);                
 121  6
             assertTrue("set must be empty", this.nodeSet.isEmpty());
 122  6
     }
 123  
 
 124  
     public void testIterator() {
 125  6
             this.nodeSet.add(this.v);
 126  6
             this.nodeSet.add(this.w);
 127  
             
 128  6
             NodeIterator it = this.nodeSet.iterator();
 129  6
             CheckGraph.checkNumIterations(it, 2);
 130  6
     }
 131  
 }