本文介绍了需要找出一些测试用例来实现这个程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

银行提供以下抵押贷款利率:



期限费率

10年3.00%

30年4.50%

根据客户的信用评分使用以下修饰符:



信用评分率修改器

300至699 2.00%

700至799 0.00%

800至850 -0.50%

抵押贷款的实际汇率使用两者计算术语和信用评分。例如,如果一个人需要10年期抵押贷款并且信用评分为550,则该比率为:3%+ 2%= 5%。如果另一个人需要相同的抵押贷款,但信用评分为810,则费率为3% - 0.50%= 2.50%。







浮动计算(int term,int score)



{



浮动利率= 0;



if(term == 10)



rate = 0.03f ;



否则if(term == 30)



rate = 0.045f;



if(得分> = 800)



退货率 - 0.005f;



否则if(得分> = 700)



退货率;



else if(得分> = 300)



退货率+ 0.02f;



扔new ArgumentOutOfRangeException();



}



实现100%代码覆盖率所需的测试用例数是



我尝试过:



我评分:10,得分:300,结果:

0.05



率:10,得分:700,结果:

0.03



评分:10,得分:850,结果:

0.025



评分:30,得分:300,结果:

0.065



率:30,得分:700,结果:

0.045



汇率:30,得分:850,结果:

解决方案

A bank offers the following mortgage rates:

TermRate
10 years3.00%
30 years4.50%
With the following modifiers based on a customer's credit score:

Credit ScoreRate Modifier
300 to 6992.00%
700 to 7990.00%
800 to 850-0.50%
The actual rate for a mortgage is calculated using both the term and the credit score. For example if a person needs a 10 year mortgage and has a credit score of 550 the rate would be: 3% + 2% = 5%. If another person needs the same mortgage but has a credit score of 810, the rate would be 3% - 0.50% = 2.50%.



float calculaterate(int term, int score)

{

float rate = 0;

if (term == 10)

rate = 0.03f;

else if (term == 30)

rate = 0.045f;

if (score >= 800)

return rate - 0.005f;

else if (score >= 700)

return rate;

else if (score >= 300)

return rate + 0.02f;

throw new ArgumentOutOfRangeException();

}

The number of test cases needed to achieve 100% code coverage is

What I have tried:

I rate: 10, score: 300, result:
0.05

rate: 10, score: 700, result:
0.03

rate: 10, score: 850, result:
0.025

rate: 30, score: 300, result:
0.065

rate: 30, score: 700, result:
0.045

rate: 30, score: 850, result:

解决方案


这篇关于需要找出一些测试用例来实现这个程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 12:48