03-29复利计算单元测试
生活随笔
收集整理的這篇文章主要介紹了
03-29复利计算单元测试
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
說明:之前用C語言寫代碼,現用java寫代碼。
?
場景分析,期待的返回值以及運行結果如下表:
注釋:預期結果0.0,表示輸入數據有誤。即得不到正確的結果
| 測試模塊 ? | 測試輸入 ? | 預期結果 ? | 運行結果 ? | bug跟蹤 ? |
| ? ? 單利計算 獲得利息 | “100”,”2”,”1” | 102.0 | 正確 | ? |
| “0”,”2”,”1” | 0.0 | 正確 | ? | |
| “0”,”dsaf”,”1” | 0.0 | 正確 | ? | |
| “0”,”-100”,”1” | 0.0 | 正確 | ? | |
| ? ? ? 單利計算 獲得利息 | “100”,”2”,”1” | 102.01 | 正確 | ? |
| “0”,”dsaf”,”1” | 0.0 | 正確 | ? | |
| “0”,”2”,”1” | 0.0 | 正確 | ? | |
| “0”,”-100”,”1” | 0.0 | 正確 | ? | |
| ? ? ? 計算本金(按復利) | “106”,”2”,”1” | 103.91 | 正確 | ? |
| “0”,”dsaf”,”1” | 0.0 | 正確 | ? | |
| “0”,”2”,”1” | 0.0 | 正確 | ? | |
| “0”,”-100”,”1” | 0.0 | 正確 | ? |
其他計算功能測試與上述相似。
運行測試結果如下(部分):
?
?
?
測試程序代碼如下(部分):
//用于測試單利計算獲得利息public void testSimpleInteres() {SimpleInteres s = new SimpleInteres();Assert.assertEquals(102.0, s.getResult("100", "1", "2"),0.1);Assert.assertEquals(0.0, s.getResult("0", "1", "2"),0.1);Assert.assertEquals(0.0, s.getResult("asdf", "1", "2"),0.1);Assert.assertEquals(0.0, s.getResult("100", "-1", "2"),0.1);}//用于測試復利計算獲得利息public void testCompoundInterest() {CompoundInterest s = new CompoundInterest();Assert.assertEquals(102.01, s.getResult("100", "1", "2"),0.1);Assert.assertEquals(0.0, s.getResult("0", "1", "2"),0.1);Assert.assertEquals(0.0, s.getResult("asdf", "1", "2"),0.1);Assert.assertEquals(0.0, s.getResult("100", "-1", "2"),0.1);}//用于測試計算本金(按復利)public void testGetPrincipal() {GetPrincipal s = new GetPrincipal();Assert.assertEquals(103.91, s.getResult("106", "1", "2"),0.1);Assert.assertEquals(0.0, s.getResult("0", "1", "2"),0.1);Assert.assertEquals(0.0, s.getResult("asdf", "1", "2"),0.1);Assert.assertEquals(0.0, s.getResult("100", "-1", "2"),0.1);}?
轉載于:https://www.cnblogs.com/yanwensheng/p/5335158.html
總結
以上是生活随笔為你收集整理的03-29复利计算单元测试的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CTO 比普通程序员强在哪?
- 下一篇: 读《世界是数字的》有感