Commit 15425bbb authored by michael lundquist's avatar michael lundquist
Browse files

Adding test code for Application.isValid and spiffing up other test code. Also fixing Queue.element

parent 4c489400
......@@ -16,13 +16,6 @@ public class Application {
}
public static void main(String[] args) {
char[] input1 = "[(4+5+1) x (4 / 2)]".toCharArray();
char[] input2 = "[(4+5+1) x (4 / 2]".toCharArray();
System.out.println(isValid(input1));
System.out.println(isValid(input2));
}
/**
* validates the brackets of a mathematical expression
......
......@@ -38,7 +38,7 @@ public class Queue {
*/
//TODO make sure this works
public Object element() throws NoSuchElementException{
return head;
return head.getData();
}
......
package com.ds.fifthassignment;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
......@@ -7,11 +8,15 @@ import javax.swing.JOptionPane;
/**
* Unit test for simple App.
*
* @author Michael Lundquist
*/
public class AppTest {
/**
* Tests the stack peek function
*
* @author Michael Lundquist
*/
@Test
public void testStackPeek(){
......@@ -29,6 +34,8 @@ public class AppTest {
/**
* Tests the stack peek function
*
* @author Michael Lundquist
*/
@Test
public void test_LL_StackPeek(){
......@@ -44,6 +51,8 @@ public class AppTest {
/**
* Tests the stack peek function
*
* @author Michael Lundquist
*/
@Test
public void testStackSearch(){
......@@ -66,6 +75,8 @@ public class AppTest {
/**
* Tests the stack peek function
*
* @author Michael Lundquist
*/
@Test
public void test_LL_StackSearch(){
......@@ -87,6 +98,7 @@ public class AppTest {
/**
* Tests the stack peek function
* @author Michael Lundquist
*/
@Test
public void testArrayStackSearch(){
......@@ -109,35 +121,45 @@ public class AppTest {
}
/**
* Tests the stack peek function
* Tests the stack peek function to make sure it returns the right thing
*
* @author Michael Lundquist
* @see ArrayStack
*/
@Test
public void testQueueElement(){
Integer test = randRange(1,10);
ArrayStack s = new ArrayStack();
for(int k = 1; k<=10; k++){
s.push("a");
Integer test = randRange(5,10);
Queue q = new Queue();
q.add("b");
for(int k = 1; k<=test; k++){
q.add("a");
}
s.push("b");
assertTrue(true);
assertTrue(q.element().equals("b"));
}
/**
* Tests the stack peek function
* Tests LinkedListQueue.element to make sure it returns the correct thing
*
* @author Michael Lundquist
* @see LinkedListQueue#element()
*/
@Test
public void test_LL_QueueElement(){
Integer test = randRange(1,10);
Integer test = randRange(5,10);
LinkedListQueue q = new LinkedListQueue();
q.add("b");
for(int k = 1; k<=10; k++){
for(int k = 1; k<=test; k++){
q.add("a");
}
assertTrue(q.remove().equals("b"));
assertTrue(q.element().equals("b"));
}
/**
* Tests the stack peek function
* Tests ArrayQueue's offer function to make sure it rejects input when
* it's out of space
*
* @author Michael Lundquist
* @see ArrayQueue#offer(Object)
*/
@Test
public void testArrayQueueOffer(){
......@@ -155,20 +177,17 @@ public class AppTest {
}
/**
* Tests the stack peek function
* Tests Application.isValid
*
* @see Application#isValid(char[])
* @author Michael Lundquist
*/
@Test
public void testIsValid(){
assertTrue(true);
assertTrue(Application.isValid("[(4+5+1) x (4 / 2)]"));
assertFalse(Application.isValid("[(4+5+1) x (4 / 2]"));
}
public static void main(String[] args) {
char[] input1 = "[(4+5+1) x (4 / 2)]".toCharArray();
char[] input2 = "[(4+5+1) x (4 / 2]".toCharArray();
System.out.println(Application.isValid(input1));
System.out.println(Application.isValid(input2));
}
/**
* gets a random number between max and min
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment