0% found this document useful (0 votes)
21 views

Tasbiya ST FileHHHHH

Uploaded by

tasbiyakumail
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)
21 views

Tasbiya ST FileHHHHH

Uploaded by

tasbiyakumail
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/ 49

INDIRA GANDHI DELHI

TECHNICAL UNIVERSITY FOR


WOMEN

SOFTWARE TESTING FILE

Submitted By:
Tasbiya
03301032021
IT-1(G-group)
Submitted To:
Dr. Pratibha
INDEX

S.NO TOPIC DATE SIGNATURE


1. Verify date format by using various test cases
Design a program to determine roots of quadratic equation
2.
ax^2
+ bx + c. If roots are real, equal or imaginary. Also check if it's
a quadratic equation or not. (Range of values: 0 to 100)

3. Comparative study of software testing tools

4. Write a program to test add/subtraction of 2*2 matrix

5. To generate test cases using adhoc testing

6. To understand black box testing and generate test cases using


boundary value analysis

7. To understand robustness testing techniques and generate test


cases for addition/ subtraction of 2d matrix
To understand worst case testing and robust worst case
8.
technique and generate test cases for addition/subtraction of 2d
matrix

9. To understand equivalence class testing and identify input and


output based equivalence classes for 2d matrix and generate
test cases using it

10. To understand decision table based testing and generate test


cases using limited entry decision tables and extended entry
decision tables.

11. To understand mutation testing and generate test cases for


addition/subtraction for 2d matrix.

12. To understand slicing testing and generate test cases for


addition/subtraction for 2d matrix.
EXPERIMENT 1
Aim:
Write a program to verify if the given date is valid considering leap years and proper
day/month ranges.

C++ Code:

#include <iostream>
using namespace std;

// Function to check if year is a leap year


bool isLeapYear(int year) {
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
{ return true;
}
return false;
}

// Function to validate date


bool isValidDate(int day, int month, int year) {
if (year < 0 || month < 1 || month > 12 || day < 1)
{ return false;
}

int daysInMonth[] = {31, (isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31,
30, 31};

if (day > daysInMonth[month - 1])


{ return false;
}

return true;
}

int main() {
int day, month, year;
cout << "Enter day, month, and year (DD MM YYYY): ";
cin >> day >> month >> year;

if (isValidDate(day, month, year)) {


cout << "The date is valid!" << endl;
} else {
cout << "The date is invalid!" << endl;
}

return 0;
}

Output:
EXPERIMENT 2
Aim:
Write a program to solve quadratic equations and find their roots.

C++ Code:

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

void solveQuadratic(int a, int b, int c)


{ int discriminant = b * b - 4 * a * c;

if (discriminant > 0) {
double root1 = (-b + sqrt(discriminant)) / (2 *
a); double root2 = (-b - sqrt(discriminant)) / (2 *
a);
cout << "Two distinct real roots: " << root1 << " and " << root2 << endl;
} else if (discriminant == 0)
{ double root = -b / (2 * a);
cout << "One real root: " << root << endl;
} else {
double realPart = -b / (2 * a);
double imaginaryPart = sqrt(-discriminant) / (2 * a);
cout << "Complex roots: " << realPart << " + " << imaginaryPart << "i and "
<< realPart << " - " << imaginaryPart << "i" << endl;
}
}

int main() {
int a, b,
c;
cout << "Enter coefficients a, b, and c: ";
cin >> a >> b >> c;

solveQuadratic(a, b, c);

return 0;
}
Output:
EXPERIMENT 3
Aim: Document various software testing tools used in the industry (e.g., Selenium,
Postman, JMeter). Describe their use cases and functionalities.

1. Selenium

- Purpose: Used for automating testing of websites.

- How It Works:

- Selenium is open-source, meaning anyone can use and modify it freely.

- It automates web applications by simulating actions like clicking buttons and


filling forms.

- Selenium supports various programming languages like Java, Python, and C#


for writing tests.

- It works with popular browsers such as Chrome, Firefox, and Safari.

- Selenium WebDriver, a key part of Selenium, is commonly used for testing


websites that change often.

- Ideal For: Repeated (regression) tests and checking the functionality of websites.

2. Postman

- Purpose: Used for testing APIs (Application Programming Interfaces).

- How It Works:

- Postman allows users to send different types of requests (GET, POST, PUT,
DELETE) to test if an API is working as expected.

- It offers an interface for manually testing APIs and for creating automated
test collections.

- Postman is great for checking if an API returns the right data and performs well.

- It supports integration into automated workflows, making it suitable for


continuous testing.

- Ideal For: Ensuring APIs return the correct data and function as expected.
3. JMeter

- Purpose: Used for testing the load and performance of web applications and APIs.

- How It Works:

- JMeter is an open-source tool that checks how well an application can handle
multiple users at once.

- It can be used to simulate real user interactions and measure performance metrics
like response time.

- JMeter is useful for understanding how an application behaves under heavy use.

- It also works well in automated CI/CD (Continuous


Integration/Continuous Deployment) setups for regular performance checks.

- Ideal For: Stress and load testing to find performance limits.

4. QTest

- Purpose: Test management for teams.

- How It Works:

- QTest is a cloud tool that helps teams organize test cases, track bugs, and manage
test plans.

- It integrates well with development tools like JIRA and Jenkins, which are often used
in agile (fast-paced) environments.

- QTest lets teams store test results, track testing progress, and generate reports
for stakeholders.

- Ideal For: Organizing and managing test processes in agile teams.

5. Katalon Studio

- Purpose: Automates testing for web, mobile, and API applications.

- How It Works:
- Katalon Studio is an all-in-one testing tool with built-in templates to make test
creation easy.

- It supports automation for websites, mobile apps, desktop apps, and APIs.

- Katalon Studio integrates with DevOps tools like JIRA and Jenkins, making it
suitable for agile workflows.

- **Ideal For**: Beginners in automation and teams needing a versatile, easy-to-


use testing tool.

6. Appium

- Purpose: Used for automating tests for mobile applications.

- How It Works:

- Appium supports testing mobile apps on both Android and iOS platforms using a
single test code.

- It allows testing on both real devices and emulators.

- Appium uses WebDriver for automation, and it works with various


programming languages.

- Ideal For: Automating functional and regression tests on mobile apps.

7. TestNG

- Purpose: Provides a framework for organizing and running tests in an automated way.

- How It Works:

- Inspired by JUnit, TestNG allows testers to create a wide range of tests (unit,
functional, and integration).

- It integrates with Selenium, and can handle multiple tests running at once.

- TestNG uses annotations to organize tests and supports grouping and parallel execution.

- Ideal For: Structuring and organizing test cases, especially in Selenium projects.
8. LoadRunner

- Purpose: Used for performance and load testing to simulate high usage.

- How It Works:

- LoadRunner creates virtual users to test how an application handles a large number
of users or heavy data.

- It provides insights into system performance, like response times and resource
use, helping identify weak points.

- Ideal For: Checking if an application can handle high traffic and


identifying performance issues.

9. JIRA

- Purpose: Manages project tasks and tracks bugs.

- How It Works:

- JIRA is widely used for tracking bugs and assigning tasks to team members.

- It integrates with tools like Selenium and TestNG, supporting project management
in agile workflows.

- JIRA provides insights into project progress and issue resolution.

- Ideal For: Managing projects and tracking software issues in development teams.

Result

Each of these tools has a specific role, from automating web tests (Selenium) and testing
APIs (Postman) to managing projects (JIRA) and measuring performance (LoadRunner).
Together, they help ensure software quality by covering different aspects of testing and
bug tracking.
EXPERIMENT -4
Aim:
Write a program to add and subtract two matrices of size 2x2.

Code:

#include <iostream>

#include <cstdlib> // For rand() and srand()

#include <ctime> // For time()

using namespace std;

// Function to generate random matrices and test

cases void generateMatrixTestCases(int

numberOfTests) {

srand(time(0)); // Seed the random number generator

for (int test = 1; test <= numberOfTests; test++)

{ int matA[2][2], matB[2][2], result[2][2];

// Generate random elements for matrices A and B

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

for (int j = 0; j < 2; j++) {

matA[i][j] = rand() % 21 - 10; // Random values between -10 and 10

matB[i][j] = rand() % 21 - 10;

}
}

// Display generated matrices

cout << "Test Case " << test << ": " <<

endl; cout << "Matrix A: " << endl;

for (int i = 0; i < 2; i++)

{ for (int j = 0; j < 2; j++)

cout << matA[i][j] << " ";

cout << endl;

cout << "Matrix B: " << endl;

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

for (int j = 0; j < 2; j++)

{ cout << matB[i][j] << "

";

cout << endl;

// Perform addition of matrices

cout << "Matrix after Addition: " << endl;

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

for (int j = 0; j < 2; j++) {

result[i][j] = matA[i][j] + matB[i][j];


cout << result[i][j] << " ";

cout << endl;

// Perform subtraction of matrices

cout << "Matrix after Subtraction: " <<

endl; for (int i = 0; i < 2; i++) {

for (int j = 0; j < 2; j++) {

result[i][j] = matA[i][j] - matB[i][j];

cout << result[i][j] << " ";

cout << endl;

cout << " " << endl;

int main() {

int numberOfTests;

cout << "Enter the number of test cases you want to generate: ";

cin >> numberOfTests;

generateMatrixTestCases(numberOfTests);
return 0;

Output:
Matrix after Subtraction:
7 -15
-8 8

A:
6 -2
-9 4

B:
1 3

7 -6

-2 -2

Matrix after Subtraction:


5 -5
-16
10
EXPERIMENT - 5
Aim: Perform ad-hoc testing on a calculator and generate test cases to identify potential
issues.

CODE:

#include <iostream>

#include <cstdlib> // For rand() and srand()

#include <ctime> // For time()

using namespace std;

// Function to generate random test cases

void generateTestCases(int numberOfTests)

{ srand(time(0)); // Seed the random number generator

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

int a = rand() % 100 - 50; // Generate random number between -50 and 50

int b = rand() % 100 - 50; // Generate random number between -50 and

50

int operation = rand() % 4 + 1; // Random operation choice: 1 for add, 2 for


subtract, 3 for multiply, 4 for divide

cout << "Test Case " << i << ": " << endl;

cout << "Inputs: a = " << a << ", b = " << b << endl;

switch (operation) {

case 1:
cout << "Operation: Addition" << endl;

cout << "Expected Output: " << a + b << endl;

break;

case 2:

cout << "Operation: Subtraction" << endl;

cout << "Expected Output: " << a - b << endl;

break;

case 3:

cout << "Operation: Multiplication" << endl;

cout << "Expected Output: " << a * b <<

endl; break;

case 4:

cout << "Operation: Division" << endl;

if (b != 0)

cout << "Expected Output: " << a / b << endl;

else

cout << "Expected Output: Division by zero error!" << endl;

break;

cout << " " << endl;

int main() {
int numberOfTests;

cout << "Enter the number of test cases you want to generate: ";

cin >> numberOfTests;

generateTestCases(numberOfTests);

return 0;

Output:
EXPERIMENT- 6
Aim: To understand black box testing and generate test cases using boundary value
analysis.

Code:

#include <iostream>

#include <limits> // For INT_MIN and INT_MAX

using namespace std;

class BankAccount {

private:

int balance;

public:

// Constructor with an initial balance

BankAccount(int initialBalance) : balance(initialBalance) {}

// Setter to update the balance, simulating a deposit or withdrawal

void setBalance(int newBalance) {

balance = newBalance;

// Getter to retrieve the

balance int getBalance() const

return balance;

// Display the balance

void displayBalance() const {

cout << "Current Balance: " << balance << endl;


}

// Boundary Value Analysis Test

Cases static void

runBoundaryValueTests() {

cout << "\n### Boundary Value Analysis Tests ###\n";

// Define minimum and maximum boundary values for balance

int minBalance = 0;

int maxBalance = 10000;

// Test Case 1: Minimum boundary value

cout << "\nTest Case 1 - Minimum Boundary Value (" << minBalance << "):\n";

BankAccount account1(minBalance);

account1.displayBalance();

// Test Case 2: Just above the minimum boundary

cout << "\nTest Case 2 - Just Above Minimum Boundary (" << minBalance + 1 <<
"):\n";

BankAccount account2(minBalance + 1);

account2.displayBalance();

// Test Case 3: Nominal (Middle) value

int nominalBalance = (minBalance + maxBalance) / 2;

cout << "\nTest Case 3 - Nominal Value (Middle of Range, " << nominalBalance
<< "):\n";

BankAccount account3(nominalBalance);

account3.displayBalance();

// Test Case 4: Just below the maximum boundary

cout << "\nTest Case 4 - Just Below Maximum Boundary (" << maxBalance - 1 <<
"):\n";

BankAccount account4(maxBalance - 1);


account4.displayBalance();

// Test Case 5: Maximum boundary value

cout << "\nTest Case 5 - Maximum Boundary Value (" << maxBalance << "):\n";

BankAccount account5(maxBalance);

account5.displayBalance();

};

int main() {

cout << "Running Boundary Value Analysis Test Cases...\n";

BankAccount::runBoundaryValueTests();

return 0;

Output:
Current Balance: 9999

:
EXPERIMENT – 7
Aim: To understand robustness testing techniques and generate test cases for addition/
subtraction of 2d matrix.

Code:

#include <iostream>

#include <climits> // For INT_MAX and INT_MIN

using namespace std;

class Matrix

{ private:

int data[2][2]; // 2x2 matrix

public:

// Constructor to initialize the matrix

Matrix(int a = 0, int b = 0, int c = 0, int d = 0)

data[0][0] = a;

data[0][1] = b;

data[1][0] = c;

data[1][1] = d;

// Function to display the matrix

void display() const {

for (int i = 0; i < 2; i++)

{ for (int j = 0; j < 2; j++)

cout << data[i][j] << " ";

cout << endl;

}
}

// Function to add two matrices

Matrix add(const Matrix& other) const

{ return Matrix(

data[0][0] + other.data[0][0], data[0][1] + other.data[0][1],

data[1][0] + other.data[1][0], data[1][1] + other.data[1][1]

);

// Function to subtract two matrices

Matrix subtract(const Matrix& other) const

{ return Matrix(

data[0][0] - other.data[0][0], data[0][1] - other.data[0][1],

data[1][0] - other.data[1][0], data[1][1] - other.data[1][1]

);

// Function to run robustness test cases

static void runRobustnessTests() {

int testValues[] = {INT_MIN, INT_MAX, 0, INT_MIN + 1, INT_MAX - 1, INT_MIN - 1,


INT_MAX + 1};

Matrix mat2(0, 0, 0, 0); // Second matrix with all zero values

for (int testCase = 0; testCase < 7; testCase++) {

Matrix mat1(testValues[testCase], 0, 0, 0); // Set mat1[0][0] to one of the test values

cout << "\nTest Case " << testCase + 1 << " - mat1[0][0] = " << mat1.data[0][0] << ":\n";

cout << "Matrix 1:\n";

mat1.display();

cout << "Matrix 2:\n";

mat2.display();
// Perform addition

Matrix sum = mat1.add(mat2);

cout << "Sum:\n"; sum.display();

// Perform subtraction

Matrix diff = mat1.subtract(mat2);

cout << "Difference:\n"; diff.display();

};

int main() {

cout << "Running Robustness Test Cases for Matrix Operations...\n";

Matrix::runRobustnessTests();

return 0;

Output:
Test 2 - mat1[0][0] = 2147483647:
Case
Matrix 1: 0
2147483647
0 0

Matrix 2:
0 0

0 0

Sum:
2147483647
0
0 0
Difference:
2147483647
0
0 0

Test 7 - mat1[0][0] = 2147483648:


Case
Matrix
2147483648 0
1:
0 0

Matrix 2:
0 0

0 0

Sum:
2147483648 0
0 0
Difference :
2147483648 0
0 0
EXPERIMENT – 8
Aim: To understand worst case testing and robust worst case technique and generate test cases
for addition/subtraction of 2d matrix.

Code:

#include <iostream>

#include <climits> // For INT_MAX and INT_MIN

using namespace std;

class Matrix

{ private:

int data[2][2]; // 2x2 matrix

public:

// Constructor to initialize the matrix

Matrix(int a = 0, int b = 0, int c = 0, int d = 0)

data[0][0] = a;

data[0][1] = b;

data[1][0] = c;

data[1][1] = d;

// Function to display the matrix

void display() const {

for (int i = 0; i < 2; i++)

{ for (int j = 0; j < 2; j++)

cout << data[i][j] << " ";

cout << endl;

}
}

// Function to add two matrices

Matrix add(const Matrix& other) const

{ return Matrix(

data[0][0] + other.data[0][0], data[0][1] + other.data[0][1],

data[1][0] + other.data[1][0], data[1][1] + other.data[1][1]

);

// Function to subtract two matrices

Matrix subtract(const Matrix& other) const

{ return Matrix(

data[0][0] - other.data[0][0], data[0][1] - other.data[0][1],

data[1][0] - other.data[1][0], data[1][1] - other.data[1][1]

);

// Function to run Worst Case and Robust Worst Case test cases

static void runWorstCaseTests() {

// Worst Case Test Case - INT_MIN, INT_MAX, overflow and underflow

int testValues[] = {INT_MIN, INT_MAX, 0, INT_MIN + 1, INT_MAX - 1, INT_MIN - 1,


INT_MAX + 1};

// Matrix with nominal values

Matrix mat2(0, 0, 0, 0); // Second matrix with all zero values

// Worst Case Testing: Combining extreme values like INT_MIN, INT_MAX

for (int testCase = 0; testCase < 7; testCase++) {

Matrix mat1(testValues[testCase], testValues[testCase], testValues[testCase],


testValues[testCase]);

cout << "\nWorst Case Test Case " << testCase + 1 << " - mat1[0][0] = " << mat1.data[0]
[0] << ":\n";
cout << "Matrix 1:\n";

mat1.display();

cout << "Matrix 2 (Zero Matrix):\n";

mat2.display();

// Perform addition

Matrix sum = mat1.add(mat2);

cout << "Sum:\n"; sum.display();

// Perform subtraction

Matrix diff = mat1.subtract(mat2);

cout << "Difference:\n"; diff.display();

// Function to run Robust Worst Case tests (overflow and underflow with addition/subtraction)

static void runRobustWorstCaseTests() {

// Robust Worst Case Testing: This focuses on boundary conditions that could trigger
overflow/underflow

int testValues[] = {INT_MIN, INT_MAX, INT_MIN + 1, INT_MAX - 1, INT_MIN - 1,


INT_MAX + 1};

// Matrix with extreme values

Matrix mat2(INT_MAX, INT_MIN, INT_MIN, INT_MAX); // Matrix with extreme values

for (int testCase = 0; testCase < 6; testCase++) {

// Set mat1 to extreme test case values

Matrix mat1(testValues[testCase], testValues[testCase], testValues[testCase],


testValues[testCase]);

cout << "\nRobust Worst Case Test Case " << testCase + 1 << " - mat1[0][0] = " <<
mat1.data[0][0] << ":\n";

cout << "Matrix 1:\n";

mat1.display();
cout << "Matrix 2 (Extreme Values):\n";

mat2.display();

// Perform addition

Matrix sum = mat1.add(mat2);

cout << "Sum:\n"; sum.display();

// Perform subtraction

Matrix diff = mat1.subtract(mat2);

cout << "Difference:\n"; diff.display();

};

int main() {

cout << "Running Worst Case Test Cases for Matrix Operations...\n";

Matrix::runWorstCaseTests();

cout << "\nRunning Robust Worst Case Test Cases for Matrix Operations...\n";

Matrix::runRobustWorstCaseTests();

return 0;

Output:
a rix
2147483648 2147483648
2147483648 2147483648

2147483647 -2147483648
-2147483648 2147483647
Sum:
4294967295 -2147483648
-2147483648 4294967295
Difference:
2147483647 -2147483648
-2147483648 2147483647

-2147483649 -2147483649
-2147483649 -2147483649

2147483647 -2147483648
-2147483648 2147483647
Sum:
2147483648 -2147483648
-2147483648 2147483648
Difference:
-2147483650 -2147483649
-2147483649 -2147483650
EXPERIMENT – 9
Aim: To understand equivalence class testing and identify input and output based equivalence
classes for 2d matrix and generate test cases using it.

Code:

#include <iostream>

#include <vector>

#include <stdexcept>

using namespace std;

class Matrix {

private:

vector<vector<int>> data;

public:

// Constructor to initialize matrix with given values

Matrix(const vector<vector<int>>& input) : data(input) {}

// Function to get the size of the matrix (rows and columns)

pair<size_t, size_t> getSize() const {

return {data.size(), data.empty() ? 0 : data[0].size()};

// Function to add another matrix to the current matrix

Matrix add(const Matrix& other) const {

// Check if the matrices have the same

size auto [rows1, cols1] = this->getSize();

auto [rows2, cols2] = other.getSize();

if (rows1 != rows2 || cols1 != cols2) {

throw invalid_argument("Matrices must be of the same size for addition.");


}

vector<vector<int>> result(rows1, vector<int>(cols1, 0));

for (size_t i = 0; i < rows1; ++i) {

for (size_t j = 0; j < cols1; ++j) {

result[i][j] = this->data[i][j] + other.data[i][j];

return Matrix(result); // Return the resulting matrix

// Function to print the matrix

void print() const {

for (const auto& row : data)

{ for (const auto& val : row)

cout << val << " ";

cout << endl;

};

// Main function to run the test

cases int main() {

// Test cases for equivalence class testing

// 1. Strong Normal: All combinations of valid inputs

try {

cout << "Strong Normal Test Case:" << endl;

Matrix matrix1({{1, 2}, {3, 4}});


Matrix matrix2({{5, 6}, {7, 8}});

auto result = matrix1.add(matrix2);

result.print();

} catch (const exception& e) {

cout << e.what() << endl;

// 2. Weak Normal: At least one valid value from each equivalence

class try {

cout << "Weak Normal Test Case:" <<

endl; Matrix matrix1({{4, 5}, {6, 7}});

Matrix matrix2({{0, 0}, {0, 0}});

auto result =

matrix1.add(matrix2);

result.print();

} catch (const exception& e) {

cout << e.what() << endl;

// 3. Strong Robust: All combinations of valid and invalid

inputs try {

cout << "Strong Robust Test Case (invalid sizes):" << endl;

Matrix matrix1({{1, 2}, {3, 4}});

Matrix matrix2({{1, 2}});

auto result = matrix1.add(matrix2); // This should throw an

exception result.print();

} catch (const exception& e) {

cout << e.what() << endl;

}
// 4. Weak Robust: At least one invalid input

try {

cout << "Weak Robust Test Case (empty matrix):" << endl;

Matrix matrix1({{1, 2}, {3, 4}});

Matrix matrix2({}); // Empty matrix

auto result = matrix1.add(matrix2); // This should throw an

exception result.print();

} catch (const exception& e)

{ cout << e.what() << endl;

return 0;

Output:
EXPERIMENT-10
Aim- To understand decision table based testing and generate test cases using limited
entry decision tables and extended entry decision tables.

CODE:

#include <iostream>

#include <vector>

#include <string>

using namespace std;

// Define a structure for a rule

struct Rule {

vector<bool> conditions; // Conditions (true or false for limited

entry) string action; // Action to perform if rule matches

};

// Function to match a rule based on conditions

bool matchRule(const vector<bool>& conditions, const Rule& rule) {

for (size_t i = 0; i < conditions.size(); i++) {

if (conditions[i] != rule.conditions[i])

{ return false;

return true;
}

// Function to create limited entry decision table rules

vector<Rule> createLimitedEntryDecisionTable() {

return {

{{true, true}, "Action 1"},

{{true, false}, "Action 2"},

{{false, true}, "Action 3"},

{{false, false}, "Action 4"}

};

// Function to create extended entry decision table rules

vector<Rule> createExtendedEntryDecisionTable() {

return {

{{true, false, false}, "Action 1"},

{{true, true, false}, "Action 2"},

{{false, true, true}, "Action 3"},

{{false, false, true}, "Action 4"}

};

// Function to run test cases

void testCases(const vector<Rule>& rules, const vector<vector<bool>>& testConditions)


{
for (const auto& conditions : testConditions) {

bool foundMatch = false;

for (const auto& rule : rules) {

if (matchRule(conditions, rule)) {

cout << "Conditions: ";

for (bool cond : conditions) cout << cond << " ";

cout << "=> " << rule.action << endl;

foundMatch = true;

break;

if (!foundMatch) {

cout << "Conditions: ";

for (bool cond : conditions) cout << cond << " ";

cout << "=> No matching action found" << endl;

int main() {

// Limited entry decision table testing

cout << "Limited Entry Decision Table:\n";

vector<Rule> limitedTable = createLimitedEntryDecisionTable();

vector<vector<bool>> limitedTestCases = {{true, true}, {true, false}, {false, true},


{false, false}};
testCases(limitedTable, limitedTestCases);

cout << "\nExtended Entry Decision Table:\n";

vector<Rule> extendedTable = createExtendedEntryDecisionTable();

vector<vector<bool>> extendedTestCases = {{true, false, false}, {true, true, false},


{false, true, true}, {false, false, true}};

testCases(extendedTable, extendedTestCases);

return 0;

Output:
EXPERIMENT-11
Aim: To understand mutation testing and generate test cases for addition/subtraction for
2d matrix.

Code:

#include <iostream>

#include <vector>

#include <stdexcept>

using namespace std;

// Define a matrix as a vector of vectors

typedef vector<vector<int>> Matrix;

// Function for matrix addition

Matrix matrixAddition(const Matrix& matA, const Matrix& matB)

{ int rows = matA.size();

int cols = matA[0].size();

Matrix result(rows, vector<int>(cols));

for (int i = 0; i < rows; ++i)

{ for (int j = 0; j < cols; +

+j) {

result[i][j] = matA[i][j] + matB[i][j];

return result;
}

// Mutant version of matrix addition (uses subtraction instead of addition)

Matrix mutantMatrixAddition(const Matrix& matA, const Matrix& matB) {

int rows = matA.size();

int cols = matA[0].size();

Matrix result(rows, vector<int>(cols));

for (int i = 0; i < rows; ++i)

{ for (int j = 0; j < cols; +

+j) {

result[i][j] = matA[i][j] - matB[i][j]; // Mutation: subtraction instead of addition

return result;

// Function for matrix subtraction

Matrix matrixSubtraction(const Matrix& matA, const Matrix& matB)

{ int rows = matA.size();

int cols = matA[0].size();

Matrix result(rows, vector<int>(cols));

for (int i = 0; i < rows; ++i)

{ for (int j = 0; j < cols; +

+j) {

result[i][j] = matA[i][j] - matB[i][j];


}

return result;

// Mutant version of matrix subtraction (uses addition instead of subtraction)

Matrix mutantMatrixSubtraction(const Matrix& matA, const Matrix& matB) {

int rows = matA.size();

int cols = matA[0].size();

Matrix result(rows, vector<int>(cols));

for (int i = 0; i < rows; ++i)

{ for (int j = 0; j < cols; +

+j) {

result[i][j] = matA[i][j] + matB[i][j]; // Mutation: addition instead of subtraction

return result;

// Function to display the matrix

void displayMatrix(const Matrix& mat)

{ for (const auto& row : mat) {

for (int val : row)

{ cout << val << "

";

}
cout << endl;

// Test cases to validate the correctness of addition and subtraction

void testMatrixOperations() {

Matrix matA = {{1, 2}, {3, 4}};

Matrix matB = {{5, 6}, {7, 8}};

// Expected results

Matrix expectedAddition = {{6, 8}, {10, 12}};

Matrix expectedSubtraction = {{-4, -4}, {-4, -4}};

// Testing correct addition

cout << "Testing Matrix Addition:\n";

Matrix resultAdd = matrixAddition(matA, matB);

if (resultAdd == expectedAddition) {

cout << "Addition test passed!\n";

} else {

cout << "Addition test failed!\n";

displayMatrix(resultAdd);

// Testing correct subtraction

cout << "\nTesting Matrix Subtraction:\n";


Matrix resultSub = matrixSubtraction(matA, matB);

if (resultSub == expectedSubtraction) {

cout << "Subtraction test passed!\n";

} else {

cout << "Subtraction test failed!\n";

displayMatrix(resultSub);

// Testing mutant addition

cout << "\nTesting Mutant Matrix Addition:\n";

Matrix mutantAdd = mutantMatrixAddition(matA,

matB); if (mutantAdd != expectedAddition) {

cout << "Mutant addition test passed (error detected)!\n";

} else {

cout << "Mutant addition test failed (no error detected)!\n";

displayMatrix(mutantAdd);

// Testing mutant subtraction

cout << "\nTesting Mutant Matrix Subtraction:\n";

Matrix mutantSub = mutantMatrixSubtraction(matA, matB);

if (mutantSub != expectedSubtraction) {

cout << "Mutant subtraction test passed (error detected)!\n";

} else {

cout << "Mutant subtraction test failed (no error detected)!\n";


}

displayMatrix(mutantSub);

int main() {

testMatrixOperations();

return 0;

Output:
EXPERIMENT-12
Aim: To understand slicing testing and generate test cases for addition/subtraction for 2d
matrix.

Code:

#include <iostream>

#include <vector>

#include <stdexcept>

using namespace std;

// Define a matrix as a vector of vectors

typedef vector<vector<int>> Matrix;

// Function for matrix addition (Addition slice)

Matrix matrixAdditionSlice(const Matrix& matA, const Matrix& matB)

{ int rows = matA.size();

int cols = matA[0].size();

Matrix result(rows, vector<int>(cols));

// Sliced section for matrix addition

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

for (int j = 0; j < cols; ++j) { result[i]

[j] = matA[i][j] + matB[i][j];

}
return result;

// Function for matrix subtraction (Subtraction slice)

Matrix matrixSubtractionSlice(const Matrix& matA, const Matrix& matB)

{ int rows = matA.size();

int cols = matA[0].size();

Matrix result(rows, vector<int>(cols));

// Sliced section for matrix subtraction

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

for (int j = 0; j < cols; ++j) { result[i]

[j] = matA[i][j] - matB[i][j];

return result;

// Function to display the matrix

void displayMatrix(const Matrix& mat)

{ for (const auto& row : mat) {

for (int val : row)

{ cout << val << "

";

cout << endl;


}

// Test cases to validate the matrix addition and subtraction slices

void testMatrixSlices() {

Matrix matA = {{1, 2}, {3, 4}};

Matrix matB = {{5, 6}, {7, 8}};

// Expected results for addition and subtraction

Matrix expectedAddition = {{6, 8}, {10, 12}};

Matrix expectedSubtraction = {{-4, -4}, {-4, -4}};

// Test case for matrix addition slice

cout << "Testing Matrix Addition Slice:\n";

Matrix resultAdd = matrixAdditionSlice(matA, matB);

if (resultAdd == expectedAddition) {

cout << "Addition slice test passed!\n";

} else {

cout << "Addition slice test failed!\n";

displayMatrix(resultAdd);

// Test case for matrix subtraction slice

cout << "\nTesting Matrix Subtraction Slice:\n";

Matrix resultSub = matrixSubtractionSlice(matA, matB);


if (resultSub == expectedSubtraction) {

cout << "Subtraction slice test passed!\

n";

} else {

cout << "Subtraction slice test failed!\n";

displayMatrix(resultSub);

int main() {

testMatrixSlices();

return 0;

Output:

You might also like