Click here to Skip to main content
15,879,474 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:
Posted
Updated 18-Feb-17 21:34pm

1 solution

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!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900