Coverage Report - net.sourceforge.combean.test.graph.containers.TestStackAsNodeStack
 
Classes in this File Line Coverage Branch Coverage Complexity
TestStackAsNodeStack
81%
25/31
100%
4/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 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 java.util.EmptyStackException;
 25  
 import java.util.Stack;
 26  
 
 27  
 import junit.framework.TestCase;
 28  
 import net.sourceforge.combean.graph.NumberNode;
 29  
 import net.sourceforge.combean.graph.containers.StackAsNodeStack;
 30  
 import net.sourceforge.combean.interfaces.graph.Node;
 31  
 import net.sourceforge.combean.interfaces.graph.containers.NodeStack;
 32  
 
 33  
 /**
 34  
  * @author schickin
 35  
  *
 36  
  */
 37  
 public class TestStackAsNodeStack extends TestCase {
 38  
     
 39  6
     private NodeStack S = null;
 40  
     private static final int STACKSIZE = 4;
 41  
     
 42  
     public static void main(String[] args) {
 43  0
         junit.textui.TestRunner.run(TestStackAsNodeStack.class);
 44  0
     }
 45  
 
 46  
     /*
 47  
      * @see TestCase#setUp()
 48  
      */
 49  
     protected void setUp() throws Exception {
 50  6
         super.setUp();
 51  6
         Stack<Node> genericStack = new Stack<Node>();
 52  6
         this.S = new StackAsNodeStack(genericStack);
 53  6
     }
 54  
 
 55  
     /*
 56  
      * @see TestCase#tearDown()
 57  
      */
 58  
     protected void tearDown() throws Exception {
 59  6
         super.tearDown();
 60  6
     }
 61  
 
 62  
     /**
 63  
      * Constructor for TestStackAsNodeStack.
 64  
      * @param name
 65  
      */
 66  
     public TestStackAsNodeStack(String name) {
 67  6
         super(name);
 68  6
     }
 69  
 
 70  
     public void testWorkWithStack() {
 71  15
         for (int i = 0; i < STACKSIZE; i++) {
 72  12
             this.S.push(new NumberNode(i));
 73  
         }
 74  3
         assertFalse("stack is non-empty", this.S.isEmpty());
 75  15
         for (int i = STACKSIZE-1; i >= 0; i--) {
 76  12
             NumberNode v = (NumberNode) this.S.peek();
 77  12
             assertEquals(i, v.getNodeNum());
 78  12
             v = (NumberNode) this.S.pop();
 79  12
             assertEquals(i, v.getNodeNum());
 80  
         }
 81  3
         assertTrue("stack is empty after removing all elements",
 82  
                 this.S.isEmpty());
 83  3
     }
 84  
 
 85  
     public void testEmptyStack() {
 86  3
         assertTrue("initially the stack is empty", this.S.isEmpty());
 87  
         try {
 88  3
             this.S.peek();
 89  0
             fail("cannot peek on empty stack");
 90  
         }
 91  3
         catch (EmptyStackException e) {
 92  
             /* expected exception has been thrown */
 93  0
         }
 94  
         try {
 95  3
             this.S.pop();
 96  0
             fail("cannot peek on empty stack");
 97  
         }
 98  3
         catch (EmptyStackException e) {
 99  
             /* expected exception has been thrown */
 100  0
         }
 101  3
     }
 102  
 
 103  
 }