對我們和複利計算程式,寫單元測試。
有哪些場景?
期待的傳回值
寫測試程式。
運作測試。
測試計算是否正确:

@Test
public void test0() {//測單利終值
double money=1000000.0;
int years=30;
double r=0.03;
double sum;
sum = money + money * years * r;
Assert.assertEquals(1900000,sum, 1.0);
}
@Test
public void test1(){//測複利終值
double money=1000000.0;
int years=30;
double r=0.03;
double N=1;
double sum;
for (int i = 1; i <= years; i++) {
N = (1 + r) * N;
}
sum = N * money;
Assert.assertEquals(2427262,sum, 1.0);
}
@Test
public void test2(){//測本金
double N = 1, money;
double sum=3000000;
int years=30;
double r=0.03;
for (int i = 1; i <= years; i++) {
N = (1 + r) * N;
}
money = sum / N;
Assert.assertEquals(1235960,money, 1.0);
}

不清楚究竟怎樣做,都是跟着同學的教導做的,不太明白

@Test
public void test0() {//測單利終值
double money=1000000.0;
int years=30;
double r=0.03;
double sum;
sum = money + money * years * r;
Assert.assertEquals(1900000,sum, 1.0);
}
@Test
public void test1(){//測複利終值
double money=1000000.0;
int years=30;
double r=0.03;
double N=1;
double sum;
for (int i = 1; i <= years; i++) {
N = (1 + r) * N;
}
sum = N * money;
Assert.assertEquals(2427262,sum, 1.0);
}
@Test
public void test2(){//測本金
double N = 1, money;
double sum=3000000;
int years=30;
double r=0.03;
for (int i = 1; i <= years; i++) {
N = (1 + r) * N;
}
money = sum / N;
Assert.assertEquals(1235960,money, 1.0);
}
