需要找出一些测试用例来实现这个程序 [英] Need to findout number of test cases to acheive this program

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

问题描述

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



期限费率

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,结果:

解决方案

重要的一点是:实现 100%代码覆盖率所需的测试用例数是。

这意味着你需要提供一个测试用例意味着每个可能的代码路径都被执行。所以每个if有两个案例 - 一个通过测试,一个失败。

你还没有那样做 - 我至少可以看到一个你没有覆盖的案例......例外。

检查你的代码,确保你的测试涵盖了每个条件。



我不打算为你做这个,因为它是你的作业!

A bank offers the following mortgage rates:

Term Rate
10 years 3.00%
30 years 4.50%
With the following modifiers based on a customer's credit score:

Credit Score Rate Modifier
300 to 699 2.00%
700 to 799 0.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:

解决方案

The important bit is: "The number of test cases needed to achieve 100% code coverage is".
That means you need to provide a test case that means that every possible code path is executed. So two cases for each if - one which passes the test, and one which fails.
You don't do that yet - I can see at least one case you do not cover ... the exception.
Check your code, make sure your tests cover each condition.

I'm not going to do this for you as it's your homework!


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆