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

Software testing lab file kalash

Uploaded by

Vrishhti Goel
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)
27 views

Software testing lab file kalash

Uploaded by

Vrishhti Goel
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/ 18

JSS Academy of Technical Education Software Testing Lab (KIT -751A)

EXPERIMENT – 1
AIM: Implement a program in ‘C’ for Triangle Problem using Boundary
Value Analysis technique.
Program::
#include <stdio.h>

// Function to check if sides form a triangle


int isValidTriangle(int a, int b, int c) {
return (a + b > c) && (a + c > b) && (b + c > a);

// Function to determine the type of triangle


void determineTriangleType(int a, int b, int c) {

if (!isValidTriangle(a, b, c)) {
printf("Not a triangle.\n");
return;

}
if (a == b && b == c) {
printf("Equilateral triangle.\n");
} else if (a == b || b == c || a == c) {
printf("Isosceles triangle.\n");
} else {
printf("Scalene triangle.\n");
}

int main() {
int a, b, c;
printf("Enter the sides of the triangle: ");

scanf("%d %d %d", &a, &b, &c);


KALASH KUMAR 2100910130050 IT -1 (A2)
JSS Academy of Technical Education Software Testing Lab (KIT -751A)

printf("Testing with sides (%d, %d, %d):\n", a, b, c);


determineTriangleType(a, b, c);

return 0;
}

OUTPUT::
Enter the sides of the triangle: 3 3 3.

Testing with sides (3, 3, 3):

Equilateral triangle.

Enter the sides of the triangle: 4 4 6

Testing with sides (4, 4, 6):

Isosceles triangle.

Enter the sides of the triangle: 5 6 7

Testing with sides (5, 6, 7):

Scalene triangle.

Enter the sides of the triangle: 1 2 3

Testing with sides (1, 2, 3):

Not a triangle.

Enter the sides of the triangle: 1 1 2

Testing with sides (1, 1, 2):

Not a triangle.

KALASH KUMAR 2100910130050 IT – 1(A2)


JSS Academy of Technical Education Software Testing Lab (KIT -751A)

EXPERIMENT – 2
AIM: Implement a program in ‘C’ for Commission Problem using
Boundary Value Analysis technique.
Program::
#include <stdio.h>

// Function to calculate commission

float calculateCommission(int sales) {

if (sales <= 5000) {

return 0.0;

} else if (sales <= 10000) {

return sales * 0.05;

} else if (sales <= 20000) {

return sales * 0.10;

} else {
return sales * 0.15;

int main() {

// Test cases using Boundary Value Analysis

int testCases[] = {5000, 5001, 10000, 10001, 20000, 20001};

int numCases = sizeof(testCases) / sizeof(testCases[0]);

printf("Boundary Value Analysis Test Cases:\n");

printf("Sales\tCommission\n");

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

int sales = testCases[i];

float commission = calculateCommission(sales);

printf("%d\t%.2f\n", sales, commission);

KALASH KUMAR 2100910130050 IT-1(A2)


JSS Academy of Technical Education Software Testing Lab (KIT -751A)

return 0;

OUTPUT::
Boundary Value Analysis Test Cases:

Sales Commission
5000 0.00

5001 250.05

10000 500.00

10001 1000.10

20000 2000.00
20001 3000.15

KALASH KUMAR 2100910130050 IT -1(A2)


JSS Academy of Technical Education Software Testing Lab (KIT -751A)

EXPERIMENT – 3
AIM: Implement a Program in ‘C’ for Next date using Boundary Value
Analysis technique
Program::
#include <stdio.h>

#include <stdbool.h>

// Function to check if a year is a leap year

bool isLeapYear(int year) {

return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);

// Function to get the number of days in a given month

int getDaysInMonth(int month, int year) {

switch (month) {

case 1: case 3: case 5: case 7: case 8: case 10: case 12:

return 31;

case 4: case 6: case 9: case 11:

return 30;

case 2:

return isLeapYear(year) ? 29 : 28;

default:

return 0; // Invalid month

// Function to calculate the next date

void getNextDate(int day, int month, int year) {

int daysInMonth = getDaysInMonth(month, year);

KALASH KUMAR 2100910130050 IT-1(A2)


JSS Academy of Technical Education Software Testing Lab (KIT -751A)

if (day < 1 || day > daysInMonth || month < 1 || month > 12 || year < 1) {

printf("Invalid date: %d-%d-%d\n", day, month, year);

return;

if (day < daysInMonth) {

day++;

} else {

day = 1;

if (month < 12) {

month++;

} else {

month = 1;

year++;

printf("Next date: %02d-%02d-%04d\n", day, month, year);

int main() {

// Test cases using Boundary Value Analysis

int testCases[][3] = {

{31, 12, 2023}, // End of year

{28, 2, 2023}, // Non-leap year end of February

{29, 2, 2024}, // Leap year end of February

{30, 4, 2023}, // End of April

{31, 1, 2023}, // End of January

{1, 1, 2023} // Start of the year

};

int numCases = sizeof(testCases) / sizeof(testCases[0]);

KALASH KUMAR 2100910130050 IT -1(A2)


JSS Academy of Technical Education Software Testing Lab (KIT -751A)

printf("Boundary Value Analysis Test Cases:\n");

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

int day = testCases[i][0];

int month = testCases[i][1];

int year = testCases[i][2];

printf("Input date: %02d-%02d-%04d -> ", day, month, year);

getNextDate(day, month, year);

return 0;

OUTPUT::
Boundary Value Analysis Test Cases:

Input date: 31-12-2023 -> Next date: 01-01-2024

Input date: 28-02-2023 -> Next date: 01-03-2023

Input date: 29-02-2024 -> Next date: 01-03-2024

Input date: 30-04-2023 -> Next date: 01-05-2023

Input date: 31-01-2023 -> Next date: 01-02-2023

Input date: 01-01-2023 -> Next date: 02-01-2023

KALASH KUMAR 2100910130050 IT-1(A2)


JSS Academy of Technical Education Software Testing Lab (KIT -751A)

EXPERIMENT – 4
AIM: Implement a program in ‘C’ for Triangle Problem using
Equivalence Class Testing technique.
Program::
#include <stdio.h>

// Function to classify the triangle


void classifyTriangle(int a, int b, int c) {
// Check for invalid inputs

if (a <= 0 || b <= 0 || c <= 0) {


printf("Invalid Triangle: Sides must be positive.\n");
return;
}

// Check triangle inequality


if (a + b <= c || a + c <= b || b + c <= a) {
printf("Not a Triangle: Violates triangle inequality.\n");
return;
}

// Classify the triangle


if (a == b && b == c) {
printf("Equilateral Triangle\n");
} else if (a == b || b == c || a == c) {

printf("Isosceles Triangle\n");
} else {
printf("Scalene Triangle\n");
}
}
KALASH KUMAR 2100910130050 IT -1(A2)
JSS Academy of Technical Education Software Testing Lab (KIT -751A)

int main() {
// Test cases using Equivalence Class Testing
int testCases[][3] = {
{3, 3, 3}, // Equilateral

{3, 3, 5}, // Isosceles

{3, 4, 5}, // Scalene


{0, 3, 5}, // Invalid: Side is zero
{-3, 4, 5}, // Invalid: Negative side
{1, 2, 3}, // Invalid: Triangle inequality violation
{5, 5, 10} // Invalid: Triangle inequality violation

};

int numCases = sizeof(testCases) / sizeof(testCases[0]);

printf("Triangle Classification Test Cases:\n");

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

int a = testCases[i][0];
int b = testCases[i][1];
int c = testCases[i][2];
printf("Input Sides: %d, %d, %d -> ", a, b, c);

classifyTriangle(a, b, c);
}

return 0;
}

KALASH KUMAR 2100910130050 IT-1(A2)


JSS Academy of Technical Education Software Testing Lab (KIT -751A)

OUTPUT::

Triangle Classification Test Cases:

Input Sides: 3, 3, 3 -> Equilateral Triangle

Input Sides: 3, 3, 5 -> Isosceles Triangle

Input Sides: 3, 4, 5 -> Scalene Triangle

Input Sides: 0, 3, 5 -> Invalid Triangle: Sides must be positive.

Input Sides: -3, 4, 5 -> Invalid Triangle: Sides must be positive.

Input Sides: 1, 2, 3 -> Not a Triangle: Violates triangle inequality.

Input Sides: 5, 5, 10 -> Not a Triangle: Violates triangle inequality.

KALASH KUMAR 2100910130050 IT -1(A2)


JSS Academy of Technical Education Software Testing Lab (KIT -751A)

EXPERIMENT – 5
AIM: Implement a program in ‘C’ for Commission Problem using
Equivalence Class Testing technique
Program::
#include <stdio.h>

// Function to calculate commission


float calculateCommission(float sales) {
if (sales <= 5000) {

return 0.0; // No commission


} else if (sales <= 10000) {
return sales * 0.05; // 5% commission
} else if (sales <= 20000) {
return sales * 0.10; // 10% commission

} else {
return sales * 0.15; // 15% commission
}
}

int main() {
// Test cases using Equivalence Class Testing
float testCases[] = {
0, // Invalid: Zero sales
-1000, // Invalid: Negative sales
3000, // Valid: No commission range

7500, // Valid: 5% commission range

15000, // Valid: 10% commission range


25000 // Valid: 15% commission range
};

int numCases = sizeof(testCases) / sizeof(testCases[0]);


KALASH KUMAR 2100910130050 IT -1(A2)
JSS Academy of Technical Education Software Testing Lab (KIT -751A)

printf("Commission Calculation Test Cases:\n");


printf("Sales\t\tCommission\n");
for (int i = 0; i < numCases; i++) {
float sales = testCases[i];
if (sales < 0) {

printf("%.2f\tInvalid input: Sales cannot be negative.\n", sales);


} else {
float commission = calculateCommission(sales);
printf("%.2f\t%.2f\n", sales, commission);
}

return 0;
}

OUTPUT::
Commission Calculation Test Cases:

Sales Commission
0.00 Invalid input: Sales cannot be zero.
-1000.00 Invalid input: Sales cannot be negative.
3000.00 0.00
7500.00 375.00

15000.00 1500.00

25000.00 3750.00

KALASH KUMAR 2100910130050 IT-1(A2)


JSS Academy of Technical Education Software Testing Lab (KIT -751A)

EXPERIMENT – 6
AIM: Implement a program in ‘C’ for Next date program using
Equivalence Class Testing technique.
Program::
#include <stdio.h>

#include <stdbool.h>

// Function to check if a year is a leap year

bool isLeapYear(int year) {

return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));

// Function to get the number of days in a given month

int getDaysInMonth(int month, int year) {

switch (month) {

case 1: case 3: case 5: case 7: case 8: case 10: case 12:

return 31;

case 4: case 6: case 9: case 11:

return 30;

case 2:

return isLeapYear(year) ? 29 : 28;

default:

return 0; // Invalid month


}

// Function to calculate the next date

void getNextDate(int day, int month, int year) {

int daysInMonth = getDaysInMonth(month, year);

// Validate the input date

KALASH KUMAR 2100910130050 IT-1(A2)


JSS Academy of Technical Education Software Testing Lab (KIT -751A)

if (year <= 0 || month < 1 || month > 12 || day < 1 || day > daysInMonth) {

printf("Invalid date: %02d-%02d-%04d\n", day, month, year);

return;

// Calculate the next day

if (day < daysInMonth) {

day++;

} else {

day = 1;

if (month < 12) {

month++;

} else {

month = 1;

year++;

printf("Next date: %02d-%02d-%04d\n", day, month, year);

int main() {

// Test cases using Equivalence Class Testing

int testCases[][3] = {

{31, 12, 2023}, // End-of-year transition

{28, 2, 2023}, // Non-leap year February

{29, 2, 2024}, // Leap year February

{30, 4, 2023}, // End-of-month (30-day month)

{31, 1, 2023}, // End-of-month (31-day month)

{1, 1, 2023}, // Beginning of the year

{31, 4, 2023}, // Invalid: April has 30 days

KALASH KUMAR 2100910130050 IT-1(A2)


JSS Academy of Technical Education Software Testing Lab (KIT -751A)

{32, 1, 2023}, // Invalid: Day exceeds maximum for January

{15, 13, 2023}, // Invalid: Month > 12

{-1, 10, 2023}, // Invalid: Negative day

{15, 0, 2023} // Invalid: Month = 0

};

int numCases = sizeof(testCases) / sizeof(testCases[0]);

printf("Next Date Program - Equivalence Class Testing:\n");

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

int day = testCases[i][0];

int month = testCases[i][1];

int year = testCases[i][2];

printf("Input date: %02d-%02d-%04d -> ", day, month, year);

getNextDate(day, month, year);

return 0;

OUTPUT::
Next Date Program - Equivalence Class Testing:

Input date: 31-12-2023 -> Next date: 01-01-2024

Input date: 28-02-2023 -> Next date: 01-03-2023

Input date: 29-02-2024 -> Next date: 01-03-2024

Input date: 30-04-2023 -> Next date: 01-05-2023

Input date: 31-01-2023 -> Next date: 01-02-2023

Input date: 01-01-2023 -> Next date: 02-01-2023

Input date: 31-04-2023 -> Invalid date: 31-04-2023

Input date: 32-01-2023 -> Invalid date: 32-01-2023

Input date: 15-13-2023 -> Invalid date: 15-13-2023

Input date: -1-10-2023 -> Invalid date: -1-10-2023

Input date: 15-00-2023 -> Invalid date: 15-00-2023


KALASH KUMAR 2100910130050 IT-1(A2)
JSS Academy of Technical Education Software Testing Lab (KIT -751A)

EXPERIMENT – 7
AIM: Implement a program in ‘C’ for Binary Search using Basis paths
technique.
Program::
#include <stdio.h>

// Binary Search function

int binarySearch(int arr[], int size, int target) {

int low = 0, high = size - 1;

while (low <= high) {

int mid = low + (high - low) / 2; // Prevent overflow

if (arr[mid] == target) {

return mid; // Target found

} else if (arr[mid] > target) {

high = mid - 1; // Search in the left subarray

} else {

low = mid + 1; // Search in the right subarray

return -1; // Target not found

int main() {

// Test cases for Basis Path Testing

int arr[] = {1, 3, 5, 7, 9, 11, 13, 15};

int size = sizeof(arr) / sizeof(arr[0]);

KALASH KUMAR 2100910130050 IT-1(A2)


JSS Academy of Technical Education Software Testing Lab (KIT -751A)

// Test cases

int testCases[] = {

7, // Path 1: Target found at mid

3, // Path 2: Search left subarray

13, // Path 3: Search right subarray

8, // Path 4: Target not found

1, // Edge case: First element

15, // Edge case: Last element

-5, // Invalid: Below range

20 // Invalid: Above range

};

int numCases = sizeof(testCases) / sizeof(testCases[0]);

printf("Binary Search Test Cases (Basis Path Testing):\n");

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

int target = testCases[i];

int result = binarySearch(arr, size, target);

if (result != -1) {

printf("Target %d found at index %d.\n", target, result);

} else {

printf("Target %d not found in the array.\n", target);

return 0;

KALASH KUMAR 2100910130050 IT-1(A2)


JSS Academy of Technical Education Software Testing Lab (KIT -751A)

OUTPUT::
Binary Search Test Cases (Basis Path Testing):

Target 7 found at index 3.

Target 3 found at index 1.

Target 13 found at index 6.

Target 8 not found in the array.

Target 1 found at index 0.

Target 15 found at index 7.

Target -5 not found in the array.

Target 20 not found in the array.

KALASH KUMAR 2100910130050 IT-1(A2)

You might also like