0% found this document useful (0 votes)
6 views8 pages

Experiment 11

Uploaded by

rohansahu02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views8 pages

Experiment 11

Uploaded by

rohansahu02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

EXPERIMENT 11

AIM: Write a program to program to perform Control Flow Testing.

THEORY:

Control Flow Testing is a white-box testing technique used to design test cases by
analyzing the control flow of a program. It focuses on the logical paths and
decisions taken during program execution. The goal is to ensure that all possible
paths through the program's control structure (like decisions, loops, and branches)
are tested at least once.

CODE:
#include <iostream>

#include <cassert>

#include <string>

using namespace std;

string numberCheck(int num) {

if (num > 0) {

return "Positive";

} else if (num < 0) {

return "Negative";

} else {

return "Zero";

void controlFlowTesting() {

cout << "Starting Control Flow Testing..." << endl;

assert(numberCheck(10) == "Positive");

cout << "Test case 1 passed: Positive number." << endl;


assert(numberCheck(-5) == "Negative");

cout << "Test case 2 passed: Negative number." << endl;

assert(numberCheck(0) == "Zero");

cout << "Test case 3 passed: Zero." << endl;

cout << "All test cases passed!" << endl;

int main() {

controlFlowTesting();

cout << "\nOptional Interactive Testing" << endl;

int num;

cout << "Enter a number to check: ";

cin >> num;

cout << "The number is " << numberCheck(num) << "." << endl;

return 0;

OUTPUT:
EXPERIMENT 12
AIM: Write a program to program to perform Data Flow Testing.

THEORY:

Data Flow Testing is a white-box testing technique that focuses on the use and
definition of variables within a program. It examines how data flows through the
program, particularly analyzing the points where variables are defined, used, and
killed (become out of scope or reassigned).

CODE:

#include <iostream>

#include <cassert>

#include <vector>

using namespace std;

int calculateSum(const vector<int>& numbers) {

int sum = 0;

for (int i = 0; i < numbers.size(); i++) {

sum += numbers[i];

return sum;

void dataFlowTesting() {

cout << "Starting Data Flow Testing..." << endl;

vector<int> test1 = {1, 2, 3, 4};

assert(calculateSum(test1) == 10);

cout << "Test case 1 passed!" << endl;


vector<int> test2 = {-1, -2, -3, -4};

assert(calculateSum(test2) == -10);

cout << "Test case 2 passed!" << endl;

vector<int> test3 = {-1, 2, -3, 4};

assert(calculateSum(test3) == 2);

cout << "Test case 3 passed!" << endl;

vector<int> test4 = {};

assert(calculateSum(test4) == 0);

cout << "Test case 4 passed!" << endl;

cout << "All test cases passed!" << endl;

int main() {

dataFlowTesting();

cout << "\nOptional Interactive Testing:" << endl;

int n;

cout << "Enter the number of elements in the array: ";

cin >> n;

vector<int> userArray(n);

cout << "Enter the elements of the array:" << endl;

for (int i = 0; i < n; i++) {

cin >> userArray[i];

cout << "The sum of the array is: " << calculateSum(userArray) << endl;
return 0;

Output:
EXPERIMENT 13
AIM: Write a program to program to perform Data Flow Testing.

THEORY:

Slice-Based Testing is a technique that focuses on isolating parts of the code


(slices) that directly influence a specific variable or computation. A program slice
is a subset of program statements that are relevant to a particular variable or output
at a specific point. By analyzing slices, we can test only the relevant parts of the
code for a specific functionality or variable, improving test efficiency and
debugging.

CODE:

#include <iostream>

#include <cassert>

using namespace std;

int calculateArea(int length, int width) {

return length * width; // Slice 1: Area calculation

bool isAboveThreshold(int area, int threshold) {

return area >= threshold; // Slice 2: Threshold comparison

void sliceBasedTesting() {

cout << "Starting Slice-Based Testing..." << endl;

assert(calculateArea(5, 10) == 50);

cout << "Slice 1 Test 1 passed: Area calculation is correct." << endl;

assert(calculateArea(0, 10) == 0);


cout << "Slice 1 Test 2 passed: Area calculation with zero is correct." << endl;

assert(calculateArea(7, 3) == 21);

cout << "Slice 1 Test 3 passed: Area calculation is correct." << endl;

assert(isAboveThreshold(50, 40) == true);

cout << "Slice 2 Test 1 passed: Threshold comparison is correct." << endl;

assert(isAboveThreshold(30, 30) == true);

cout << "Slice 2 Test 2 passed: Threshold comparison is correct." << endl;

assert(isAboveThreshold(20, 50) == false);

cout << "Slice 2 Test 3 passed: Threshold comparison is correct." << endl;

cout << "All Slice-Based Tests Passed!" << endl;

int main() {

sliceBasedTesting();

cout << "\nOptional Interactive Testing:" << endl;

int length, width, threshold;

cout << "Enter length and width of the rectangle: ";

cin >> length >> width;

int area = calculateArea(length, width);

cout << "The area of the rectangle is: " << area << endl;

cout << "Enter the threshold value: ";

cin >> threshold;

if (isAboveThreshold(area, threshold)) {
cout << "The area meets or exceeds the threshold." << endl;

} else {

cout << "The area is below the threshold." << endl;

return 0;

Output

You might also like