ST Lab File PDF
ST Lab File PDF
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
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;
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;
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;
int main() {
int 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";
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>
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 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
Source Code: -
#include <bits/stdc++.h>
using namespace std;
class CyclomaticComplexityCalculator {
public:
int calculate(const vector<string>& sourceCode) {
int nodes = 0;
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;
}
};
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
Source Code: -
#include <iostream>
#include <vector>
using namespace std;
int killed = 0;
if (A > B)
if (A > C)
return A;
else
return C;
else
if (C > B)
return C;
else
return B;
return 0;
}
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;
}
if (A > B)
if (A < C)
return A;
else
return C;
else
if (C > B)
return C;
else
return B;
return 0;
}
if (A > B)
if (A > C)
return A;
else
return C;
else
if (C == B)
return C;
else
return B;
return 0;
}
if (A > B)
if (A > C)
return A;
else
return C;
else
if (C > B)
return B;
else
return B;
return 0;
}
if (flag == true)
cout << endl << "Mutant Killed";
else
cout << endl << "Mutant not Killed";
}
if (flag == true)
cout << endl << "Mutant Killed";
else
cout << endl << "Mutant not Killed";
}
if (flag == true)
cout << endl << "Mutant Killed";
else
cout << endl << "Mutant not Killed";
}
if (flag == true)
cout << endl << "Mutant Killed";
else
cout << endl << "Mutant not Killed";
}
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);
return 0;
}
Output: -
Index
2023