I'm trying to write the Junit test code for the following code:
public class RateofPay {
public double totalSalary(double work, double work2, double hour1, double hour2, double hour3) {
double salary1 = work * hour1;
double salary2 = work2 * hour2;
double salary3 = work * hour3;
double wages = salary1 + salary2 + salary3;
return wages;
}
}
And this is the JUnit test I have wrote:
public class WageTest {
@Test
public void testWage() {
RateofPay test=new RateofPay();
double result=test.totalSalary(1.0, 2.0, 3.0, 4.0, 5.0);
assertEquals(12.0, result);
}
@Test
public void testWage1() {
RateofPay test=new RateofPay();
double result=test.totalSalary(6.0, 7.0, 8.0, 9.0, 10.0);
assertEquals(157.0, result);
}
}
The problem is that every time when I run the JUnit test, none of them pass the test. The result says
assertEquals(expected, actual, delta) to compare floating point number.
I'm wondering what is wrong? Thanks.