0% found this document useful (0 votes)
33 views28 pages

ST Lab File PDF

At lab file for software testing students

Uploaded by

mohitgora1008
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)
33 views28 pages

ST Lab File PDF

At lab file for software testing students

Uploaded by

mohitgora1008
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
You are on page 1/ 28

SOFTWARE TESTING (SE301)

LAB MANUAL
Subject Code: SE301
Subject Name: Software Testing
Branch: Software Engineering
Year: 3rd Year/5th Semester
Submitted by:

MOHIT
2K22/SE/115

Submitted to:
Prof. Ruchika Malhotra
Head of Department
Department of Software Engineering
Delhi Technological University

Delhi Technological University


(Formerly Delhi College of Engineering)
Bawana Road, Delhi-110042
November, 2023

EXPERIMENT - 1

Aim: - Write a program to find the maximum in three numbers input by the user and generate
test cases for the program using Boundary Value Analysis.

Source Code: -
#include <bits/stdc++.h>
using namespace std;
int main(){
cout<<"Enter No. of variables:- ";
int n;
cin>>n;
vector<pair<int,int>> Ranges;
for(int i = 0; i<n; i++){
cout<<"Enter Range:- ";
int a,b;
cin>>a>>b;
Ranges.push_back({a,b});
}
vector<vector<int>> ans;
for(int i = 0; i<n; i++){
vector<int> temp(n);
for(int j = 0; j<4; j++){
for(int k = 0; k<n; k++){
if(i!=k){
temp[k] = (Ranges[k].first+Ranges[k].second)/2;
}
else{
if(j==0) temp[k] = Ranges[i].first;
else if(j==1) temp[k] = Ranges[i].first+1;
else if(j==2) temp[k] = Ranges[i].second-1;
else temp[k] = Ranges[i].second;
}
}
ans.push_back(temp);
}
}
vector<int> temp(n);
for(int i = 0; i<n; i++){
temp[i] = (Ranges[i].first+Ranges[i].second)/2;
}
ans.push_back(temp);
cout<<"S.No."<<" ";
for(int i = 0; i<n; i++){
cout<<" Variable"<<i+1<<" ";
}
cout<<" Output";
cout<<endl;
int tc = 1;
for(auto i:ans){
cout<<setw(5)<<tc;
tc++;
int maxi = INT_MIN;
for(auto j:i){
maxi = max(maxi,j);
cout<<setw(11)<<j;
}
cout<<setw(10)<<maxi;
cout<<endl;
}
}

Output: -
EXPERIMENT - 2

Aim: - Write a program to find the maximum in three numbers input by the user and generate
test cases for the program using Robust Approach.

Source Code: -
#include <bits/stdc++.h>
using namespace std;
int main(){
cout<<"Enter No. of variables:- ";
int n;
cin>>n;
vector<pair<int,int>> Ranges;
for(int i = 0; i<n; i++){
cout<<"Enter Range:- ";
int a,b;
cin>>a>>b;
Ranges.push_back({a,b});
}
vector<vector<int>> ans;
for(int i = 0; i<n; i++){
vector<int> temp(n);
for(int j = 0; j<6; j++){
for(int k = 0; k<n; k++){
if(i!=k){
temp[k] = (Ranges[k].first+Ranges[k].second)/2;
}
else{
if(j==0) temp[k] = Ranges[i].first-1;
else if(j==1) temp[k] = Ranges[i].first;
else if(j==2) temp[k] = Ranges[i].first+1;
else if(j==3) temp[k] = Ranges[i].second-1;
else if(j==4) temp[k] = Ranges[i].second;
else temp[k] = Ranges[i].second+1;
}
}
ans.push_back(temp);
}
}
vector<int> temp(n);
for(int i = 0; i<n; i++){
temp[i] = (Ranges[i].first+Ranges[i].second)/2;
}
ans.push_back(temp);
cout<<"S.No."<<" ";
for(int i = 0; i<n; i++){
cout<<" Variable"<<i+1<<" ";
}
cout<<" Output";
cout<<endl;
int tc = 1;
for(int i = 0; i<ans.size(); i++){
cout<<setw(5)<<tc;
tc++;
int maxi = INT_MIN;
for(auto j:ans[i]){
maxi = max(maxi,j);
cout<<setw(11)<<j;
}
if(i==6*n) cout<<setw(10)<<maxi;
else if(i%(2*n)==0 || i%(2*n)==((2*n)-1)) cout<<" InValid";
else cout<<setw(10)<<maxi;
cout<<endl;
}
}

Output: -
EXPERIMENT - 3

Aim: - Write a program to find the maximum in three numbers input by the user and generate
test cases for the program using Worst Boundary Value.

Source Code: -
#include <bits/stdc++.h>
using namespace std;

void patterns(int i, vector<int>& temp,vector<vector<int>> &cases,vector<vector<int>>&


ans){
if(i==cases.size()){
ans.push_back(temp);
return;
}
for(int j = 0; j<5; j++){
temp.push_back(cases[i][j]);
patterns(i+1,temp,cases,ans);
temp.pop_back();
}
}
int main(){
cout<<"Enter No. of variables:- ";
int n;
cin>>n;
vector<pair<int,int>> Ranges;
for(int i = 0; i<n; i++){
cout<<"Enter Range:- ";
int a,b;
cin>>a>>b;
Ranges.push_back({a,b});
}
vector<vector<int>> cases(n);
for(int i = 0; i<n; i++){
cases[i].push_back(Ranges[i].first);
cases[i].push_back(Ranges[i].first+1);
cases[i].push_back((Ranges[i].first+Ranges[i].second)/2);
cases[i].push_back(Ranges[i].second-1);
cases[i].push_back(Ranges[i].second);
}
vector<int> temp;
vector<vector<int>> ans;
patterns(0,temp,cases,ans);
cout<<"S.No."<<" ";
for(int i = 0; i<n; i++){
cout<<" Variable"<<i+1<<" ";
}
cout<<" Output";
cout<<endl;
int tc = 1;
for(auto i:ans){
cout<<setw(5)<<tc;
tc++;
int maxi = INT_MIN;
for(auto j:i){
maxi = max(maxi,j);
cout<<setw(11)<<j;
}
cout<<setw(10)<<maxi;
cout<<endl;
}
}

Output: -
EXPERIMENT - 4

Aim: - Write a program to find the maximum in three numbers input by the user and generate
test cases for the program using Worst Robust Approach.

Source Code: -
#include <bits/stdc++.h>
using namespace std;

void patterns(int i, vector<int>& temp, vector<vector<int>>& cases, vector<vector<int>>&


ans) {
if (i == cases.size()) {
ans.push_back(temp);
return;
}
for (int j = 0; j < 7; j++) {
temp.push_back(cases[i][j]);
patterns(i + 1, temp, cases, ans);
temp.pop_back();
}
}

int main() {
cout << "Enter No. of variables: ";
int n;
cin >> n;
vector<pair<int, int>> Ranges;
for (int i = 0; i < n; i++) {
cout << "Enter Range: ";
int a, b;
cin >> a >> b;
Ranges.push_back({ a, b });
}
vector<vector<int>> cases(n);
for (int i = 0; i < n; i++) {
cases[i].push_back(Ranges[i].first - 1);
cases[i].push_back(Ranges[i].first);
cases[i].push_back(Ranges[i].first + 1);
cases[i].push_back((Ranges[i].first + Ranges[i].second) / 2);
cases[i].push_back(Ranges[i].second - 1);
cases[i].push_back(Ranges[i].second);
cases[i].push_back(Ranges[i].second + 1);
}
vector<int> temp;
vector<vector<int>> ans;
patterns(0, temp, cases, ans);
cout << "S.No." << " ";
for (int i = 0; i < n; i++) {
cout << "Variable" << i + 1 << " ";
}
cout << "Output" << endl;
int tc = 1;
for (auto i : ans) {
cout << setw(5) << tc;
tc++;
int maxi = INT_MIN;
bool flag = true;
for (int j = 0; j < n; j++) {
if (i[j] > Ranges[j].second || i[j] < Ranges[j].first) {
flag = false;
}
maxi = max(maxi, i[j]);
cout << setw(9) << i[j];
}
if (flag) {
cout << setw(9) << maxi;
}
else {
cout << " INVALID";
}
cout << endl;
}
}

Output: -
EXPERIMENT - 5

Aim: - Write a program to find the type of the triangle on the basis of sides input by the user
and generate test cases to test the using Equivalance Class Testing.

Source Code: -
#include <bits/stdc++.h>
using namespace std;

int num = 1;

void check(int side1, int side2, int side3, int l, int r) {


cout<<setw(3) << num << setw(10) << side1 << setw(10) << side2 << setw(10) << side3 << " ";
num++;
if (side1 < l || side1 > r || side2 < l || side2 > r || side3 < l || side3 > r) cout<< "Invalid Input" << endl;
else if (side1 + side2 <= side3 || side1 + side3 <= side2 || side2 + side3 <= side1) cout<< "Not a triangle" <<
endl;
else {
if (side1 == side2 && side1 == side3) cout<< "Equilateral Triangle" << endl;
else if (side1 == side2 || side2 == side3 || side1 == side3) cout<< "Isosceles Triangle" << endl;
else cout<< "Scalene Triangle" << endl;
}
}

int main() {
int left, right;

cout<< "Enter value range for sides: ";


cin >> left >> right;

map<int, int> m;
m[0] = (left + right) / 2;
m[1] = left - 1;
m[2] = right + 1;

cout<<"<----------Input Classes----------->";
cout<< "I1 = { 1 <= a <= 100, 1 <= b <= 100, 1 <= c <= 100 } (All inputs are valid)\n";
cout<< "I2 = { a < 1, 1 <= b <= 100, 1 <= c <= 100 } (a is invalid, b is valid, c is valid)\n";
cout<< "I3 = { 1 <= a <= 100, b < 1, 1 <= c <= 100 } (a is valid, b is invalid, c is valid)\n";
cout<< "I4 = { 1 <= a <= 100, 1 <= b <= 100, c < 1 } (a is valid, b is valid, c is invalid)\n";
cout<< "I5 = { a > 100, 1 <= b <= 100, 1 <= c <= 100 } (a is invalid, b is valid, c is valid)\n";
cout<< "I6 = { 1 <= a <= 100, b > 100, 1 <= c <= 100 } (a is valid, b is invalid, c is valid)\n";
cout<< "I7 = { 1 <= a <= 100, 1 <= b <= 100, c > 100 } (a is valid, b is valid, c is invalid)\n";
cout<< "I8 = { a < 1, b < 1, 1 <= c <= 100 } (a is invalid, b is invalid, c is valid)\n";
cout<< "I9 = { 1 <= a <= 100, b < 1, c < 1 } (a is valid, b is invalid, c is invalid)\n";
cout<< "I10 = { a < 1, 1 <= b <= 100, c < 1 } (a is invalid, b is valid, c is invalid)\n";
cout<< "I11 = { a > 100, b > 100, 1 <= c <= 100 } (a is invalid, b is invalid, c is valid)\n";
cout<< "I12 = { 1 <= a <= 100, b > 100, c > 100 } (a is valid, b is invalid, c is invalid)\n";
cout<< "I13 = { a > 100, 1 <= b <= 100, c > 100 } (a is invalid, b is valid, c is invalid)\n";
cout<< "I14 = { a < 1, b > 100, 1 <= c <= 100 } (a is invalid, b is invalid, c is valid)\n";
cout<< "I15 = { a > 100, b < 1, 1 <= c <= 100 } (a is invalid, b is invalid, c is valid)\n";
cout<< "I16 = { 1 <= a <= 100, b < 1, c > 100 } (a is valid, b is invalid, c is invalid)\n";
cout<< "I17 = { 1 <= a <= 100, b > 100, c < 1 } (a is valid, b is invalid, c is invalid)\n";
cout<< "I18 = { a < 1, 1 <= b <= 100, c > 100 } (a is invalid, b is valid, c is invalid)\n";
cout<< "I19 = { a > 100, 1 <= b <= 100, c < 1 } (a is invalid, b is valid, c is invalid)\n";
cout<< "I20 = { a < 1, b < 1, c < 1 } (All inputs are invalid)\n";
cout<< "I21 = { a > 100, b > 100, c > 100 } (All inputs are invalid)\n";
cout<< "I22 = { a < 1, b < 1, c > 100 } (All inputs are invalid)\n";
cout<< "I23 = { a < 1, b > 100, c < 1 } (All inputs are invalid)\n";
cout<< "I24 = { a > 100, b < 1, c < 1 } (All inputs are invalid)\n";
cout<< "I25 = { a > 100, b > 100, c < 1 } (All inputs are invalid)\n";
cout<< "I26 = { a > 100, b < 1, c > 100 } (All inputs are invalid)\n";
cout<< "I27 = { a < 1, b > 100, c > 100 } (All inputs are invalid)\n";

cout<< endl<< "<---------Equivalence Input Class----------------->" << endl;


cout<< "CaseID Side1 Side2 Side3 Output" << endl;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
check(m[i], m[j], m[k], left, right);
}
}
}

cout<< endl << "<---------Equivalence Output Class----------------->" << endl;


cout<< "CaseID Side1 Side2 Side3 Output" << endl;
cout<< setw(5) << "O1" << setw(10) << 50 << setw(10) << 50 << setw(10) << 50 << " " << "Equilateral
Triangle" << endl;
cout<< setw(5) << "O2" << setw(10) << 50 << setw(10) << 40 << setw(10) << 50 << " " << "Scalene
Triangle" << endl;
cout<< setw(5) << "O3" << setw(10) << 30 << setw(10) << 40 << setw(10) << 50 << " " << "Isosceles
Triangle" << endl;
cout<< setw(5) << "O4" << setw(10) << 100 << setw(10) << 50 << setw(10) << 50 << " " << "Not a
Triangle" << endl;

return 0;
}
Output: -
EXPERIMENT - 6

Aim: - Write a program to find the type of the triangle on the basis of sides input by the user
and generate test cases to test the program using Decision Table Testing.

Source Code: -
#include <iostream>
#include <vector>

using namespace std;

vector<vector<int>> sides(7, vector<int>(3, 0));


int a, b, c;

string result(int a, int b, int c, vector<vector<int>> arr) {


string ans = "Not a Triangle";
if (a < arr[0][0] || a > arr[0][1] || b < arr[1][0] || b > arr[1][1] || c < arr[2][0] || c > arr[2][1]) {
ans = "Input values are out of range";
} else if (a < b + c && b < a + c && c < a + b) {
if (a == b && b == c) {
ans = "Equilateral Triangle";
} else if (a == b || b == c || a == c) {
ans = "Isosceles Triangle";
} else {
ans = "Scalene Triangle";
}
}
return ans;
}

string Build_DT() {
string str = "\nDECISION TABLE FOR TRIANGLE CLASSIFICATION PROBLEM\n";
str = str + "----------------------------------------------------------------\n";
str = str + "Decisions | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10| 11|\n";
str = str + "----------------------------------------------------------------\n";
str = str + "C1: a < b + c? | F | T | T | T | T | T | T | T | T | T | T |\n";
str = str + "C2: b < a + c? | - | F | T | T | T | T | T | T | T | T | T |\n";
str = str + "C3: c < a + b? | - | - | F | T | T | T | T | T | T | T | T |\n";
str = str + "C4: a = b ? | - | - | - | T | T | T | T | F | F | F | F |\n";
str = str + "C5: a = c ? | - | - | - | T | T | F | F | T | F | F | F |\n";
str = str + "C6: b = c ? | - | - | - | T | F | T | F | F | F | T | F |\n";
str = str + "----------------------------------------------------------------\n";
str = str + "Rule count |32 |16 | 8 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |\n";
str = str + "----------------------------------------------------------------\n";
str = str + "A1: Not a triangle | X | X | X | | | | | | | | |\n";
str = str + "A2: Scalene | | | | | | | | | | | X |\n";
str = str + "A3: Isosceles | | | | | | | X | | X | X | |\n";
str = str + "A4: Equilateral | | | | X | | | | | | | |\n";
str = str + "A5: Impossible | | | | | X | X | | X | | | |\n";
return str;
}

int not_triangle(int ind, vector<vector<int>> arr) {


a = arr[0][1];
b = arr[1][2];
c = arr[2][2];
while (a < (b + c)) {
b = b / 2;
c = c / 2;
}
sides[0][0] = a;
sides[0][1] = b;
sides[0][2] = c;
ind++;
a = arr[0][2];
b = arr[1][1];
c = arr[2][2];
while (b < (a + c)) {
a = a / 2;
c = c / 2;
}
sides[1][0] = a;
sides[1][1] = b;
sides[1][2] = c;
ind++;
a = arr[0][2];
b = arr[1][2];
c = arr[2][1];
while (c < (a + b)) {
a = a / 2;
b = b / 2;
}
sides[2][0] = a;
sides[2][1] = b;
sides[2][2] = c;
ind++;
return ind;
}

int Equilateral(int ind, vector<vector<int>> arr) {


a = arr[0][3];
b = arr[1][3];
c = arr[2][3];
int min_max = arr[0][0], max_min = arr[0][1], nominal_val;
for (int i = 0; i < 3; i++) {
if (min_max > arr[i][0])
min_max = arr[i][0];
if (max_min > arr[i][1])
max_min = arr[i][1];
}
nominal_val = (min_max + max_min) / 2;
sides[ind][0] = nominal_val;
sides[ind][1] = nominal_val;
sides[ind][2] = nominal_val;
ind++;
return ind;
}

int Isosceles(int ind, vector<vector<int>> arr) {


a = arr[0][3];
b = arr[1][3];
c = arr[2][3];
int min_max = arr[0][0], max_min = arr[0][1], nominal_val;
for (int i = 0; i < 3; i++) {
if (min_max > arr[i][0])
min_max = arr[i][0];
if (max_min > arr[i][1])
max_min = arr[i][1];
}
nominal_val = (min_max + max_min) / 2;
sides[ind][0] = arr[0][0];
sides[ind][1] = nominal_val;
sides[ind][2] = nominal_val;
ind++;
sides[ind][0] = nominal_val;
sides[ind][1] = arr[1][0];
sides[ind][2] = nominal_val;
ind++;
sides[ind][0] = nominal_val;
sides[ind][1] = nominal_val;
sides[ind][2] = arr[2][0];
ind++;
return ind;
}

int impossible(int ind) {


for (int i = 0; i < 3; i++) {
cout << ind + i << "\t?\t?\t?\tImpossible" << endl;
}
ind = ind + 3;
return ind;
}

int main() {
vector<vector<int>> arr(3, vector<int>(3, 0));
cout << "Enter the sides of the Triangle:" << endl;
for (int i = 0; i < 3; i++) {
cout << "Enter min and max values of side " << i + 1 << ": ";
cin >> arr[i][0] >> arr[i][1];
arr[i][2] = (arr[i][0] + arr[i][1]) / 2;
arr[i][3] = arr[i][1] - arr[i][0];
}
cout << Build_DT() << endl;
cout << "DECISION TABLE - TEST CASES" << endl;
cout << "S.No\ta\tb\tc\tExpected Output" << endl;
int ind = 0;
ind = not_triangle(ind, arr);
ind = Equilateral(ind, arr);
ind = Isosceles(ind, arr);
ind = 1;
for (int i = 0; i < 7; i++) {
a = sides[i][0];
b = sides[i][1];
c = sides[i][2];
cout << ind << "\t" << a << "\t" << b << "\t" << c << "\t" << result(a, b, c, arr) << endl;
ind++;
}
ind = impossible(ind);
cout << ind << "\t" << arr[0][1] - 1 << "\t" << arr[1][2] << "\t" << arr[2][2] + 2 << "\t" << result(arr[0][1] -
1, arr[1][2], arr[2][2] + 2, arr) << endl;
return 0;
}

Output: -
EXPERIMENT - 7

Aim: - Write a program to find Cyclomatic complexity of a program.

Source Code: -
#include <bits/stdc++.h>
using namespace std;

class CyclomaticComplexityCalculator {
public:
int calculate(const vector<string>& sourceCode) {
int nodes = 0;

for (const string& line : sourceCode) {


nodes+= countDecisiveNodes (line);
}
int complexity = nodes + 1;
return complexity;
}
private:
int countDecisiveNodes(const string& line) {
int controlFlows = 1;
if (line.find("if") != string::npos || line.find("else if") != string::npos)
controlFlows++;
if (line.find("for") != string::npos || line.find("while") != string::npos)
controlFlows++;
if (line.find("case") != string::npos)
controlFlows++;
return controlFlows;
}
};

int main() {
ifstream inputFile("source_code.txt");
if (!inputFile.is_open()) {
cerr << "Failed to open the source_code.txt file." << endl;
return 1;
}
vector<string> sourceCode;
string line;
while (getline(inputFile, line)) {
sourceCode.push_back(line);
}
inputFile.close();
for(auto i:sourceCode){
cout<<i<<endl;
}

CyclomaticComplexityCalculator calculator;
int complexity = calculator.calculate(sourceCode);
cout << "Cyclomatic Complexity: " << complexity << endl;
return 0;
}

Output: -
EXPERIMENT - 8

Aim: - Write a program to input graph matrix and perform DD path testing.

Source Code: -
#include <bits/stdc++.h>
using namespace std;

class Edge {
public:
int wt;
int v;
Edge(int nb, int w) {
v = nb;
wt = w;
}
};

void dfs_printPaths(vector<vector<Edge *>> &graph, int src, vector<bool> &vis, int


endNode, int &count, string path) {
if (src == endNode) {
path += "N" + to_string(endNode);
cout << "Path " << count++ << ": " << path << endl;
return;
}
vis[src] = true;
for (Edge *e : graph[src]) {
if (vis[e->v] == false)
dfs_printPaths(graph, e->v, vis, endNode, count, path + "N" + to_string(src) + " -> ");
}
vis[src] = false;
}

int main() {
int n;
cout << "Enter the number of Decision nodes (Size of Matrix):";
cin >> n;
cout << "Please input the graph matrix:\n";
vector<vector<int>> mat(n, vector<int>(n, 0));
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
cin >> mat[i][j];
vector<vector<Edge *>> graph(n, vector<Edge *>());
int P = 1;
int e = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (mat[i][j] == 1) {
graph[i].push_back(new Edge(j, 1));
e++;
}
vector<bool> vis(n, false);
int count = 1;
cout << "Cyclomatic Complexity is: " << e - n + 2 * P << endl;
cout << "\nPaths are:\n";
dfs_printPaths(graph, 0, vis, n-1, count, "");
cout << endl;
return 0;
}

Output: -
EXPERIMENT - 9

Aim: - Write a program to perform mutation testing.

Source Code: -
#include <iostream>
#include <vector>
using namespace std;

int killed = 0;

int correct(vector<int> testCase) {


int A = testCase[0];
int B = testCase[1];
int C = testCase[2];

if (A > B)
if (A > C)
return A;
else
return C;
else
if (C > B)
return C;
else
return B;

return 0;
}

int M1_Code(vector<int> testCase) {


int A = testCase[0];
int B = testCase[1];
int C = testCase[2];

if (A < B)
if (A > C)
return A;
else
return C;
else
if (C > B)
return C;
else
return B;

return 0;
}
int M2_Code(vector<int> testCase) {
int A = testCase[0];
int B = testCase[1];
int C = testCase[2];

if (A > (B + C))
if (A > C)
return A;
else
return C;
else
if (C > B)
return C;
else
return B;

return 0;
}

int M3_Code(vector<int> testCase) {


int A = testCase[0];
int B = testCase[1];
int C = testCase[2];

if (A > B)
if (A < C)
return A;
else
return C;
else
if (C > B)
return C;
else
return B;

return 0;
}

int M4_Code(vector<int> testCase) {


int A = testCase[0];
int B = testCase[1];
int C = testCase[2];

if (A > B)
if (A > C)
return A;
else
return C;
else
if (C == B)
return C;
else
return B;

return 0;
}

int M5_Code(vector<int> testCase) {


int A = testCase[0];
int B = testCase[1];
int C = testCase[2];

if (A > B)
if (A > C)
return A;
else
return C;
else
if (C > B)
return B;
else
return B;

return 0;
}

void M1(vector<vector<int>> testCases) {


cout << endl << endl << "---------------------------------------------------- ---- ----------------------
----\n";
cout << " Mutant 1" << endl;
cout << "\t\t A\tB\tC\tExpected\t Actual" << endl;

bool flag = false;


for (int i = 0; i < testCases.size(); i++) {
cout << "Test Case " << i + 1 << " \t " << testCases[i][0] << "\t" << testCases[i][1] <<
"\t" << testCases[i][2] << "\t " << correct(testCases[i]) << "\t\t" << M1_Code(testCases[i]) <<
endl;
if (correct(testCases[i]) != M1_Code(testCases[i]) && flag == false) {
killed++;
flag = true;
}
}

if (flag == true)
cout << endl << "Mutant Killed";
else
cout << endl << "Mutant not Killed";
}

void M2(vector<vector<int>> testCases) {


cout << endl << endl << "----------------------------------------------------- --------------------------
\n";
cout << " Mutant 2" << endl;
cout << "\t\t A\tB\tC\tExpected\t Actual" << endl;

bool flag = false;


for (int i = 0; i < testCases.size(); i++) {
cout << "Test Case " << i + 1 << " \t " << testCases[i][0] << "\t" << testCases[i][1] <<
"\t" << testCases[i][2] << "\t " << correct(testCases[i]) << "\t\t" << M2_Code(testCases[i]) <<
endl;
if (correct(testCases[i]) != M2_Code(testCases[i]) && flag == false) {
killed++;
flag = true;
}
}

if (flag == true)
cout << endl << "Mutant Killed";
else
cout << endl << "Mutant not Killed";
}

void M3(vector<vector<int>> testCases) {


cout << endl << endl << "----------------------------------------------------- --------------------------
\n";
cout << " Mutant 3" << endl;
cout << "\t\t A\tB\tC\tExpected\t Actual" << endl;

bool flag = false;


for (int i = 0; i < testCases.size(); i++) {
cout << "Test Case " << i + 1 << " \t " << testCases[i][0] << "\t" << testCases[i][1] <<
"\t" << testCases[i][2] << "\t " << correct(testCases[i]) << "\t\t" << M3_Code(testCases[i]) <<
endl;
if (correct(testCases[i]) != M3_Code(testCases[i]) && flag == false) {
killed++;
flag = true;
}
}

if (flag == true)
cout << endl << "Mutant Killed";
else
cout << endl << "Mutant not Killed";
}

void M4(vector<vector<int>> testCases) {


cout << endl << endl << "---------------------------------------------------- ---- ----------------------
----\n";
cout << " Mutant 4" << endl;
cout << "\t\t A\tB\tC\tExpected\t Actual" << endl;
bool flag = false;
for (int i = 0; i < testCases.size(); i++) {
cout << "Test Case " << i + 1 << " \t " << testCases[i][0] << "\t" << testCases[i][1] <<
"\t" << testCases[i][2] << "\t " << correct(testCases[i]) << "\t\t" << M4_Code(testCases[i]) <<
endl;
if (correct(testCases[i]) != M4_Code(testCases[i]) && flag == false) {
killed++;
flag = true;
}
}

if (flag == true)
cout << endl << "Mutant Killed";
else
cout << endl << "Mutant not Killed";
}

void M5(vector<vector<int>> testCases) {


cout << endl << endl << "----------------------------------------------------- --------------------------
\n";
cout << " Mutant 5" << endl;
cout << "\t\t A\tB\tC\tExpected\t Actual" << endl;

bool flag = false;


for (int i = 0; i < testCases.size(); i++) {
cout << "Test Case " << i + 1 << " \t " << testCases[i][0] << "\t" << testCases[i][1] <<
"\t" << testCases[i][2] << "\t " << correct(testCases[i]) << "\t\t" << M5_Code(testCases[i]) <<
endl;
if (correct(testCases[i]) != M5_Code(testCases[i]) && flag == false) {
killed++;
flag = true;
}
}

if (flag == true)
cout << endl << "Mutant Killed";
else
cout << endl << "Mutant not Killed";
}

int main() {
cout << endl << endl << "---------------------------------------------------- ---- ----------------------
----\n";
cout << " MUTATION TESTING" << endl;
cout << "Enter number of test cases:";
int N;
cin >> N;
vector<vector<int>> testCases(N, vector<int>(3, 0));
for (int i = 0; i < N; i++) {
cout << "Enter test case " << i + 1 << " : ";
cin >> testCases[i][0] >> testCases[i][1] >> testCases[i][2];
}

M1(testCases);
M2(testCases);
M3(testCases);
M4(testCases);
M5(testCases);

cout << endl << endl << "---------------------------------------------------- ---- ----------------------


----\n";
cout << " MUTATION SCORE" << endl;
cout << "Total Mutants: " << 5 << endl;
cout << "Mutants Killed: " << killed << endl;
cout << "Mutation Score: " << killed / 5.0 << endl;

return 0;
}
Output: -
Index

S.No Experiment Name Date Teacher Remarks


Sign
1. Write a program to find the largest among three 18 Aug
numbers and generate test cases using boundary 2023
value analysis.
2. Write a program to find the largest among three 25 Aug
numbers and generate test cases using Robust Test 2023
Case Approach.
3. Write a program to find the largest among three 1 Sep
numbers and generate test cases using Worst Test 2023
Case Approach.
4. Write a program to find the largest among three 15 Sep
numbers and generate test cases using Worst Robust 2023
Test Case Approach.
5. Write a program to find the Triangle types on the 22 Sep
basis of the input sides given and generate test cases 2023
using Equivalence Class Testing.
6. Write a program to find the Triangle types on the 6 Oct
basis of the input sides given and generate test cases 2023
using Decision Table Testing.
7. Write a program to find the Cyclomatic Complexity 13 Oct
of a program. 2023

8. Some Software Requirement Engineering Tool 20 Oct


2023

9. Write a program to program to perform Mutation 27 Oct


Testing.
2023

10. Perform Web Testing on Real Estate Website 3 Nov

2023

You might also like