Class Name:
kiasan.examples.stack.StackAr Report Rendered: Mon May 04 11:28:33 CDT 2009, by Sireum/Kiasan for Java v0.1.20090504
| Branches Covered For Tests: 16/22 (72%) | |
| Instructions Covered For Tests: 145/157 (92%) |
| Branches Covered For Class: 11/30 (36%) | |
| Instructions Covered For Class: 96/164 (58%) |
Methods Covered:
| Class / Method | T | E | Instruction Coverage | Branch Coverage | Time |
| 1 | 1 |
31/33
93.94%
|
3/4
75%
|
0.195s | |
| 1 | 2 |
37/37
100%
|
4/4
100%
|
0.203s | |
| 1 | 1 |
77/87
88.51%
|
9/14
64.29%
|
0.235s | |
|
Total
|
3 | 4 |
145/157
92.36%
|
16/22
72.73%
|
0.633s |
Source Code:
1 package kiasan.examples.stack;
2
3 import kiasan.examples.common.Overflow;
4 import kiasan.examples.common.Underflow;
5
6 // StackAr class
7 //
8 // CONSTRUCTION: with or without a capacity; default is 10
9 //
10 // ******************PUBLIC OPERATIONS*********************
11 // void push( x ) --> Insert x
12 // void pop( ) --> Remove most recently inserted item
13 // Object top( ) --> Return most recently inserted item
14 // Object topAndPop( ) --> Return and remove most recently inserted item
15 // boolean isEmpty( ) --> Return true if empty; else false
16 // boolean isFull( ) --> Return true if full; else false
17 // void makeEmpty( ) --> Remove all items
18 // ******************ERRORS********************************
19 // Overflow and Underflow thrown as needed
20
21 /**
22 * Array-based implementation of the stack.
23 *
24 * @author Mark Allen Weiss
25 */
26 public class StackAr {
27 private final Object[] theArray;
28
29 private int topOfStack;
30
31 static final int DEFAULT_CAPACITY = 10;
32
33 public static void main(final String[] args) {
34 final StackAr s = new StackAr(12);
35
36 try {
37 for (int i = 0; i < 10; i++) {
38 s.push(new Integer(i));
39 }
40 } catch (final Overflow e) {
41 System.out.println("Unexpected overflow");
42 }
43
44 while (!s.isEmpty()) {
45 System.out.println(s.topAndPop());
46 }
47 }
48
49 /**
50 * Construct the stack.
51 */
52 public StackAr() {
53 this(StackAr.DEFAULT_CAPACITY);
54 }
55
56 /**
57 * Construct the stack.
58 *
59 * @param capacity
60 * the capacity.
61 */
62 public StackAr(final int capacity) {
63 this.theArray = new Object[capacity];
64 this.topOfStack = -1;
65 }
66
67 /**
68 * Test if the stack is logically empty.
69 *
70 * @return true if empty, false otherwise.
71 */
72 public boolean isEmpty() {
74 }
75
76 /**
77 * Test if the stack is logically full.
78 *
79 * @return true if full, false otherwise.
80 */
81 public boolean isFull() {
83 }
84
85 /**
86 * Make the stack logically empty.
87 */
88 public void makeEmpty() {
89 this.topOfStack = -1;
90 }
91
92 /**
93 * Remove the most recently inserted item from the stack.
94 *
95 * @exception Underflow
96 * if stack is already empty.
97 */
98 //@ requires (this.theArray != null) && (this.theArray.length >= 0) && (this.topOfStack >= -1) && (this.topOfStack < this.theArray.length);
99 //@ ensures true;
100 public void pop() throws Underflow {
103 }
106
107 /**
108 * Insert a new item into the stack, if not already full.
109 *
110 * @param x
111 * the item to insert.
112 * @exception Overflow
113 * if stack is already full.
114 */
115 //@ requires (this.theArray != null) && (this.theArray.length > 0) && (this.topOfStack >= -1) && (this.topOfStack < this.theArray.length);
116 //@ ensures this.theArray[this.topOfStack] == x;
117 public void push(final Object x) throws Overflow {
120 }
123
124 //@ requires (this.theArray != null) && (this.theArray.length > 0) && !isFull() && (this.topOfStack >= -1) && (this.topOfStack < this.theArray.length);
125 //@ ensures true;
126 public void pushPop(final Object x) throws Overflow {
131
132 /**
133 * Get the most recently inserted item in the stack. Does not alter the stack.
134 *
135 * @return the most recently inserted item in the stack, or null, if empty.
136 */
137 public Object top() {
139 return null;
140 }
142 }
143
144 /**
145 * Return and remove most recently inserted item from the stack.
146 *
147 * @return most recently inserted item, or null, if stack is empty.
148 */
149 public Object topAndPop() {
151 return null;
152 }
156 }
157
158 }
2
3 import kiasan.examples.common.Overflow;
4 import kiasan.examples.common.Underflow;
5
6 // StackAr class
7 //
8 // CONSTRUCTION: with or without a capacity; default is 10
9 //
10 // ******************PUBLIC OPERATIONS*********************
11 // void push( x ) --> Insert x
12 // void pop( ) --> Remove most recently inserted item
13 // Object top( ) --> Return most recently inserted item
14 // Object topAndPop( ) --> Return and remove most recently inserted item
15 // boolean isEmpty( ) --> Return true if empty; else false
16 // boolean isFull( ) --> Return true if full; else false
17 // void makeEmpty( ) --> Remove all items
18 // ******************ERRORS********************************
19 // Overflow and Underflow thrown as needed
20
21 /**
22 * Array-based implementation of the stack.
23 *
24 * @author Mark Allen Weiss
25 */
26 public class StackAr {
27 private final Object[] theArray;
28
29 private int topOfStack;
30
31 static final int DEFAULT_CAPACITY = 10;
32
33 public static void main(final String[] args) {
34 final StackAr s = new StackAr(12);
35
36 try {
37 for (int i = 0; i < 10; i++) {
38 s.push(new Integer(i));
39 }
40 } catch (final Overflow e) {
41 System.out.println("Unexpected overflow");
42 }
43
44 while (!s.isEmpty()) {
45 System.out.println(s.topAndPop());
46 }
47 }
48
49 /**
50 * Construct the stack.
51 */
52 public StackAr() {
53 this(StackAr.DEFAULT_CAPACITY);
54 }
55
56 /**
57 * Construct the stack.
58 *
59 * @param capacity
60 * the capacity.
61 */
62 public StackAr(final int capacity) {
63 this.theArray = new Object[capacity];
64 this.topOfStack = -1;
65 }
66
67 /**
68 * Test if the stack is logically empty.
69 *
70 * @return true if empty, false otherwise.
71 */
72 public boolean isEmpty() {
74 }
75
76 /**
77 * Test if the stack is logically full.
78 *
79 * @return true if full, false otherwise.
80 */
81 public boolean isFull() {
83 }
84
85 /**
86 * Make the stack logically empty.
87 */
88 public void makeEmpty() {
89 this.topOfStack = -1;
90 }
91
92 /**
93 * Remove the most recently inserted item from the stack.
94 *
95 * @exception Underflow
96 * if stack is already empty.
97 */
98 //@ requires (this.theArray != null) && (this.theArray.length >= 0) && (this.topOfStack >= -1) && (this.topOfStack < this.theArray.length);
99 //@ ensures true;
100 public void pop() throws Underflow {
103 }
106
107 /**
108 * Insert a new item into the stack, if not already full.
109 *
110 * @param x
111 * the item to insert.
112 * @exception Overflow
113 * if stack is already full.
114 */
115 //@ requires (this.theArray != null) && (this.theArray.length > 0) && (this.topOfStack >= -1) && (this.topOfStack < this.theArray.length);
116 //@ ensures this.theArray[this.topOfStack] == x;
117 public void push(final Object x) throws Overflow {
120 }
123
124 //@ requires (this.theArray != null) && (this.theArray.length > 0) && !isFull() && (this.topOfStack >= -1) && (this.topOfStack < this.theArray.length);
125 //@ ensures true;
126 public void pushPop(final Object x) throws Overflow {
131
132 /**
133 * Get the most recently inserted item in the stack. Does not alter the stack.
134 *
135 * @return the most recently inserted item in the stack, or null, if empty.
136 */
137 public Object top() {
139 return null;
140 }
142 }
143
144 /**
145 * Return and remove most recently inserted item from the stack.
146 *
147 * @return most recently inserted item, or null, if stack is empty.
148 */
149 public Object topAndPop() {
151 return null;
152 }
156 }
157
158 }