Commit 946daa09 authored by michael lundquist's avatar michael lundquist
Browse files

Spiffing up these methods and adding tests for them

parent e0b21e2c
......@@ -69,7 +69,7 @@ public class LinkedListStack implements Iterable{
public int search(Object o){
int distance = 0;
//search for the element and increment distance
Iterator it = this.iterator();
Iterator<Object> it = this.data.descendingIterator();
Object testObject = null;
while(it.hasNext()){
distance ++;
......
......@@ -69,7 +69,8 @@ public class Stack {
//search for the element and increment distance
Node test = this.top;
while(test != null){
if(test.data.equals(o)){
boolean result = test.data.equals(o);
if(result){
return distance;
}
distance ++;
......
......@@ -3,18 +3,167 @@ package com.ds.fifthassignment;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
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"));
}
/**
* Tests the stack peek function
*/
@Test
public void testStackPeek(){
Integer test = randRange(0,100);
Integer randomStop = randRange(5, 10);
Stack s = new Stack();
for(int k = 0; k<randomStop; k++){
test = new Integer(randRange(0,100));
s.push(test);
}
assertTrue(s.peek().equals(test));
}
/**
* Tests the stack peek function
*/
@Test
public void test_LL_StackPeek(){
Integer test = randRange(0,100);
Integer randomStop = randRange(5, 10);
LinkedListStack s = new LinkedListStack();
for(int k = 0; k<randomStop; k++){
test = new Integer(randRange(0,100));
s.push(test);
}
assertTrue(s.peek().equals(test));
}
/**
* Tests the stack peek function
*/
@Test
public void testStackSearch(){
//Integer test = randRange(1,10);
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: " + (11 - test) );
//JOptionPane.showMessageDialog(null, "The search result: " + s.search("b"));
assertTrue(s.search("b") == (11 - test));
//assertTrue(false);
}
/**
* Rigorous Test :-)
* Tests the stack peek function
*/
@Test
public void shouldAnswerWithTrue()
{
assertTrue( true );
public void test_LL_StackSearch(){
//Integer test = randRange(1,10);
int test = 4;
JOptionPane.showMessageDialog(null, "hi" );
LinkedListStack s = new LinkedListStack();
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: " + (11 - test) );
JOptionPane.showMessageDialog(null, "The search result: " + s.search("b"));
assertTrue(s.search("b") == (11 - test));
//assertTrue(false);
}
/**
* Tests the stack peek function
*/
@Test
public void testArrayStackSearch(){
//Integer test = randRange(1,10);
int test = 4;
JOptionPane.showMessageDialog(null, "hi" );
ArrayStack s = new ArrayStack();
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: " + (11 - test) );
JOptionPane.showMessageDialog(null, "The search result: " + s.search("b"));
assertTrue(s.search("b") == (11 - test));
//assertTrue(false);
}
/**
* Tests the stack peek function
*/
@Test
public void testQueueElement(){
assertTrue(true);
}
/**
* Tests the stack peek function
*/
@Test
public void test_LL_QueueElement(){
assertTrue(true);
}
/**
* Tests the stack peek function
*/
@Test
public void testArrayQueueOffer(){
assertTrue(true);
}
/**
* Tests the stack peek function
*/
@Test
public void testIsValid(){
assertTrue(true);
}
/**
* gets a random number between max and min
*
* @param max
* @param min
* @return
*/
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