Class Name:
kiasan.examples.stack.StackLi Report Rendered: Mon May 04 12:43:42 CDT 2009, by Sireum/Kiasan for Java v0.1.20090504
| Branches Covered For Tests: 4/4 (100%) | |
| Instructions Covered For Tests: 53/53 (100%) |
| Branches Covered For Class: 12/28 (42%) | |
| Instructions Covered For Class: 81/138 (58%) |
Methods Covered:
| Class / Method | T | E | Instruction Coverage | Branch Coverage | Time |
| 2 | 1 |
35/35
100%
|
4/4
100%
|
0.201s | |
| 3 | 0 |
18/18
100%
|
0/0
100%
|
0.215s | |
|
Total
|
5 | 1 |
53/53
100%
|
4/4
100%
|
0.416s |
Source Code:
1 package kiasan.examples.stack;
2
3 import kiasan.examples.common.Underflow;
4
5 // StackLi class
6 //
7 // CONSTRUCTION: with no initializer
8 //
9 // ******************PUBLIC OPERATIONS*********************
10 // void push( x ) --> Insert x
11 // void pop( ) --> Remove most recently inserted item
12 // Object top( ) --> Return most recently inserted item
13 // Object topAndPop( ) --> Return and remove most recent item
14 // boolean isEmpty( ) --> Return true if empty; else false
15 // boolean isFull( ) --> Always returns false
16 // void makeEmpty( ) --> Remove all items
17 // ******************ERRORS********************************
18 // pop on empty stack
19
20 /**
21 * List-based implementation of the stack.
22 *
23 * @author Mark Allen Weiss
24 */
25 public class StackLi {
26 public static void main(final String[] args) {
27 final StackLi s = new StackLi();
28
29 for (int i = 0; i < 10; i++) {
30 s.push(new Integer(i));
31 }
32
33 while (!s.isEmpty()) {
34 System.out.println(s.topAndPop());
35 }
36 }
37
38 private ListNode topOfStack;
39
40 /**
41 * Construct the stack.
42 */
46
47 private boolean contains(final Object e) {
52 }
54 }
56 }
57
58 boolean isAcyclic() {
64 }
67 }
69 }
70
71 /**
72 * Test if the stack is logically empty.
73 *
74 * @return true if empty, false otherwise.
75 */
76 public boolean isEmpty() {
78 }
79
80 /**
81 * Test if the stack is logically full.
82 *
83 * @return false always, in this implementation.
84 */
85 public boolean isFull() {
86 return false;
87 }
88
89 /**
90 * Make the stack logically empty.
91 */
92 public void makeEmpty() {
93 this.topOfStack = null;
94 }
95
96 /**
97 * Remove the most recently inserted item from the stack.
98 *
99 * @exception Underflow
100 * if the stack is empty.
101 */
102 //@ requires this.isAcyclic();
103 //@ ensures this.isAcyclic();
104 public void pop() throws Underflow {
107 }
110
111 /**
112 * Insert a new item into the stack.
113 *
114 * @param x
115 * the item to insert.
116 */
117 //@ requires this.isAcyclic();
118 //@ ensures this.isAcyclic() && this.topOfStack.element == x;
119 public void push(final Object x) {
122
123 /**
124 * Get the most recently inserted item in the stack. Does not alter the stack.
125 *
126 * @return the most recently inserted item in the stack, or null, if empty.
127 */
128 public Object top() {
129 if (isEmpty()) {
130 return null;
131 }
132 return this.topOfStack.element;
133 }
134
135 /**
136 * Return and remove the most recently inserted item from the stack.
137 *
138 * @return the most recently inserted item in the stack, or null, if empty.
139 */
140 public Object topAndPop() {
141 if (isEmpty()) {
142 return null;
143 }
144
145 final Object topItem = this.topOfStack.element;
146 this.topOfStack = this.topOfStack.next;
147 return topItem;
148 }
149 }
2
3 import kiasan.examples.common.Underflow;
4
5 // StackLi class
6 //
7 // CONSTRUCTION: with no initializer
8 //
9 // ******************PUBLIC OPERATIONS*********************
10 // void push( x ) --> Insert x
11 // void pop( ) --> Remove most recently inserted item
12 // Object top( ) --> Return most recently inserted item
13 // Object topAndPop( ) --> Return and remove most recent item
14 // boolean isEmpty( ) --> Return true if empty; else false
15 // boolean isFull( ) --> Always returns false
16 // void makeEmpty( ) --> Remove all items
17 // ******************ERRORS********************************
18 // pop on empty stack
19
20 /**
21 * List-based implementation of the stack.
22 *
23 * @author Mark Allen Weiss
24 */
25 public class StackLi {
26 public static void main(final String[] args) {
27 final StackLi s = new StackLi();
28
29 for (int i = 0; i < 10; i++) {
30 s.push(new Integer(i));
31 }
32
33 while (!s.isEmpty()) {
34 System.out.println(s.topAndPop());
35 }
36 }
37
38 private ListNode topOfStack;
39
40 /**
41 * Construct the stack.
42 */
46
47 private boolean contains(final Object e) {
52 }
54 }
56 }
57
58 boolean isAcyclic() {
64 }
67 }
69 }
70
71 /**
72 * Test if the stack is logically empty.
73 *
74 * @return true if empty, false otherwise.
75 */
76 public boolean isEmpty() {
78 }
79
80 /**
81 * Test if the stack is logically full.
82 *
83 * @return false always, in this implementation.
84 */
85 public boolean isFull() {
86 return false;
87 }
88
89 /**
90 * Make the stack logically empty.
91 */
92 public void makeEmpty() {
93 this.topOfStack = null;
94 }
95
96 /**
97 * Remove the most recently inserted item from the stack.
98 *
99 * @exception Underflow
100 * if the stack is empty.
101 */
102 //@ requires this.isAcyclic();
103 //@ ensures this.isAcyclic();
104 public void pop() throws Underflow {
107 }
110
111 /**
112 * Insert a new item into the stack.
113 *
114 * @param x
115 * the item to insert.
116 */
117 //@ requires this.isAcyclic();
118 //@ ensures this.isAcyclic() && this.topOfStack.element == x;
119 public void push(final Object x) {
122
123 /**
124 * Get the most recently inserted item in the stack. Does not alter the stack.
125 *
126 * @return the most recently inserted item in the stack, or null, if empty.
127 */
128 public Object top() {
129 if (isEmpty()) {
130 return null;
131 }
132 return this.topOfStack.element;
133 }
134
135 /**
136 * Return and remove the most recently inserted item from the stack.
137 *
138 * @return the most recently inserted item in the stack, or null, if empty.
139 */
140 public Object topAndPop() {
141 if (isEmpty()) {
142 return null;
143 }
144
145 final Object topItem = this.topOfStack.element;
146 this.topOfStack = this.topOfStack.next;
147 return topItem;
148 }
149 }