CTFL Exam QuestionsBrowse all questions from this exam

CTFL Exam - Question 7


Consider the following pseudo code

1. Begin

2. Read Gender

3. __Print "Dear"

4. If Gender = female

5. Print ("Ms")

6. Else

7. __Print ( "Mr")

8. Endif

9. End

How many test cases are needed to achieve 100 per cent decision coverage?

Show Answer
Correct Answer: B

To achieve 100 per cent decision coverage, we need to test all possible outcomes of every decision point in the code. In this pseudo code, there is one decision point (the if-else statement that checks if the gender is female). Therefore, we need two test cases: one where Gender is female (to cover the 'if' branch and print 'Ms') and one where Gender is male (to cover the 'else' branch and print 'Mr'). These two test cases will ensure that both branches of the decision are tested, achieving 100% decision coverage.

Discussion

6 comments
Sign in to comment
Arcino12Option: C
Jan 11, 2021

1. Verify that "Dear" is displayed 2. Verify that "Ms." is displayed if gender is Female 3. Verify that "Mr." is displayed if gender is Male

subwaysandwichOption: B
Dec 8, 2021

Ans: B. Decision coverage = minimum number of test cases to cover all branches. In this case, there is only one if-else statement, which means that 2 test cases are required. Note that if they asked for 100% statement coverage, it would still be 2, because the "Dear" statement would be covered by both test cases.

subwaysandwichOption: C
Dec 5, 2021

Ans: C. 3 tests are needed to check for "Dear", "Ms." and "Mr."

subwaysandwich
Dec 8, 2021

Please ignore this. I have revised my answer to B. See my other comment.

SivajiTheBossOption: B
Jul 15, 2022

Tip: un nested : 2 testcases (irrespective of count of If)

Shoxybee99
Aug 20, 2022

what is the statement coverage here guys?

laraerfOption: B
Jun 8, 2023

B is correct