My contains
method works properly for smaller indices but then for big indices such as the test cases 1000, 2000, 2999 it does not work. I do not see why. I checked the output for the print statement in the loop which shows that the numbers I am checking for are present in the object array.
Assume the objects in array and element are int. data is Object []
public boolean contains(E element) {
boolean flag = false;
if (this.size() == 0) { return flag;}
for (int i = 0; i < this.data.length; i++) {
if (element == this.data[i]) { flag = true; }
System.out.println(this.data[i]);
}
return flag;
}
@Test
public void mustGrowArray() {
OurSet<Integer> ints = new ArraySet<Integer>();
for (int i = 0; i < 3000; i++) {
ints.add(i);
}
assertEquals(3000, ints.size());//passes
assertTrue(ints.contains(1000));// fails
assertTrue(ints.contains(2000));// fails
assertTrue(ints.contains(2999));// fails
}