Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as Java by anonymous ( 15 years ago )
package calccheck;
import org.junit.*;
import static org.junit.Assert.*;
import java.util.*;
public class JUnitTest{
private Stack<Double> linkedStack;
private Stack<Double> arrayStack;
@Before
public void setUp(){
linkedStack = new LinkedStack<Double>();
arrayStack = new ArraybasedStack<Double>();
}
@Test
public void testEmptyLinkedStack(){
assertTrue(linkedStack.isEmpty());
}
@Test
public void testPushItemToLinkedStack(){
linkedStack.push(1);
assertEquals(1, linkedStack.getSize());
}
@Test
public void testPushItemToArraybasedStack(){
arrayStack.push(1);
assertEquals(1, arrayStack.getSize());
}
@Test
public void testPopItemFromLinkedStack(){
arrayStack.push(1);
linkedStack.pop();
assertEquals(0, arrayStack.getSize());
}
@Test(expected = RuntimeException.class)
public void testPopFromEmptyLinkedStack(){
Stack<Double> emptyLinkedStack = new LinkedStack<Double>();
emptyLinkedStack.pop();
}
@Test(expected = RuntimeException.class)
public void testPopFromEmptyArrayStack(){
Stack<Double> emptyArrayStack = new ArraybasedStack<Double>();
emptyArrayStack.pop();
}
@Test(expected = RuntimeException.class)
public void testPushToFullArrayStack(){
while(!arrayStack.isFull()){arrayStack.push(1);}
arrayStack.push(2);
}
@Test(expected = SyntaxError.class)
public void testIncorrectPostfix[removed]){
RPNCalculator.calc({1, 2, 3, +});
}
// intentionally left out when writing RPNCalculator
@Test(expected = Exception.class)
public void testDivisionPerZero(){
RPNCalculator.calc({1, 0, "/"});
}
@Test
public void testRPNResult(){
double result = RPNCalculator.calc({1.5, 2, +, 3, 4, -, *});
assertEquals(-3.5, result);
}
public static junit.framework.Test suite(){
return new junit.framework.JUnit4TestAdapter(JUnitTest.class);
}
public static void main(String args[]) {
org.junit.runner.JUnitCore.main("calccheck.JUnitTest");
}
}
Revise this Paste