???????????
??????λ??? ???????????????????????????????????????????????????????Calculation???У? ????????е?????? ???????? ???????????????????????? ?????????Calculation???е????·??????в???:
????compoundYear() //???????????
????simpleMoney() //??????
?????????????junit???в???? ???????junit???hamcrest??jar??
????????
?????????compoundYear()???в???? ??????????????????? :
compoundYear() :
public static int compoundYear(double compoundMoney?? double compoundRate?? double compoundSum) {
return (int)((Math.log(compoundSum)/Math.log(1+compoundRate))-(Math.log(compoundMoney)/Math.log(1+compoundRate)));
}
testCompoundYear() :
@Test
public void testCompoundYear() {
int compoundYear = Calculation.compoundYear(1000000?? 0.1?? 2000000);
assertThat(compoundYear?? is(7));
}
????????????? ?????????????7?? ????assertThat()?????????ж?? ?????????? :

??????Σ? ??simpleMoney()???в???? ??????????????????? :
simpleMoney() :
public static double simpleMoney(double simpleSum?? int simpleYear?? double simpleRate) {
return simpleSum/(1 + simpleYear * simpleRate);
}
testSimpleMoney() :
@Test(expected=java.lang.ArithmeticException.class)
public void testSimpleMoney() {
Calculation.simpleMoney(100000?? 1?? -1);
}
?????????????????????????????????? ???annotation?е?expected????? ???????ArithmeticException?? ??????????? :

??????????ó????????? ???????????! ???鵽????????????? ????????????double????? ??????????? (double)0 ??????????????????????? ?????????????????????????????? ?????????????Exception
?????????Grey?????????? ???BigDecimal??(??????????????????api???)?? ????????д???? ????????е?divide()?????? ??????????????????????????????????????????????????? ArithmeticException
???????????simpleMoney()????????:
????public static double simpleMoney(double simpleSum?? int simpleYear?? double simpleRate) {
????BigDecimal BSimpleSum = new BigDecimal(simpleSum);
????BigDecimal BSimpleYR = new BigDecimal(1 + simpleYear * simpleRate);
????return BSimpleSum.divide(BSimpleYR).doubleValue();
????}
??????β??? :

????????????β???????????????????????????? ?????? ???????????????δ???????...