AuD
Lecture 'Algorithmen und Datenstrukturen' (code examples)
StackTest.java
Go to the documentation of this file.
1package aud.test;
2
3import aud.Stack;
4import java.util.NoSuchElementException;
5
6import org.junit.*;
7import static org.junit.Assert.*;
8
9public class StackTest {
10
11 @Test
12 public void testStack() {
14
15 assertTrue(stack.is_empty());
16 stack.push(1);
17 assertFalse(stack.is_empty());
18 assertEquals(stack.top().intValue(),1);
19
20 stack.pop();
21 assertTrue(stack.is_empty());
22
23 stack.push(1);
24 stack.push(2);
25 stack.push(3);
26 assertTrue(stack.pop()==3);
27 assertTrue(stack.pop()==2);
28 assertTrue(stack.pop()==1);
29 assertTrue(stack.is_empty());
30 }
31
32 @Test(expected=NoSuchElementException.class)
33 public void testInvalid_top() {
35 stack.top();
36 }
37 @Test(expected=NoSuchElementException.class)
38 public void testInvalid_pop() {
40 stack.pop();
41 }
42
43 public static void main(String args[]) {
44 org.junit.runner.JUnitCore.main("aud.test.StackTest");
45 }
46}
Implementation of a stack based on aud.Vector.
Definition: Stack.java:8
void push(T x)
Push x onto stack.
Definition: Stack.java:31
boolean is_empty()
Is stack empty?
Definition: Stack.java:14
T pop()
Pop element from stack.
Definition: Stack.java:23
T top()
Get stack top.
Definition: Stack.java:17
void testInvalid_top()
Definition: StackTest.java:33
static void main(String args[])
Definition: StackTest.java:43
void testInvalid_pop()
Definition: StackTest.java:38
AuD lecture: Data structures, algorithms, examples.
Definition: A234Tree.java:1