Commit 4c489400 authored by michael lundquist's avatar michael lundquist
Browse files

Adding tests for offer

parent 3d27f6c3
......@@ -100,11 +100,15 @@ public class ArrayQueue {
*/
//TODO write this
public boolean offer(Object e){
if(manyItems >= data.length){
if(e == null){
throw new NullPointerException("ArrayQueue doesn't support nulls");
}
if(size() >= getCapacity()){
return false;
}else{
this.add(e);
return true;
}
this.add(e);
return true;
}
}
\ No newline at end of file
......@@ -8,21 +8,7 @@ import javax.swing.JOptionPane;
/**
* Unit test for simple App.
*/
public class AppTest
{
public static void main(String[] args){
int test = 4;
Stack s = new Stack();
for(int k = 1; k<=10; k++){
if(k == test){
s.push("b");
}else{
s.push("a");
}
}
JOptionPane.showMessageDialog(null, "the value of test is: " + test);
System.out.println("the search value is: " + s.search("b"));
}
public class AppTest {
/**
* Tests the stack peek function
......@@ -147,7 +133,6 @@ public class AppTest
for(int k = 1; k<=10; k++){
q.add("a");
}
assertTrue(q.remove().equals("b"));
}
......@@ -156,7 +141,17 @@ public class AppTest
*/
@Test
public void testArrayQueueOffer(){
assertTrue(true);
ArrayQueue q = new ArrayQueue();
int i = 0;
while(i<12){
i ++;
if(q.offer("x") == false){
assertTrue(true);
return;
}
}
JOptionPane.showMessageDialog(null, "here. i is " + i);
assertTrue(false);
}
/**
......@@ -167,12 +162,20 @@ public class AppTest
assertTrue(true);
}
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
*
* @param max
* @param min
* @return
* @param max the smallest possible number to get
* @param min The largest possible number you can get
* @return a random number
*/
public static Integer randRange(int max, int min){
return min + (int)(Math.random() * ((max - min) + 1));
......
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