Generate test cases for the following code by using MC/DC. a) Draw the CFG. b) What is MC/DC logic coverage criteria? c) List the test cases. d) Validate the test cases can achieve MC/DC. public void TestValues( int a, int b, ref int x) { } x = 0; if (a> 0 || b < 0) x = 1; else if (a > 10 && b > 10) x = -1;

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
### Generating Test Cases Using MC/DC

#### Task Overview

Generate test cases for the following code by using Modified Condition/Decision Coverage (MC/DC). Follow the steps below:

#### a) Draw the Control Flow Graph (CFG)
- Start by analyzing the logic flow of the provided code. The CFG includes decision nodes, representing if-else conditions, and how the program flows through these nodes.

#### b) What is MC/DC Logic Coverage Criteria?
- **MC/DC** requires that each condition in a decision has been shown to independently affect the decision’s outcome.
- Test cases should be selected so that each condition within a decision is shown to independently affect the decision's outcome.

#### c) List the Test Cases
- Derive test cases based on the different input scenarios for variables `a` and `b` that evaluate each condition:

  1. `a > 0` and `b < 0`
  2. `a <= 0` and `b >= 0`
  3. `a > 10` and `b > 10`
  4. Edge cases like `a = 0`, `b = 0`, `a = 10`, and `b = 10`

#### d) Validate the Test Cases Can Achieve MC/DC
- Validate that each test case affects the resulting decision independently. Ensure coverage of all logical paths through conditions:

  - Inputs where `a > 0 || b < 0` yields `x = 1`
  - Inputs where `a > 10 && b > 10` yields `x = -1`
  - Ensure conditions minimally influence the decision outcome.

#### Code
```java
public void TestValues(int a, int b, ref int x)
{
    x = 0;
    if (a > 0 || b < 0)
        x = 1;
    else if (a > 10 && b > 10)
        x = -1;
}
```

#### Explanation:
- Initialize `x` to 0.
- First condition: `if (a > 0 || b < 0)` sets `x` to 1 if true.
- Second condition: `else if (a > 10 && b > 10)` sets `x` to -1 if true.

By following these steps, you'll generate effective test cases ensuring thorough logic coverage.
Transcribed Image Text:### Generating Test Cases Using MC/DC #### Task Overview Generate test cases for the following code by using Modified Condition/Decision Coverage (MC/DC). Follow the steps below: #### a) Draw the Control Flow Graph (CFG) - Start by analyzing the logic flow of the provided code. The CFG includes decision nodes, representing if-else conditions, and how the program flows through these nodes. #### b) What is MC/DC Logic Coverage Criteria? - **MC/DC** requires that each condition in a decision has been shown to independently affect the decision’s outcome. - Test cases should be selected so that each condition within a decision is shown to independently affect the decision's outcome. #### c) List the Test Cases - Derive test cases based on the different input scenarios for variables `a` and `b` that evaluate each condition: 1. `a > 0` and `b < 0` 2. `a <= 0` and `b >= 0` 3. `a > 10` and `b > 10` 4. Edge cases like `a = 0`, `b = 0`, `a = 10`, and `b = 10` #### d) Validate the Test Cases Can Achieve MC/DC - Validate that each test case affects the resulting decision independently. Ensure coverage of all logical paths through conditions: - Inputs where `a > 0 || b < 0` yields `x = 1` - Inputs where `a > 10 && b > 10` yields `x = -1` - Ensure conditions minimally influence the decision outcome. #### Code ```java public void TestValues(int a, int b, ref int x) { x = 0; if (a > 0 || b < 0) x = 1; else if (a > 10 && b > 10) x = -1; } ``` #### Explanation: - Initialize `x` to 0. - First condition: `if (a > 0 || b < 0)` sets `x` to 1 if true. - Second condition: `else if (a > 10 && b > 10)` sets `x` to -1 if true. By following these steps, you'll generate effective test cases ensuring thorough logic coverage.
Expert Solution
steps

Step by step

Solved in 5 steps with 2 images

Blurred answer
Knowledge Booster
Datatypes
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education