??????????????????
???????????? ???????[ 2016/4/21 16:16:13 ] ??????????????? ???????
???????????
??????λ??? ???????????????????????????????????????????????????????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();
????}
??????β??? :
????????????β???????????????????????????? ?????? ???????????????δ???????...
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11