The goal is to achieve 100% coverage of your tests for all branches (i.e., all b
ID: 3573317 • Letter: T
Question
The goal is to achieve 100% coverage of your tests for all branches (i.e., all branches of all logical decisions). What specific tests (specify the input values) would you need? List the tests along with which branches they cover below:
Consider the snippet of code below: //stake, goal, T assume they are integers bets 0; wins 0; for Cint t 0; t k T t++) 1 int cash stake while (cash 0 && cash goal) bets int random Math. random O; if random 0.5 cash++; t else cash if (cash goal) Wins++ System. out.printlnC100*wins/T wins"); System. out .printlnd"Avg H bets bets/T); The goal is to achieve 100% coverage of your tests for all branches (i.e., all branches of all logical decisions). What specific tests (specify the input values) would you need? List the tests along with which branches they cover below:Explanation / Answer
What specific tests (specify the input values) would you need?
Case 1: T value must be greater than zero (T<0)
At start, the t value is zero then T value must be greater than zero. Then the control goes to the FOR block.
Case 2: T value is less than or equal to zero(T>0)
If T value is less than Zero then control just to the next statement to the end of FOR loop. Then Print statement
System.Out.println(100*wins/T + “% wins”);
System.Out.println(“Avg # bets: ” +bets/T);
Case 3:Cash value is greater than Zero and cash value is less than goal value (cash>0 && cash<goal)
If this condition satisfy, the control go in while loop. In the while loop bets value is incremented by 1 .then random number is generated and then generated random number is check with 0.5
Case 4: Cash value is less than Zero and cash value is greater than goal value (cash<0 &&cash>goal)
Case 5: Cash value is less than Zero and cash value is less than goal value(cash<0 &&cash<goal)
Case 6: Cash value is greater than Zero and cash value is less than goal value (cash>0 &&cash<goal)
If cash value is according to case 4, case 5 or case 6 , then while loop does not execute and controls come out of while loop. And compare value of cash and goal.
Case 7: random value is less than 0.5 (random<0.5)
If random value is less than 0.5 then cash value is increment by 1.
Case 8: random value is greater than 0.5 (random>0.5)
If random value is greater than 0.5 then cash value is decrement by 1.
Case 9: value of cash and goal is equal (cash==goal)
If value of cash and goal is equal then The value of wins is increment by 1.
Case 10: value of cash and goal is not equal (cash!=goal)
If value of cash and goal is not equal then control goes out of IF statement.
List the tests along with which branches they cover below:
Function coverage:
Statement coverage
Branch coverage
Condition coverage (or predicate coverage)
Path coverage
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.