Browse Source

Anlegen der (Basis) Stack-Tests + Klasse

vollständige_und_weitere_testate
chris 3 years ago
parent
commit
6d8f36c556
  1. 289
      SimpleActivityStack/src/testat/ASimpleStackTestBase.java

289
SimpleActivityStack/src/testat/ASimpleStackTestBase.java

@ -0,0 +1,289 @@
package testat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.EmptyStackException;
import java.util.Set;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/**
*
* @author Christian
*
*/
public abstract class ASimpleStackTestBase<T> {
protected ISimpleStack<T> sstack;
protected boolean temp1 = false, temp2=true;
protected abstract ISimpleStack<T> getInstance();
protected IAction<T> act1, act2;
protected T s1;
protected T s2;
protected T s3;
protected T s4;
protected T s5;
protected T s6;
protected T s7;
protected T s8;
protected T s9;
protected T s10;
abstract protected void init() ;
@BeforeAll
static void setUpBeforeClass() throws Exception {
}
@BeforeEach
void setUp() throws Exception {
init();
sstack = getInstance();
}
@Test
public void testPush_1_Null() {
assertEquals(0, sstack.push(null));
}
@Test
public void testPush_2_Single() {
assertEquals(1, sstack.push(s1));
}
@Test
public void testPush_3_Multiple() {
sstack.push(s1);
sstack.push(s2);
sstack.push(s3);
sstack.push(s4);
sstack.push(s5);
sstack.push(s6);
sstack.push(s7);
assertEquals(8, sstack.push(s8));
}
@Test
public void testSize_1_Initial() {
assertEquals(0, sstack.size());
}
@Test
public void testSize_2_AfterPush() {
sstack.push(s1);
assertEquals(1, sstack.size());
}
@Test
public void testSize_3_AfterPushs() {
sstack.push(s1);
sstack.push(s2);
sstack.push(s3);
sstack.push(s4);
sstack.push(s5);
assertEquals(5, sstack.size());
}
@Test
public void testGet_1_Simple() {
sstack.push(s1);
assertEquals(s1, sstack.get(0));
}
@Test
public void testGet_2_Multiple() {
sstack.push(s1);
sstack.push(s2);
sstack.push(s3);
sstack.push(s4);
sstack.push(s5);
assertEquals(s3, sstack.get(2));
}
@Test
public void testGet_3_ErrorHandling_1() {
sstack.push(s1);
sstack.push(s2);
try {
sstack.get(-1);
} catch (Exception e) {
assertEquals(true, e instanceof IndexOutOfBoundsException);
assertEquals(false, e instanceof EmptyStackException);
} finally {
assertEquals(2, sstack.size());
}
}
@Test
public void testGet_4_ErrorHandling_2() {
sstack.push(s1);
sstack.push(s2);
try {
sstack.get(5);
} catch (Exception e) {
assertEquals(true, e instanceof IndexOutOfBoundsException);
} finally {
assertEquals(2, sstack.size());
}
}
@Test
public void testPop_1_Initial() {
assertEquals(null, sstack.pop());
}
@Test
public void testPop_2_Single() {
sstack.push(s1);
assertEquals(s1, sstack.pop());
}
@Test
public void testPop_3_Multiple() {
sstack.push(s1);
sstack.push(s2);
sstack.push(s3);
sstack.push(s4);
sstack.push(s5);
assertEquals(s5, sstack.pop());
assertEquals(s4, sstack.pop());
assertEquals(s3, sstack.pop());
}
@Test
public void testPush_4_Existing() {
sstack.push(s1);
sstack.push(s2);
sstack.push(s3);
sstack.push(s4);
sstack.push(s5);
sstack.push(s2);
assertEquals(s2, sstack.pop());
}
@Test
public void testPush_5_AfterPop() {
// TODO Test Push after Pop
sstack.push(s1);
sstack.push(s2);
sstack.push(s3);
sstack.push(s4);
sstack.push(s5);
sstack.pop();
sstack.push(s7);
assertEquals(6, sstack.push(s8));
}
@Test
public void testGet_5_AfterPop() {
sstack.push(s1);
sstack.push(s2);
sstack.push(s3);
sstack.push(s4);
sstack.push(s5);
sstack.pop();
sstack.pop();
sstack.pop();
sstack.push(s6);
sstack.push(s7);
assertEquals(s6, sstack.get(2));
}
@Test
public void testRemove_1_One() {
sstack.push(s1);
assertEquals(s1, sstack.remove(0));
}
@Test
public void testRemove_2_Index() {
sstack.push(s1);
sstack.push(s2);
try {
sstack.remove(-1);
} catch (Exception e) {
assertEquals(true, e instanceof IndexOutOfBoundsException);
} finally {
assertEquals(2, sstack.size());
}
try {
sstack.remove(5);
} catch (Exception e) {
assertEquals(true, e instanceof IndexOutOfBoundsException);
} finally {
assertEquals(2, sstack.size());
}
}
@Test
public void testRemove_4_Multiple() {
sstack.push(s1);
sstack.push(s2);
sstack.push(s3);
sstack.push(s4);
sstack.push(s5);
assertEquals(s3, sstack.remove(2));
assertEquals(4, sstack.size());
}
@Test
public void testContains_1() {
assertEquals(false, sstack.contains(s2));
sstack.push(s1);
sstack.push(s2);
sstack.push(s3);
assertEquals(false, sstack.contains(s4));
assertEquals(true, sstack.contains(s2));
assertEquals(true, sstack.contains(s3));
assertEquals(s3, sstack.pop());
assertEquals(false, sstack.contains(s3));
}
@Test
public void testForAll_1() {
assertEquals(false, temp1);
assertEquals(true, temp2);
this.sstack.forAll(act1);
this.sstack.forAll(act2);
assertEquals(true, temp1);
assertEquals(true, temp2);
}
@Test
public void testSize_4_AfterRemove_1() {
sstack.push(s1);
sstack.pop();
assertEquals(0, sstack.size());
}
@Test
public void testSize_4_AfterRemove_2() {
sstack.push(s1);
sstack.push(s2);
sstack.push(s3);
sstack.pop();
assertEquals(2, sstack.size());
}
}
Loading…
Cancel
Save