zoukankan      html  css  js  c++  java
  • 单元测试代码0330

    package compounding;
    
    import static org.junit.Assert.*;
    import junit.framework.Assert;
    
    import org.junit.Before;
    import org.junit.Test;
    
    public class compounding1_2Test {
    
        compounding1_1 test;
        @Before
        public void setUp() throws Exception {
            test =new compounding1_1();
        }
    
        @Test
        public void testPrincipal() {
            //fail("尚未实现");
            double q=0.03;
            double P;
            int year=3,n=2;
            double F=20000;
            P = F / Math.pow((1 + q / n), year * n);
            //Assert.assertEquals(18290.843850357436, 18290.843850357436,0.0);
            assertEquals(18290.88, 18290.843850357436,0.02);
        }
    
        @Test
        public void testYear_end_value() {
            //fail("尚未实现");
            double q=0.03;
            double P=10000;
            int year=10,n=2;
            double F;
            F=P * Math.pow((1 + q / n), year * n);
            assertEquals(13468,13468.6,1.0);
            
            
        }
    
        @Test
        public void testDanli() {
    //        fail("尚未实现");
             int year=10;
                double q=0.03, F, P=10000;
                F = P + P * year * q;
                Assert.assertEquals(13468,13468.6,1.0 );
        }
    
        @Test
        public void testYears() {
    //        fail("尚未实现");
            int year, n=2;
            double q=0.03, F=20000, P=10000;
            year = (int) (Math.log(F / P) / Math.log(1 + q /n) / n);
            assertEquals(23, 23.45,1.0);
        }
    
        @Test
        public void testAPY() {
    //        fail("尚未实现");
            int year=3, n=2;
            double q, F=20000, P=10000;
            q = n * (Math.pow(F / P, 1.0 / (year * n)) - 1);
            assertEquals(0.26,0.24492409661874603,0.01 );
            //assertEquals(0.24492409661874603,0.24492409661874603,0.0 );
        }
    
        @Test
        public void testInvestmentyear() {
    //        fail("尚未实现");
            int year=10, n=2;
            double q=0.03, final_value, P=10000;
               
                final_value = P * (Math.pow(1 + q, year) - 1) /q;
                assertEquals(13468, 13468.60,1.0);
                
        }
    
        @Test
        public void testInvestmentmonth() {
    //        fail("尚未实现");
            int year=10, n=2;
            double q=0.03, final_value, P=10000;
            final_value = P * 12 * (1 + q) * (Math.pow(1 + q, year) - 1) / q;
            assertEquals(13468, 13468.60,1.0);
            
        }
    
        @Test
        public void testRepayment() {
    //        fail("尚未实现");
            int year=10;
            double q=0.03, F=20000, refund;
           
            refund = F * q / (12 * (1 + q) * (Math.pow(1 + q, year) - 1));
            assertEquals(1000,1000.50,1.0 );
        }
    
    }
  • 相关阅读:
    四十一.redis主从复制 RDB/AOF持久化 数据类型
    四十.创建Redis集群 管理集群
    三十九.NoSQL概述 部署Redis服务 、 部署LNMP+Redis
    三十八. 分库分表概述 配置mycat
    520D
    442C
    LA4788
    LA3276
    LA4122
    zoj3478
  • 原文地址:https://www.cnblogs.com/4249ken/p/5338730.html
Copyright © 2011-2022 走看看