0% found this document useful (0 votes)
12 views45 pages

Software Testing

This document is a lab file for a Software Testing course at Manav Rachna University, detailing various lab assignments and programming tasks. It includes C++ programs for calculating binary values, factorial sums, digit sums, inverse numbers, and generating patterns, along with a case study for sales commission calculation. The document also outlines course outcomes, testing techniques, and a structured approach for boundary value, robustness, and worst-case testing.

Uploaded by

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

Software Testing

This document is a lab file for a Software Testing course at Manav Rachna University, detailing various lab assignments and programming tasks. It includes C++ programs for calculating binary values, factorial sums, digit sums, inverse numbers, and generating patterns, along with a case study for sales commission calculation. The document also outlines course outcomes, testing techniques, and a structured approach for boundary value, robustness, and worst-case testing.

Uploaded by

Praveen Tiwari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MANAV RACHNA UNIVERSITY

SCHOOL OF ENGINEERING
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY

LAB FILE

SOFTWARE TESTING (CSW328)

Submitted to: Submitted by:


Mr. Ram Chatterjee 2K22CSUN01077
Assistant Professor Praveen Kumar Tiwari
MRU-DoCST CSE_7B
MANAV RACHNA UNIVERSITY
SCHOOL OF ENGINEERING
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY

S. No. Lab Assignment Topic Date Page No. Faculty Remarks


1. Design Test Cases for the given 1st Aug., 2025
programs
2. Functional Testing Techniques-1 8th Aug 2025
3. Functional Testing Techniques-2 22nd Aug 2025
4. Basis Path Testing 29th Aug 2025
5. Decision Table Testing 5th Sept. 2025
6.1 DD Path Testing 12th Sept. 2025
6.2 Data Flow Testing 12th Sept. 2025
Lab 1

Course Outcomes:
CSH405B.1: Define software testing and infer mastery of the testing
techniques.
CSH405B.2: Identify the fundamental characteristics of good test case
design and apply
contemporary testing principles and techniques.
Bloom's Taxonomy: BT1, BT2, BT3

Program to find binary value of a number.


#include <iostream>
#include <string>
using namespace std;

string decimalToBinary(int n) {
if (n < 0) {
return "Error: Negative number";
}
if (n == 0) {
return "0";
}

string binary = "";


while (n > 0) {
binary = to_string(n % 2) + binary;
n /= 2;
}
return binary;
}

int main() {
int
number;
cout << "Enter a positive integer: ";
cin >> number;

string binary = decimalToBinary(number);


cout << "Binary equivalent: " << binary << endl;

return 0;

}
Output

Program to find sum 1/1! + 1/2! + 1/3! + ………….

#include <iostream>
#include <iomanip>
using namespace std;

double factorialSum(int n) {
if (n <= 0) {
cout << "Error: Please enter positive integer" << endl;
return -1;
}

double sum = 0.0;


double fact = 1.0;

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


fact *= i;
sum += 1.0 / fact;
}
return sum;
}

int main() {
int terms;
cout << "Enter number of terms: ";
cin >> terms;
double result = factorialSum(terms);
if (result != -1) {
cout << fixed << setprecision(4);
cout << "Sum of series: " << result << endl;
}

return 0;
}
Output

Program to accept a positive integer. Then add up all the digits and
print out the sum. For example given 12345, the sum is 1+2+3+4+5.
#include <iostream>
using namespace std;

int digitSum(int n) {
if (n <= 0) {
cout << "Error: Please enter positive integer" << endl;
return -1;
}

int sum = 0;
int temp = n;
while (temp > 0) {
sum += temp % 10;
temp /= 10;
}

return sum;
}

int main() {
int number;
cout << "Enter a positive integer: ";
cin >> number;

int sum = digitSum(number);


if (sum != -1) {
cout << "Sum of digits: " << sum << endl;
}

return 0;
}
Output

Program to accept a 5 digit positive integer. Print out the inverse of


that number. For example given 12345, print out 54321.
#include <iostream>
using namespace std;

int inverseNumber(int n) {
if (n < 10000 || n > 99999) {
cout << "Error: Please enter a 5-digit positive integer" << endl;
return -1;
}

int inverse = 0;
int temp = n;
while (temp > 0) {
inverse = inverse * 10 + (temp % 10);
temp /= 10;
}

return inverse;
}

int main() {
int number;
cout << "Enter a 5-digit positive integer: ";
cin >> number;

int inverse = inverseNumber(number);


if (inverse != -1) {
cout << "Inverse number: " << inverse << endl;
}

return 0;
}
Output
e. Program To generate pattern

1
121
12321
1234321
123454321
12345654321
#include <iostream>
using namespace std;

void generatePattern(int n) {
if (n <= 0) {
cout << "Error: Please enter positive integer" << endl;
return;
}

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


// Print leading spaces
for (int j = 1; j <= n - i; j++) {
cout << " ";
}

// Print increasing numbers


for (int j = 1; j <= i; j++) {
cout << j;
}

// Print decreasing numbers


for (int j = i - 1; j >= 1; j--) {
cout << j;
}
cout << endl;
}
}

int main() {
int rows;
cout << "Enter number of rows: ";
cin >> rows;

generatePattern(rows);

return 0;
}
Output
Lab 2
Course Outcomes:
CSH405B.1: Define software testing and infer mastery of the testing
techniques.
CSH405B.2: Identify the fundamental characteristics of good test case
design and apply
contemporary testing principles and techniques.
Bloom's Taxonomy: BT1, BT2,BT3

Rifle salespersons in the Arizona Territory sold rifle locks, stocks, and
barrels made by a gunsmith in Missouri. Locks cost $55.00, stocks cost
$40.00, and barrels cost $35.00. Salespersons had to sell at least one
complete rifle per month, and production limits are such that the most
one salesperson could sell in a month is 70 locks, 80 stocks, and 90
barrels. The sales person used to send the details of the sold items to the
gunsmith. The gunsmith then computed the sales person’s commission
as follows:
10% on sales up to and including $1000
15% on the next $800
And 20% on any sales in excess of $1800.

The company produces a monthly sales report that gives the total
number of locks, stocks, and barrels sold, the salesperson’s total dollar
sales, and finally his/her commission.

Write the C++ program based on the given case study and perform:
Boundary Value Testing.
Robustness Testing.
And Worst Case Testing.
Format of Test Case Report:
Test Input Input Input Expected Actual Test
Case Variable Variable Variable Output Output Result
Id 1 2 3 (Pass/Fail)
Code :

#include <bits/stdc++.h>
using namespace std;

const double LOCK_PRICE = 55.00;


const double STOCK_PRICE = 40.00;
const double BARREL_PRICE = 35.00;

struct TestCase {
string id;
int locks;
int stocks;
int barrels;
double expectedSales;
double expectedCommission;
double actualSales;
double actualCommission;
string result;
};

class SalesCommissionCalculator {
private:
int locks;
int stocks;
int barrels;
double totalSales;
double commission;

bool validateInput() {
return (locks >= 1 && locks <= 70) &&
(stocks >= 1 && stocks <= 80) &&
(barrels >= 1 && barrels <= 90);
}

void calculateTotalSales() {
totalSales = (locks * LOCK_PRICE) +
(stocks * STOCK_PRICE) +
(barrels * BARREL_PRICE);
}

void calculateCommission() {
if (totalSales <= 1000) {
commission = totalSales * 0.10;
} else if (totalSales <= 1800) {
commission = 1000 * 0.10 + (totalSales - 1000) * 0.15;
} else {
commission = 1000 * 0.10 + 800 * 0.15 + (totalSales - 1800) *
0.20;
}
}

public:
SalesCommissionCalculator(int l = 0, int s = 0, int b = 0) : locks(l),
stocks(s), barrels(b) {
totalSales = 0.0;
commission = 0.0;
}

bool processSales(int l, int s, int b) {


locks = l;
stocks = s;
barrels = b;
if (!validateInput()) {
return false;
}

calculateTotalSales();
calculateCommission();
return true;
}

double getTotalSales() const { return totalSales; }


double getCommission() const { return commission; }
};

void runBoundaryValueTests(vector<TestCase>& testCases) { cout


<< "\n=== BOUNDARY VALUE TESTING ===" << endl;

vector<TestCase> bvtCases = {
{"BVT-1", 1, 1, 1, 130.00, 13.00, 0, 0, ""},
{"BVT-2", 1, 1, 90, 3285.00, 517.00, 0, 0, ""},
{"BVT-3", 1, 80, 1, 3295.00, 519.00, 0, 0, ""},
{"BVT-4", 70, 1, 1, 3925.00, 645.00, 0, 0, ""},
{"BVT-5", 70, 80, 90, 10850.00, 1970.00, 0, 0, ""},
{"BVT-6", 35, 40, 45, 5425.00, 965.00, 0, 0, ""}
};

for (auto& test : bvtCases) {


SalesCommissionCalculator calc;
if ([Link]([Link], [Link], [Link])) {
[Link] = [Link]();
[Link] = [Link]();
[Link] = (abs([Link] - [Link]) < 0.01
&&
abs([Link] - [Link])
< 0.01)
? "PASS" : "FAIL";
} else {
[Link] = "FAIL";
}
testCases.push_back(test);
}
}

void runRobustnessTests(vector<TestCase>& testCases) {


cout << "\n=== ROBUSTNESS TESTING ===" << endl;

vector<TestCase> robustCases = {
{"RT-1", 0, 40, 45, 0, 0, 0, 0, "ERROR"},
{"RT-2", 71, 40, 45, 0, 0, 0, 0, "ERROR"},
{"RT-3", 35, 0, 45, 0, 0, 0, 0, "ERROR"},
{"RT-4", 35, 81, 45, 0, 0, 0, 0, "ERROR"},
{"RT-5", 35, 40, 0, 0, 0, 0, 0, "ERROR"},
{"RT-6", 35, 40, 91, 0, 0, 0, 0, "ERROR"},
{"RT-7", -1, 40, 45, 0, 0, 0, 0, "ERROR"},
{"RT-8", 35, -5, 45, 0, 0, 0, 0, "ERROR"}
};

for (auto& test : robustCases) {


SalesCommissionCalculator calc;
if ([Link]([Link], [Link], [Link])) {
[Link] = "FAIL";
} else {
[Link] = "PASS";
}
testCases.push_back(test);
}
}

void runWorstCaseTests(vector<TestCase>& testCases) {


cout << "\n=== WORST CASE TESTING ===" << endl;

vector<TestCase> wcCases = {
{"WC-1", 10, 10, 10, 1300.00, 145.00, 0, 0, ""},
{"WC-2", 9, 9, 9, 1170.00, 125.50, 0, 0, ""},
{"WC-3", 18, 18, 18, 2340.00, 368.00, 0, 0, ""},
{"WC-4", 17, 17, 17, 2210.00, 343.00, 0, 0, ""},
{"WC-5", 19, 19, 19, 2470.00, 394.00, 0, 0, ""},
{"WC-6", 8, 8, 8, 1040.00, 106.00, 0, 0, ""},
{"WC-7", 20, 20, 20, 2600.00, 420.00, 0, 0, ""}
};

for (auto& test : wcCases) {


SalesCommissionCalculator calc;
if ([Link]([Link], [Link], [Link])) {
[Link] = [Link]();
[Link] = [Link]();
[Link] = (abs([Link] - [Link]) < 0.01
&&
abs([Link] - [Link])
< 0.01)
? "PASS" : "FAIL";
} else {
[Link] = "FAIL";
}
testCases.push_back(test);
}
}
void printTestReport(const vector<TestCase>& testCases) {
cout << "\n\n=== COMPREHENSIVE TEST REPORT ===" << endl;
cout <<
"========================================================
==========================================" << endl;
cout << left << setw(8) << "TC ID" << setw(8) << "Locks" << setw(8)
<< "Stocks"
<< setw(10) << "Barrels" << setw(12) << "Exp Sales" << setw(15)
<< "Exp Commission"
<< setw(12) << "Act Sales" << setw(15) << "Act Commission" <<
setw(8) << "Result" << endl;
cout <<
"========================================================
==========================================" << endl;

for (const auto& test : testCases) {


cout << left << setw(8) << [Link]
<< setw(8) << [Link]
<< setw(8) << [Link]
<< setw(10) << [Link];

if ([Link] > 0) {
cout << fixed << setprecision(2)
<< setw(12) << [Link]
<< setw(15) << [Link]
<< setw(12) << [Link]
<< setw(15) << [Link];
} else {
cout << setw(12) << "ERROR"
<< setw(15) << "ERROR"
<< setw(12) << "ERROR"
<< setw(15) << "ERROR";
}

cout << setw(8) << [Link] << endl;


}
cout <<
"========================================================
==========================================" << endl;
}

void manualInput() {
int locks, stocks, barrels;

cout << "\n=== MANUAL INPUT ===" << endl;


cout << "Enter number of locks sold (1-70): ";
cin >> locks;

cout << "Enter number of stocks sold (1-80): ";


cin >> stocks;

cout << "Enter number of barrels sold (1-90): ";


cin >> barrels;

SalesCommissionCalculator calculator;

if ([Link](locks, stocks, barrels)) {


cout << fixed << setprecision(2);
cout << "\n=== SALES REPORT ===" << endl;
cout << "Locks sold: " << locks << endl;
cout << "Stocks sold: " << stocks << endl;
cout << "Barrels sold: " << barrels << endl;
cout << "Total sales: quot; << [Link]() << endl;
cout << "Commission: quot; << [Link]() << endl;
} else {
cout << "Error: Invalid input! Constraints:\n";
cout << "Locks: 1-70, Stocks: 1-80, Barrels: 1-90\n";
}
}

int main() {
vector<TestCase> allTestCases;

cout << "RIFLE SALES COMMISSION CALCULATOR" << endl;


cout << "=================================" << endl;

int choice;
cout << "1. Run All Tests\n2. Manual Input\nChoose option (1 or 2):
";
cin >> choice;

if (choice == 1) {
runBoundaryValueTests(allTestCases);
runRobustnessTests(allTestCases);
runWorstCaseTests(allTestCases);
printTestReport(allTestCases);
} else {
manualInput();
}

return 0;
}

Output
Lab 3

Course Outcomes:
CSH405B.1: Define software testing and infer mastery of the testing
techniques.
CSH405B.2: Identify the fundamental characteristics of good test case
design and apply
contemporary testing principles and techniques.
CSH405B.3: Make use of Test Driven Development (TDD) to help
construct software
without code smells by choosing manual and automated testing
approaches.
Bloom's Taxonomy: BT1, BT2,BT3

Rifle salespersons in the Arizona Territory sold rifle locks, stocks, and
barrels made by a gunsmith in Missouri. Locks cost $55.00, stocks cost
$40.00, and barrels cost $35.00. Salespersons had to sell at least one
complete rifle per month, and production limits are such that the most
one salesperson could sell in a month is 70 locks, 80 stocks, and 90
barrels. The sales person used to send the details of the sold items to the
gunsmith. The gunsmith then computed the sales person’s commission
as follows:
10% on sales up to and including $1000
15% on the next $800
And 20% on any sales in excess of $1800.

The company produces a monthly sales report that gives the total
number of locks, stocks, and barrels sold, the salesperson’s total dollar
sales, and finally his/her commission.
Write the C++ program based on the given case study and perform:
Weak Normal Equivalence Class Testing.
Weak Robust Equivalence Class Testing.
Strong Normal Equivalence Case Testing.
And Strong Robust Equivalence Class Testing.

Format of Test Case Report:


Test Input Input Input Expected Actual Test
Case Variable Variable Variable Output Output Result
Id 1 2 3 (Pass/Fail)
Code:
#include <bits/stdc++.h>
using namespace std;

const double LOCK_PRICE = 55.00;


const double STOCK_PRICE = 40.00;
const double BARREL_PRICE = 35.00;

struct TestCase {
string id;
int locks;
int stocks;
int barrels;
double expectedSales;
double expectedCommission;
double actualSales;
double actualCommission;
string result;
};

class SalesCommissionCalculator {
private:
int locks;
int stocks;
int barrels;
double totalSales;
double commission;

bool validateInput() {
return (locks >= 1 && locks <= 70) &&
(stocks >= 1 && stocks <= 80) &&
(barrels >= 1 && barrels <= 90);
}

void calculateTotalSales() {
totalSales = (locks * LOCK_PRICE) +
(stocks * STOCK_PRICE) +
(barrels * BARREL_PRICE);
}

void calculateCommission() {
if (totalSales <= 1000) {
commission = totalSales * 0.10;
} else if (totalSales <= 1800) {
commission = 1000 * 0.10 + (totalSales - 1000) * 0.15;
} else {
commission = 1000 * 0.10 + 800 * 0.15 + (totalSales - 1800) * 0.20;
}
}

public:
SalesCommissionCalculator(int l = 0, int s = 0, int b = 0) : locks(l),
stocks(s), barrels(b) {
totalSales = 0.0;
commission = 0.0;
}

bool processSales(int l, int s, int b) {


locks = l;
stocks = s;
barrels = b;

if (!validateInput()) {
return false;
}

calculateTotalSales();
calculateCommission();
return true;
}

double getTotalSales() const { return totalSales; }


double getCommission() const { return commission; }
};

void runWeakNormalTests(vector<TestCase>& testCases) {


vector<TestCase> wnCases = {
{"WN-1", 1, 1, 1, 130.00, 13.00, 0, 0, ""},
{"WN-2", 35, 40, 45, 5425.00, 965.00, 0, 0, ""},
{"WN-3", 10, 10, 10, 1300.00, 145.00, 0, 0, ""},
{"WN-4", 18, 18, 18, 2340.00, 368.00, 0, 0, ""}
};

for (auto& test : wnCases) {


SalesCommissionCalculator calc;
if ([Link]([Link], [Link], [Link])) {
[Link] = [Link]();
[Link] = [Link]();
[Link] = (abs([Link] - [Link]) < 0.01 &&
abs([Link] - [Link]) <
0.01)
? "PASS" : "FAIL";
} else {
[Link] = "FAIL";
}
testCases.push_back(test);
}
}

void runWeakRobustTests(vector<TestCase>& testCases) {


vector<TestCase> wrCases = {
{"WR-1", 1, 1, 1, 130.00, 13.00, 0, 0, ""},
{"WR-2", 0, 40, 45, 0, 0, 0, 0, "ERROR"},
{"WR-3", 35, 0, 45, 0, 0, 0, 0, "ERROR"},
{"WR-4", 35, 40, 0, 0, 0, 0, 0, "ERROR"},
{"WR-5", 71, 40, 45, 0, 0, 0, 0, "ERROR"}
};

for (auto& test : wrCases) {


SalesCommissionCalculator calc;
if ([Link]([Link], [Link], [Link])) {
if ([Link] > 0) {
[Link] = [Link]();
[Link] = [Link]();
[Link] = (abs([Link] - [Link]) < 0.01 &&
abs([Link] - [Link]) <
0.01)
}
else
{ ?
"PASS
":
"FAIL";
[Link] = "FAIL";
}
} else {
if ([Link] == 0) {
[Link] = "PASS";
} else {
[Link] = "FAIL";
}
}
testCases.push_back(test);
}
}

void runStrongNormalTests(vector<TestCase>& testCases) {


vector<TestCase> snCases = {
{"SN-1", 1, 1, 1, 130.00, 13.00, 0, 0, ""},
{"SN-2", 1, 1, 90, 3285.00, 517.00, 0, 0, ""},
{"SN-3", 1, 80, 1, 3295.00, 519.00, 0, 0, ""},
{"SN-4", 70, 1, 1, 3925.00, 645.00, 0, 0, ""},
{"SN-5", 70, 80, 90, 10850.00, 1970.00, 0, 0, ""},
{"SN-6", 10, 10, 10, 1300.00, 145.00, 0, 0, ""},
{"SN-7", 18, 18, 18, 2340.00, 368.00, 0, 0, ""}
};

for (auto& test : snCases) {


SalesCommissionCalculator calc;
if ([Link]([Link], [Link], [Link])) {
[Link] = [Link]();
[Link] = [Link]();
[Link] = (abs([Link] - [Link]) < 0.01 &&
abs([Link] - [Link]) <
0.01)
? "PASS" : "FAIL";
} else {
[Link] = "FAIL";
}
testCases.push_back(test);
}
}

void runStrongRobustTests(vector<TestCase>& testCases) {


vector<TestCase> srCases = {
{"SR-1", 1, 1, 1, 130.00, 13.00, 0, 0, ""},
{"SR-2", 0, 40, 45, 0, 0, 0, 0, "ERROR"},
{"SR-3", 35, 0, 45, 0, 0, 0, 0, "ERROR"},
{"SR-4", 35, 40, 0, 0, 0, 0, 0, "ERROR"},
{"SR-5", 71, 40, 45, 0, 0, 0, 0, "ERROR"},
{"SR-6", 35, 81, 45, 0, 0, 0, 0, "ERROR"},
{"SR-7", 35, 40, 91, 0, 0, 0, 0, "ERROR"},
{"SR-8", -1, 40, 45, 0, 0, 0, 0, "ERROR"},
{"SR-9", 35, -5, 45, 0, 0, 0, 0, "ERROR"}
};

for (auto& test : srCases) {


SalesCommissionCalculator calc;
if ([Link]([Link], [Link], [Link])) {
if ([Link] > 0) {
[Link] = [Link]();
[Link] = [Link]();
[Link] = (abs([Link] - [Link]) < 0.01 &&
abs([Link] - [Link]) <
0.01)
? "PASS" : "FAIL";
} else {
[Link] = "FAIL";
}
} else {
if ([Link] == 0) {
[Link] = "PASS";
} else {
[Link] = "FAIL";
}
}
testCases.push_back(test);
}
}

void printTestReport(const vector<TestCase>& testCases, const string&


testType) {
cout << "\n\n=== " << testType << " TEST REPORT ===" << endl;
cout <<
"=============================================================
=====================================" << endl;
cout << left << setw(8) << "TC ID" << setw(8) << "Locks" << setw(8) <<
"Stocks"
<< setw(10) << "Barrels" << setw(12) << "Exp Sales" << setw(15) <<
"Exp Commission"
<< setw(12) << "Act Sales" << setw(15) << "Act Commission" <<
setw(8) << "Result" << endl;
cout <<
"=============================================================
=====================================" << endl;

for (const auto& test : testCases) {


if ([Link]([Link](0,2)) != string::npos) {
cout << left << setw(8) << [Link]
<< setw(8) << [Link]
<< setw(8) << [Link]
<< setw(10) << [Link];
if ([Link] > 0) {
cout << fixed << setprecision(2)
<< setw(12) << [Link]
<< setw(15) << [Link]
<< setw(12) << [Link]
<< setw(15) << [Link];
} else {
cout << setw(12) << "ERROR"
<< setw(15) << "ERROR"
<< setw(12) << "ERROR"
<< setw(15) << "ERROR";
}

cout << setw(8) << [Link] << endl;


}
}
cout <<
"=============================================================
=====================================" << endl;
}

int main() {
vector<TestCase> allTestCases;
cout << "RIFLE SALES COMMISSION CALCULATOR - EQUIVALENCE CLASS
TESTING" << endl;
cout <<
"=============================================================
" << endl;

runWeakNormalTests(allTestCases);
runWeakRobustTests(allTestCases);
runStrongNormalTests(allTestCases);
runStrongRobustTests(allTestCases);

printTestReport(allTestCases, "WEAK NORMAL");


printTestReport(allTestCases, "WEAK ROBUST");
printTestReport(allTestCases, "STRONG NORMAL");
printTestReport(allTestCases, "STRONG ROBUST");

return 0;
}
Output:
CSW442-PR SOFTWARE TESTING WORKSHOP

LAB ASSIGNMENT-4

Course Outcomes:
CSH405B.1: Define software testing and infer mastery of the testing techniques.
CSH405B.2: Identify the fundamental characteristics of good test case design and apply
contemporary testing principles and techniques.
CSH405B.3: Make use of Test Driven Development (TDD) to help construct software
without code smells by choosing manual and automated testing approaches.

Bloom's Taxonomy: BT1, BT2,BT3

Question 1: Perform Basis Path Testing for the following given source codes, in
following terms:

Draw the flow graph.


Calculate cyclomatic complexity V(G) using all the techniques you have
learned.
Indicate the Independent Paths as per the V(G) denoted.
Design Test Cases to test each independent path traversed.

Format of Test Case Report:


Test Input Input Input Expected Actual Test
Case Id Variable Variable Variable Output Output Result
1 2 3 (Pass/Fail)

Program to generate all combinations of 1, 2 and 3 using for loop.

#include <stdio.h>
#include <conio.h>
int main()
{
int i,j,k,l,count=0;

for(i=1;i<=4;i++)
{
for(j=1;j<=4;j++)
{
for(k=1;k<=4;k++)
{
for(l=1;l<=4;l++)
{
if(i!=j&&j!=k&&i!=k&&i!=l&&j!=l&&k!=l)
{
printf("\n%d %d %d %d",i,j,k,l);
count++;
}
}
}
}
}
printf("\ncount = %d",count);
CSW442-PR SOFTWARE TESTING WORKSHOP

getch();
return 0;
}

Flow Graph (Description)


Start → initialize i=1 → loop check (i ≤ 4)? → j=1 → loop check (j ≤ 4)? → k=1 → loop check (k
≤ 4)? → l=1 → loop check (l ≤ 4)? → Condition (i!=j && j!=k && i!=k && i!=l && j!=l && k!=l). If
true → print combination and increment count. Else skip. → Increment l → repeat until l > 4 →
Increment k → repeat until k > 4 → Increment j → repeat until j > 4 → Increment i → repeat until
i > 4 → Print final count → End.

Cyclomatic Complexity
Method 1 (Edges & Nodes): V(G) = 14 - 12 + 2 = 4
Method 2 (Predicate Nodes): 5 + 1 = 6
Method 3 (Independent Paths): 6

Independent Paths
All loops entered, if-condition true → valid permutation printed.
All loops entered, if-condition false → no print.
i-loop exits directly (no iterations).
j-loop exits directly.
k-loop exits directly.
l-loop exits directly.

Test Cases
Test Input Input Input Input Expected Actual Test
Case Id Variable Variable Variable Variable Output Output Result
1 2 3 4
TC1 1 2 3 4 Prints 1 2 Same Pass
34
TC2 1 1 2 3 No output Same Pass
(fails
condition)
TC3 i>4 - - - Loop Same Pass
exits, only
count=0
printed
TC4 1 j>4 - - No Same Pass
iteration
of j-loop
TC5 1 2 k>4 - No Same Pass
iteration
of k-loop
TC6 1 2 3 l>4 No Same Pass
iteration
of l-loop
CSW442-PR SOFTWARE TESTING WORKSHOP

Program to calculate overtime pay of 10 employees. Overtime is paid at the rate of Rs.
12.00 per hour for every hour worked above 40 hours. Assume that employees do not
work for fractional part of an hour.

#include <stdio.h> //header file


#include <conio.h> //header file
int main() //main function.. starting of c code
{
int hour,employee,overtime,overtime_pay;

employee=1;
while (employee<=10)
{
printf("\nEnter the [Link] Hrs done by employee %d:",employee);
scanf ("%d",&hour);
if(hour>40)
{
overtime = hour-40;
overtime_pay =12*overtime;
printf ("\nYour overtime pay is:%d\n\n", overtime_pay);
}
else if (hour<=40)
{
printf("\nYou won't get overtime pay.\n\n");
}
employee++;
}

getch();
return 0;
}

Flow Graph (Description)


Start → initialize employee=1 → while(employee ≤ 10)? → Input hours worked → if(hour > 40)?
Yes → overtime = hour - 40 → overtime_pay = 12 * overtime → print overtime pay.
No → print no overtime pay.
Increment employee → repeat until employee > 10 → End.

Cyclomatic Complexity
Predicate nodes: while loop + if + else = 2
V(G) = P + 1 = 2 + 1 = 3
Independent paths = 3

Independent Paths
Employee ≤ 10, hours > 40 → overtime calculated.
Employee ≤ 10, hours ≤ 40 → no overtime.
Employee > 10 → exit loop and terminate.

Test Cases
Test Case Employee Hours Expected Actual Result
Id Worked Output Output
TC1 1 45 Overtime Same Pass
pay = 60
TC2 2 40 No overtime Same Pass
TC3 11 - Exit loop Same Pass
CSW442-PR SOFTWARE TESTING WORKSHOP

When interest compounds q times per year at an annual rate of r % for n years, the
principle p compounds to an amount a as per the following formula

Write a program to read 10 sets of p, r, n & q and calculate the corresponding as.

#include <stdio.h>
#include <conio.h>
int main()
{
int p,r,n,q,a,i,j,product;
float amt=1;
for(i=0;i<10;i++)
{
amt=1;
printf("enter the values of p,r,n and q: ");
scanf("%d%d%d%d",&p,&r,&n,&q);

product=n*q;
for(j=1;j<=product;j++)/*for calculating power value.
function also can be use but this is loop
chapter so we try to make use of loop*/
{
amt = amt * ( 1 +(float) r / q );/* r/q gives integer.(float) changes
to float value.*/
}
amt= p *amt;
printf("%f",amt);

getch();
return 0;
}

Flow Graph (Description)


Start → for(i=0; i<10; i++)? → Input values p,r,n,q → compute product = n*q →
for(j=1; j<=product; j++)? → amt = amt * (1 + (float)r/q) → after loop amt = p * amt → print amt
→ repeat → End.

Cyclomatic Complexity
Predicate nodes: outer for + inner for = 2
V(G) = P + 1 = 2 + 1 = 3
Independent paths = 3

Independent Paths
Loop executes with valid inputs, compound interest calculated.
Outer loop condition fails immediately (i ≥ 10).
Inner loop condition fails immediately (product=0).
CSW442-PR SOFTWARE TESTING WORKSHOP

Test Cases
Test Case p r n q Expected Result
Id Output
TC1 1000 10 2 1 Amount > Pass
1000
TC2 2000 5 0 1 Amount = Pass
2000
TC3 - - - - No Pass
execution
when i≥10

Design a structure to store a length in yards, feet and inches(for eg7 yards,2 feet,3
inches). Write a function to find the difference between two measurements as
represented by these structures.

#include<stdio.h>
#include<conio.h>
struct len
{
int yards;
int feet;
int inches;
}s;
void convert(int y,int f,int in)
{int ff,inn;
ff=y*3;
inn=f*12;
printf("%d %d",ff,inn);
}

void main()
{ clrscr();

printf("enter length in yards,feet and inches");


scanf("%d %d %d",&[Link],&[Link],&[Link]);
convert([Link],[Link],[Link]);
}

Flow Graph (Description)


Start → Input yards, feet, inches → call convert() → convert(): calculate feet = y*3, inches = f*12
→ print converted values → End.

Cyclomatic Complexity
Only sequential steps, no decisions.
Predicate nodes = 0 → V(G) = 0 + 1 = 1

Independent Paths
Only 1 independent path: sequential execution.

Test Cases
Test Case Yards Feet Inches Expected Result
Id Output
TC1 7 2 3 Feet=21, Pass
Inches=24
TC2 0 5 10 Feet=0, Pass
Inches=60
CSW442-PR SOFTWARE TESTING WORKSHOP

LAB ASSIGNMENT-5

Course Outcomes:
CO1: Define software testing and infer mastery of the testing techniques.
CO2: Identify the fundamental characteristics of good test case design and apply
contemporary testing principles and techniques.
CO3: Make use of Test Driven Development (TDD) to help construct software without
code smells by choosing manual and automated testing approaches.

Bloom's Taxonomy: BT1, BT2, BT3

Question 1: Consider the payroll system of a person:


If the salary of a person is less than equal to Rs.70000/- and expenses do not
exceed Rs.30000/- then 10% tax is charged by IT Department.
If the salary is greater than Rs.70000/- and less than equal to Rs.2lacs and
expenses don’t exceed Rs.40000/- then 20% tax is charged by IT
Department.
For salary greater than Rs.2lacs, 5% additional surcharge is also
charged.
If expenses are greater than Rs.40000/- surcharge is 9%.

Perform the following for the above given problem:


Write the program to calculate the Payroll.
Identify the Causes and Effects and draw the Cause-Effect Graph.
Prepare the Decision Table from the Cause-Effect Graph drawn.
Convert the Decision Table into Test Cases.

Format of Decision Table:


R1 R2 R3
Conditions
(or Causes)

Actions (or x
Effects) x
x

Format of Test Case Report:


Test Input Input Input Expected Actual Test
Case Id Variable Variable Variable Output Output Result
1 2 3 (Pass/Fail)
CSW442-PR SOFTWARE TESTING WORKSHOP

Part a: Payroll Calculation Program in C++

Unstructured Approach

#include <iostream>
using namespace std;

int main() {
double salary, expenses, tax = 0, surcharge = 0;

cout << "Enter salary: ";


cin >> salary;
cout << "Enter expenses: ";
cin >> expenses;

if (salary <= 70000 && expenses <= 30000) {


tax = salary * 0.10;
cout << "Tax to be paid: " << tax << endl;
}
else if (salary > 70000 && salary <= 200000 && expenses <= 40000) {
tax = salary * 0.20;
cout << "Tax to be paid: " << tax << endl;
}
else if (salary > 200000 && expenses <= 40000) {
tax = salary * 0.20;
surcharge = salary * 0.05;
cout << "Tax to be paid: " << tax + surcharge << endl;
}
else if (salary > 200000 && expenses > 40000) {
tax = salary * 0.20;
surcharge = salary * 0.09;
cout << "Tax to be paid: " << tax + surcharge << endl;
}
else {
cout << "Conditions not met for tax calculation." << endl;
}
CSW442-PR SOFTWARE TESTING WORKSHOP

return 0;
}

Structured Approach (with function)

#include <iostream>
using namespace std;

double calculateTax(double salary, double expenses) {


double tax = 0, surcharge = 0;
if (salary <= 70000 && expenses <= 30000) {
tax = salary * 0.10;
}
else if (salary > 70000 && salary <= 200000 && expenses <= 40000) {
tax = salary * 0.20;
}
else if (salary > 200000) {
tax = salary * 0.20;
if (expenses > 40000)
surcharge = salary * 0.09;
else
surcharge = salary * 0.05;
}
return tax + surcharge;
}

int main() {
double salary, expenses;
cout << "Enter salary: ";
cin >> salary;
cout << "Enter expenses: ";
cin >> expenses;
double totalTax = calculateTax(salary, expenses);
cout << "Tax to be paid: " << totalTax << endl;
return 0;
}
CSW442-PR SOFTWARE TESTING WORKSHOP

Part b: Causes and Effects

Causes:

C1: Salary ≤ 70000

C2: 70000 < Salary ≤ 200000

C3: Salary > 200000

C4: Expenses ≤ 30000

C5: Expenses ≤ 40000

C6: Expenses > 40000

Effects:

E1: 10% tax

E2: 20% tax

E3: 5% surcharge (for salary > 2 lacs and expenses ≤ 40000)

E4: 9% surcharge (if expenses > 40000)


CSW442-PR SOFTWARE TESTING WORKSHOP

Part c: Cause-Effect Graph

The relationships can be described as:

(C1 AND C4) → E1

(C2 AND C5) → E2

(C3 AND C5) → E2 AND E3

(C3 AND C6) → E2 AND E4

(A diagram can be drawn connecting these causes and effects accordingly.)

Part d: Decision Table

Condition/Cause R1 R2 R3 R4

Salary ≤ 70000 X

70000 < Salary ≤ 200000 X

Salary > 200000 X X

Expenses ≤ 30000 X

Expenses ≤ 40000 X X X

Expenses > 40000 X

Tax (10%) X

Tax (20%) X X X

Surcharge (5%) X

Surcharge (9%) X
CSW442-PR SOFTWARE
TESTING WORKSHOP

Part e: Test Cases

Test Case ID Salary (Rs) Expenses (Rs) Expected Tax Calculation

TC1 65000 25000 10% tax = 6500

TC2 150000 30000 20% tax = 30000

TC3 250000 35000 20% tax + 5% surcharge = 62500

TC4 250000 45000 20% tax + 9% surcharge = 70000

You might also like