复利计算--单元测试

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了复利计算--单元测试相关的知识,希望对你有一定的参考价值。

场景分析,期待的返回值以及运行结果如下表:

注释:预期结果0.0,表示输入数据有误。即得不到正确的结果

测试模块 测试输入 预期结果 运行结果 BUG跟踪
复利计算 (100,10,0.03) 134.39  正确  
单利计算 (100,10,0.03) 130.0 正确  
计算前期投入本金 (100,10,0.03) 76.92 正确  
计算多少年后翻倍 (100,200,0.03) 23.44 正确  
计算利率 (100,200,10) 0.073  正确  
按年定投 (100,10,0.03) 1180.77 正确  
按月定投 (100,10,0.03) 14169.35 正确  
每月还的本息 (100,10,0.03) 1.11 正确  
         

 

 

 

 

 

 

 

 

 

package unit;

import static org.junit.Assert.*;

import org.junit.Assert;
import org.junit.Test;

import bin.compounding;



public class test {

    @SuppressWarnings("deprecation")
    @Test
    
    public void test() {
        double value1=compounding.test_one(100, 10, 0.03);
        assertEquals(134.39, value1, 0.1);
        
        double value2=compounding.test_two(100, 10, 0.03);
        assertEquals(130.0, value2, 0.1);    
        
        double value3=compounding.test_three(100, 10, 0.03);
        assertEquals(76.92, value3, 0.1);    
        
        double value4=compounding.test_four(100, 200, 0.03);
        assertEquals(23.44, value4, 0.1);    
        
        double value5=compounding.test_five(100, 200, 10);
        assertEquals(0.071, value5, 0.1);
        
        double value6_1=compounding.test_six1(100, 10, 0.03);
        assertEquals(1180.77, value6_1, 0.1);
        
        double value6_2=compounding.test_six2(100, 10, 0.03);
        assertEquals(14169.35, value6_2, 0.1);
        
        double value7=compounding.test_seven(100, 10, 0.03);
        assertEquals(1.11, value7, 0.1);
    }
    
    
    
}
    public static double test_one(double a,int b,double c) {
        double sum=a*Math.pow(1+c, b);
        return sum;
    }
    public static double test_two(double a,int b,double c) {
        double sum=a*c*b;
        return sum+a;
    }
    public static double test_three(double a,int b,double c) {
        double single=a/(1+b*c);
        return single;
    }
    public static double test_four(double a,double b,double c) {
        double years=Math.log(b/a)/Math.log(1+c);
        return years;
    }
    public static double test_five(double a,double b,int c) {
        double r=Math.pow((b/a), 1/c)-1;
        return r;
    }
    public static double test_six1(double a,int b,double c) {
        double sum=a*(1+c)*(-1+Math.pow(1+c, b))/c;
        return sum;
    }
    public static double test_six2(double a,int b,double c) {
        double sum=a*12*(1+c)*(-1+Math.pow(1+c, b))/c;
        return sum;
    }
    public static double test_seven(double a,int b,double c) {
        double sum=a*Math.pow(1+c, b);
        double monthMoney=sum/b/12;
        return monthMoney;
    }

技术分享

以上是关于复利计算--单元测试的主要内容,如果未能解决你的问题,请参考以下文章

03-29复利计算单元测试

复利计算器单元测试

复利计算单元测试

复利计算单元测试

单元测试:复利计算

0330复利计算4.0单元测试