Commit 797edb9b authored by michael lundquist's avatar michael lundquist
Browse files

Adding a stest for the last search method.

parent 946daa09
...@@ -37,13 +37,13 @@ public class ArrayStack { ...@@ -37,13 +37,13 @@ public class ArrayStack {
*/ */
//TODO //TODO
public int search(Object o){ public int search(Object o){
int distance = 1;
//search for the element and increment distance //search for the element and increment distance
for(Object cmp: this.data){ Object cmp;
for(int distance = manyItems - 1, counter = 1; distance > 0; distance --, counter ++){
cmp = this.data[distance];
if(cmp.equals(o)){ if(cmp.equals(o)){
return distance; return counter;
} }
distance ++;
} }
return -1; return -1;
} }
......
...@@ -119,8 +119,9 @@ public class AppTest ...@@ -119,8 +119,9 @@ public class AppTest
} }
} }
JOptionPane.showMessageDialog(null, "the value of test is: " + (11 - test) ); JOptionPane.showMessageDialog(null, "the value of test is: " + (11 - test) );
JOptionPane.showMessageDialog(null, "The search result: " + s.search("b")); int ser = s.search("b");
assertTrue(s.search("b") == (11 - test)); JOptionPane.showMessageDialog(null, "The search result: " + ser);
assertTrue(ser == (11 - test));
//assertTrue(false); //assertTrue(false);
} }
......
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