复利计算器Junit单元测试

一。测试场景

测试模块测试输入预期结果运行结果bug跟踪
复利计算

(本金,利率,年限,次数)

终值

  

测试运算结果

(100,5,3,1)115.76115.76 
测试输入负数(-100,5,3,1)FalseFalse 
测试输入0(0,5,3,1)FalseFalse 
单利计算(本金,利率,年限)

终值

  

测试运算结果

(1000,2,5)11001100 
测试输入负数(-1000,2,5)FalseFalse 
测试输入0(0,2,5)FalseFalse 
本金估算(终值,利率,年限,次数)本金  

测试运算结果

(1000,2,5,1)905.73905.73 
测试输入负数(-1000,2,5,1)FalseFalse 
测试输入0(0,2,5,1)FalseFalse 
年限估算(本金,利率,次数,终值)年限  

测试运算结果

(1000,2,1,2000)3535 
测试输入负数(-1000,-2,1,2000)FalseFalse 
测试输入0(0,2,1,2000)FalseFalse 
利率估算(本金,年限,次数,终值)利率  

测试运算结果

(1000,5,1,2000)14.8614.86 
测试输入负数(-1000,-5,1,2000)FalseFalse 
测试输入0(0,0,1,2000)FalseFalse 
按年投资(年投资额,利率,定投年数)   

测试运算结果

(1000,2,5)5308.125308.12 
测试输入负数(-1000,2,5)FalseFalse 
测试输入0(0,2,5)FalseFalse 
按月投资(月投资额,利率,定投月数)   

测试运算结果

(1000,2,6)6035.096035.09 
测试输入负数(-1000,2,6)FalseFalse 
测试输入0(0,2,6)FalseFalse 
等额本息还款(贷款金额,利率,年限,次数)   

测试运算结果

(10000,2,5,2)175.16175.16 
测试输入负数(-10000,2,5,2)FalseFalse 
测试输入0(0,2,5,2)FalseFalse 

 

二。测试代码

  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 }

三。测试结果

转载于:https://www.cnblogs.com/alfredzhu/p/5336245.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值