Question

For the following code, write test cases that satisfy both condition and decision coverage. void func...

For the following code, write test cases that satisfy both condition and decision coverage.


void func (int a, int b, int x) {
if (a > 1 && b == 0) {
x = x / a; }
if (a == 2 || x > 1) {
x = x + 1;
} }

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ANSWER : HERE IS THE ANSWER FOR YOUR QUESTION:

----------------------------------------------------------------------------------------------------------------

here is the reference code provided :

void func (int a, int b, int x) {
if (a > 1 && b == 0) {
x = x / a; }
if (a == 2 || x > 1) {
x = x + 1;
} }

EXPLANATION:

if we want that the both if condition should work , we need to pass the arguments such that it satisfies both the conditions

looking at both the if statement we can note that :

1) value of a should be 2 (for second if statement )

2) value of b should be 0 (for first if statement)

3) value of x must be >1 (for second if statement)

thus , combining the above three conditions , Five test cases can be :

1) a=2 , b= 0 , x=2

2) a=2 , b= 0 , x=3

3) a=2 , b= 0 , x=4

4) a=2 , b= 0 , x=5

5) a=2 , b= 0 , x=6

-----------------------------------------------------------------------------------------------

            

I hope this would help you out.

If you like my answer , please upvote

If you have any doubt, you can provide comment /feedback below the answer

Thanks

Add a comment
Know the answer?
Add Answer to:
For the following code, write test cases that satisfy both condition and decision coverage. void func...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • For the following program P3 written in pseudo-code, given the test set T: T = {t1...

    For the following program P3 written in pseudo-code, given the test set T: T = {t1 = <‐5, 2>, t2 = <3, 1>, t3 = <9, 3>} a) What is the domain for statement coverage of P3? Note: do not include syntactical markers such as comments, {, }, else, begin, end. b) What is the statement coverage for T? c) What test cases should you add to T to provide 100% statement coverage? d) What is the domain for decision...

  • For the following C statement, write the corresponding LEGv8 assembly code. long long int func( long...

    For the following C statement, write the corresponding LEGv8 assembly code. long long int func( long long int n ) { if ( n <= 1 ) { return n; } return func( n – 1 ) + func( n – 2 ); }

  • void setup () Write the following code and upload it to the { Arduino, observe and...

    void setup () Write the following code and upload it to the { Arduino, observe and comment on the pinMode (8, OUTPUT); pinMode (2, INPUT); digitalWrite (8, HIGH); function of the circuit and explain how the code is working. In addition, explain how to turn ON the LED in case it is OFF. void loop () { digitalRead (2) int A if (A 0) { digitalWrite (8, LOW); void setup () Write the following code and upload it to the...

  • Question 1 Given the following composite condition (a>=0 && b==3) || c>b Generate a...

    Question 1 Given the following composite condition (a>=0 && b==3) || c>b Generate a set of test cases (just the input values for a, b, and c) that you need to have 100% MC/DC coverage. Question 2 Given the following fragment of code: int tent=0, x=92, num; cout<<"Guess the number :"; cin>>num; while ((tent<5)&&(num!=x)) { tent++; if (num>x) cout<<"Smaller\n"; else if (num cout<<"Bigger\n"; else cout<<”You won!\n” cout<<"Guess the number :"; cin>>num; } (1) Build the corresponding control flow graph. (2)...

  • Mechatronics void setup () Write the following code and upload it to the { Arduino, observe...

    Mechatronics void setup () Write the following code and upload it to the { Arduino, observe and comment on the pinMode (8, OUTPUT) function of the circuit and explain how the pinMode (2, INPUT); code is working. In addition, explain how to digitalWrite (8, HIGH) turn ON the LED in case it is OFF. void loop () { digitalRead (2) int A if (A 0) { digitalWrite (8, LOW) void setup () Write the following code and upload it to...

  • Consider the following code: 1. float foo (int a, int b, int c, int d, float...

    Consider the following code: 1. float foo (int a, int b, int c, int d, float e) { 2. float e; 3. if (a == 0) { 4. return 0; 5. } 6. int x = 0; 7. if ((a==b) || ((c == d) && bug(a) )) { 8. x=1; 9. } 10. e = 1/x; 11. return e; 12. } Function bug(a) should return a value of true when passed a value of a=1. Build: • a test suite...

  • public static boolean primeCheck (int num) int temp; boolean isPrime-true: for(int i-2;i<=num/ 2 ; i++) temp-numsi...

    public static boolean primeCheck (int num) int temp; boolean isPrime-true: for(int i-2;i<=num/ 2 ; i++) temp-numsi if (temp=-0) isPrime-false; break; return isPrime Given the above code segment, 1. (30 points) Draw a Control Flow Graph (CFG) for the code. 2. (10 points) Enumerate the Test Requirements for node coverage. Design a set of 3. 4. 5. test cases (input value num) that will satisfy node coverage. (10 points) Enumerate the Test Requirements for edge coverage. Design a set of test...

  • HALIX PROGRAMMING C++ 1. Write Halix machine code to read and add 5 values. Test cases:...

    HALIX PROGRAMMING C++ 1. Write Halix machine code to read and add 5 values. Test cases: 1 2 3 4 5 ==>15 -1 -2 -3 -4 23 ==> 13 0 0 0 0 0 ==> 0 2. Write Halix machine code to read a value: Double it if the nu halve it when it's odd. Test cases: 14 ==> 28 0 ==>0 25==>12 -2==>-4 -7==>-3 3. Write a program that reads ans echoes (display what was just values that are...

  • Provide test-cases to ensure 100% Statement Coverage. Provide actual values in your test-cases. printSum(int a, int...

    Provide test-cases to ensure 100% Statement Coverage. Provide actual values in your test-cases. printSum(int a, int b) int result- ab; if (result > 0) print ("Possitive Number:"result)s else if (result<) print ("Negative Number:"+ result); ) else print ("Equal Zero:"+result)

  • QUESTION 62 Consider the following code: void Pancake(int x, int& y, int z); void Waffle(int& x,...

    QUESTION 62 Consider the following code: void Pancake(int x, int& y, int z); void Waffle(int& x, int& y); int Doughnut(int y, int z); int main( ) {             int a = 1;             int b = 2;             int c = 3;             int d = 4;             Pancake(a, b, c);             Waffle(b, c);             Pancake(d, c, b);             d = Doughnut(b, a);             return 0; } void Pancake(int x, int& y, int z) {             y += 3;            ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT