I am trying to clear an array however it does not satisfy all the test conditions...
the code that i wrote to clear this array is:
public void clear()
{
for(int i = 0; i < itemArray.length; i ++)
{
itemArray[i] = null;
numberOfItems = -1;
//TODO check why the clear a filled array is not working?
}
}
the test code is:
public double testClear(double markpool) {
int noTest = 4;
double gain = markpool/noTest;
double mark = 0;
//clear an empty array
//clear a filled array
//clear then readd
//clear a sorted array, test if still sort
//clear a non sorted array;
header("Testing clear");
try {
ResizableArray test1 = new ResizableArray (false, 20);
print ("*** Test 1: clear an emtpy array");
test1.clear();
if (test1.numberOfItems() == 0) {
mark += gain;
print ("*** Passed: clear empty array");
printM (gain,mark);
}
print ("");
print ("*** Test 2: clear a filled array");
for (int i = 0; i < items.length; i++ ) {
test1.addItem(items[i]);
}
test1.clear();
if (test1.numberOfItems() == 0) {
mark += gain;
print ("*** Passed: clear filled array");
}
//re add:
for (int i = 0; i < items.length; i++ ){
test1.addItem (items[i]);
}
if (test1.numberOfItems() == items.length) {
mark += gain;
print ("*** Passed: re-add okay after clear");
printM (gain, mark);
}
print ("");
print ("** Test 3: Clear sorted and non sorted arrays");
ResizableArray test2 = new ResizableArray (false, 20);
ResizableArray test3 = new ResizableArray (true, 20);
for (int i = 0 ; i < items.length; i ++ ) {
test2.addItem(items[i]);
test3.addItem(items[i]);
}
test2.clear();
test3.clear ();
if (!test2.isSorted() && test3.isSorted()) {
mark += gain;
print ("*** Passed: clear() doesn't change sorted variable");
printM (gain, mark);
}
}
catch (Exception e) {
print ("*** Unknown exception");
e.printStackTrace();
return 0;
}
print80stars();
return mark;
}
the output i get is:
********************************************************************************
Testing clear
********************************************************************************
*** Test 1: clear an emtpy array
*** Passed: clear empty array
**** Gain: 2.50 . Mark: 2.50
*** Test 2: clear a filled array
*** Unknown exception
Am i missing something?

New Topic/Question
Reply




MultiQuote






|