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 { ...@@ -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 * validates the brackets of a mathematical expression
......
...@@ -38,7 +38,7 @@ public class Queue { ...@@ -38,7 +38,7 @@ public class Queue {
*/ */
//TODO make sure this works //TODO make sure this works
public Object element() throws NoSuchElementException{ public Object element() throws NoSuchElementException{
return head; return head.getData();
} }
......
package com.ds.fifthassignment; package com.ds.fifthassignment;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import org.junit.Test; import org.junit.Test;
...@@ -7,11 +8,15 @@ import javax.swing.JOptionPane; ...@@ -7,11 +8,15 @@ import javax.swing.JOptionPane;
/** /**
* Unit test for simple App. * Unit test for simple App.
*
* @author Michael Lundquist
*/ */
public class AppTest { public class AppTest {
/** /**
* Tests the stack peek function * Tests the stack peek function
*
* @author Michael Lundquist
*/ */
@Test @Test
public void testStackPeek(){ public void testStackPeek(){
...@@ -29,6 +34,8 @@ public class AppTest { ...@@ -29,6 +34,8 @@ public class AppTest {
/** /**
* Tests the stack peek function * Tests the stack peek function
*
* @author Michael Lundquist
*/ */
@Test @Test
public void test_LL_StackPeek(){ public void test_LL_StackPeek(){
...@@ -44,6 +51,8 @@ public class AppTest { ...@@ -44,6 +51,8 @@ public class AppTest {
/** /**
* Tests the stack peek function * Tests the stack peek function
*
* @author Michael Lundquist
*/ */
@Test @Test
public void testStackSearch(){ public void testStackSearch(){
...@@ -66,6 +75,8 @@ public class AppTest { ...@@ -66,6 +75,8 @@ public class AppTest {
/** /**
* Tests the stack peek function * Tests the stack peek function
*
* @author Michael Lundquist
*/ */
@Test @Test
public void test_LL_StackSearch(){ public void test_LL_StackSearch(){
...@@ -87,6 +98,7 @@ public class AppTest { ...@@ -87,6 +98,7 @@ public class AppTest {
/** /**
* Tests the stack peek function * Tests the stack peek function
* @author Michael Lundquist
*/ */
@Test @Test
public void testArrayStackSearch(){ public void testArrayStackSearch(){
...@@ -109,35 +121,45 @@ public class AppTest { ...@@ -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 @Test
public void testQueueElement(){ public void testQueueElement(){
Integer test = randRange(1,10); Integer test = randRange(5,10);
ArrayStack s = new ArrayStack(); Queue q = new Queue();
for(int k = 1; k<=10; k++){ q.add("b");
s.push("a"); for(int k = 1; k<=test; k++){
q.add("a");
} }
s.push("b"); assertTrue(q.element().equals("b"));
assertTrue(true);
} }
/** /**
* Tests the stack peek function * Tests LinkedListQueue.element to make sure it returns the correct thing
*
* @author Michael Lundquist
* @see LinkedListQueue#element()
*/ */
@Test @Test
public void test_LL_QueueElement(){ public void test_LL_QueueElement(){
Integer test = randRange(1,10); Integer test = randRange(5,10);
LinkedListQueue q = new LinkedListQueue(); LinkedListQueue q = new LinkedListQueue();
q.add("b"); q.add("b");
for(int k = 1; k<=10; k++){ for(int k = 1; k<=test; k++){
q.add("a"); 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 @Test
public void testArrayQueueOffer(){ public void testArrayQueueOffer(){
...@@ -155,20 +177,17 @@ public class AppTest { ...@@ -155,20 +177,17 @@ public class AppTest {
} }
/** /**
* Tests the stack peek function * Tests Application.isValid
*
* @see Application#isValid(char[])
* @author Michael Lundquist
*/ */
@Test @Test
public void testIsValid(){ 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 * 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