Question: My average method runs succesfully for each test except the last, unsure why tests public void testAverage() { assertEquals(4.5/8,sheet.average(0, 0, 6, 6), 0.01); assertEquals(2.6/6,sheet.average(0, 0,

My average method runs succesfully for each test except the last, unsure why

tests

public void testAverage() {

assertEquals(4.5/8,sheet.average(0, 0, 6, 6), 0.01);

assertEquals(2.6/6,sheet.average(0, 0, 5, 6), 0.01); //without the 0 and 1.9

assertEquals(4.6/7,sheet.average(0, 0, 6, 4), 0.01); //without the -0.1

assertEquals(-4.7/2,sheet.average(0, 3, 5, 3), 0.01); //4th column only

assertEquals(0.4/2,sheet.average(4, 1, 4, 10), 0.01); //5th row only

assertEquals(0,sheet.average(3, 0, 3, 10), 0.01); //4th row only - nothing there

method

public double average(int row1, int column1, int row2, int column2) {

double sum = 0;

int count = 0;

for(DataEntry de : data)

{

if(de.inRange(row1, column1, row2, column2))

{

sum += de.getValue();

count ++;

}

}

return sum / count;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!