一。测试场景
测试模块 | 测试输入 | 预期结果 | 运行结果 | bug跟踪 |
复利计算 | (本金,利率,年限,次数) | 终值 | ||
测试运算结果 | (100,5,3,1) | 115.76 | ||
测试输入负数 | (-100,5,3,1) | False | ||
测试输入0 | (0,5,3,1) | |||
单利计算 | (本金,利率,年限) | |||
(1000,2,5) | 1100 | |||
(-1000,2,5) | ||||
(0,2,5) | ||||
本金估算 | (终值,利率,年限,次数) | 本金 | ||
(1000,2,5,1) | 905.73 | |||
(-1000,2,5,1) | ||||
(0,2,5,1) | ||||
年限估算 | (本金,利率,次数,终值) | 年限 | ||
(1000,2,1,2000) | 35 | |||
(-1000,-2,1,2000) | ||||
(0,2,1,2000) | ||||
利率估算 | (本金,年限,次数,终值) | 利率 | ||
(1000,5,1,2000) | 14.86 | |||
(-1000,-5,1,2000) | ||||
(0,0,1,2000) | ||||
按年投资 | (年投资额,利率,定投年数) | |||
5308.12 | ||||
按月投资 | (月投资额,利率,定投月数) | |||
(1000,2,6) | 6035.09 | |||
(-1000,2,6) | ||||
(0,2,6) | ||||
等额本息还款 | (贷款金额,利率,年限,次数) | |||
(10000,2,5,2) | 175.16 | |||
(-10000,2,5,2) | ||||
(0,2,5,2) |
二。测试代码
1 import static org.junit.Assert.*;
2
3 import org.junit.Assert;
4 import org.junit.Before;
5 import org.junit.Test;
6
7
8 public class test {
9 @Before
10 public void setUp() throws Exception {
11 }
12 @org.junit.Test
13 public void testCompound() {
14 CompoundCalculator Compound = new CompoundCalculator();
15 double F = Compound.Compound(100,5,3,1);
16 Assert.assertEquals(F, 115.76, 1.0);
17 // assertTrue(F>0);
18 double f =Compound.Compound(-100,5,3,1);
19 assertFalse(f>0);
20 double a=Compound.Compound(0,5,3,1);
21 assertFalse(a>0);
22 }
23 @org.junit.Test
24 public void testSimple() {
25 CompoundCalculator Simple = new CompoundCalculator();
26 double F = Simple.Simple(1000,2,5);
27 Assert.assertEquals(F, 1100, 0.0);
28 // assertTrue(F>0);
29 double f =Simple.Simple(-1000,2,5);
30 assertFalse(f>0);
31 double a=Simple.Simple(0,2,5);
32 assertFalse(a>0);
33 }
34 @org.junit.Test
35 public void testPrinciple() {
36 CompoundCalculator Principle = new CompoundCalculator();
37 double F = Principle.Principle(1000,2,5,1);
38 Assert.assertEquals(F, 905.73, 1.0);
39 // assertTrue(F>0);
40 double f =Principle.Principle(-1000,2,5,1);
41 assertFalse(f>0);
42 double a=Principle.Principle(0,2,5,1);
43 assertFalse(a>0);
44 }
45 @org.junit.Test
46 public void testYear() {
47 CompoundCalculator Year = new CompoundCalculator();
48 double F = Year.Year(1000,2,1,2000);
49 Assert.assertEquals(F, 35, 0.0);
50 // assertTrue(F>0);
51 double f =Year.Year(-1000,-2,1,2000);
52 assertFalse(f>0);
53 double a=Year.Year(0,2,1,2000);
54 assertFalse(a<0);
55 }
56 @org.junit.Test
57 public void testRate() {
58 CompoundCalculator Rate = new CompoundCalculator();
59 double F = Rate.Rate(1000,5,1,2000);
60 Assert.assertEquals(F, 14.86, 1.0);
61 // assertTrue(F>0);
62 double f =Rate.Rate(-1000,-5,1,2000);
63 assertFalse(f>0);
64 double a=Rate.Rate(0,0,1,2000);
65 assertFalse(a<0);
66 }
67 @org.junit.Test
68 public void testYearinvest() {
69 CompoundCalculator Yearinvest = new CompoundCalculator();
70 double F = Yearinvest.Yearinvest(1000,2,5);
71 Assert.assertEquals(F, 5308.12, 1.0);
72 // assertTrue(F>0);
73 double f =Yearinvest.Yearinvest(-1000,2,5);
74 assertFalse(f>0);
75 double a=Yearinvest.Yearinvest(0,2,5);
76 assertFalse(a>0);
77 }
78 @org.junit.Test
79 public void testMonthinvest() {
80 CompoundCalculator Monthinvest = new CompoundCalculator();
81 double F = Monthinvest.Monthinvest(1000,2,6);
82 Assert.assertEquals(F, 6035.09, 1.0);
83 // assertTrue(F>0);
84 double f =Monthinvest.Monthinvest(-1000,2,6);
85 assertFalse(f>0);
86 double a=Monthinvest.Monthinvest(0,2,6);
87 assertFalse(a>0);
88 }
89 @org.junit.Test
90 public void testRepayment() {
91 CompoundCalculator Repayment = new CompoundCalculator();
92 double F = Repayment.Repayment(10000,2,5,2);
93 Assert.assertEquals(F, 175.16, 1.0);
94 // assertTrue(F>0);
95 double f =Repayment.Repayment(-10000,2,5,2);
96 assertFalse(f>0);
97 double a=Repayment.Repayment(0,2,5,2);
98 assertFalse(a>0);
99 }
100
101 }
三。测试结果
