You are on page 1of 24

Software Testing Lab Manual[2014]

Veermata Jijabai Technological Institute, Mumbai 1



Experiment No.01

TITLE:
Random test data generation.

PROBLEM:
Consider the triangle program that accepts three integers a,b and c, as input. These are taken
sides of a triangle. The output of the program is the type of the triangle determined by the three
sides: Equilateral, Isosceles, scalene, or not a triangle. Constraints on input are as follows:
C1: 1<=a<=200; C2: 1<=b<=200; C3: 1<=c<=200;
C4: a<b+c; C5: b<a+c; C6: c<b+a;
Write a program in C,C++, Java Programming Language.
Generate test cases using random test data generator. Test program using the input generated by
Random method. Write percentage for each type of the output generated by given test data.
Write your observation for test cases and percentage test cases generated for each type of output.

PROGRAMS:
1. STLab1.c
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
//to generate random numbers
int generateRandomNumber()
{
return rand() % 201;
}
//main function
void main()
{
FILE *f=fopen("TestFile.txt","w");
int j,a,b,c;
for(j=0;j<25;j++)
{
a=generateRandomNumber();
fprintf(f,"%d \n",a);
b=generateRandomNumber();
fprintf(f,"%d \n",b);
c=generateRandomNumber();
fprintf(f,"%d \n",c);
}
Software Testing Lab Manual[2014]

Veermata Jijabai Technological Institute, Mumbai 2

fclose(f);
}

2. STLab1TriangleCheck.c
#include<stdio.h>
//check type of triangle with respect to given inputs
void TriangleCheck(int ax, int bx, int cx)
{
if(ax==bx==cx)
{
printf("\nIts Equilateral\n");
}
else if(cx>(ax+bx)||bx>(ax+cx)||ax>(bx+cx))
{
printf("\n Its not a Triangle\n");
}
else if(ax==bx || bx==cx || ax==cx)
{
printf("\n Its Isoceles\n");
}
else
{
printf("\n Its Scalene\n");
}
}

3.STLabTesting.c
#include "STLab1TriangleCheck.c"
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
//main function
int main()
{
FILE *fp;
fp=fopen("TestFile.txt","r");
int a,b,c;
while(!feof(fp))
{
fscanf(fp,"%d",&a);
Software Testing Lab Manual[2014]

Veermata Jijabai Technological Institute, Mumbai 3

fscanf(fp,"%d",&b);
fscanf(fp,"%d",&c);
TriangleCheck(a,b,c);
}
fclose(fp);
return 0;
}

4. TestFile.txt [ScreenShot]









Software Testing Lab Manual[2014]

Veermata Jijabai Technological Institute, Mumbai 4

OBSERVATION:
Table 1:
Test Case ID A B C Expected
Output
1. 41 176 103 Not a triangle
2. 169 74 46 Not a triangle
3. 21 12 28 Scalene
4. 143 77 5 Not a triangle
5. 166 144 112 Scalene
6. 89 181 83 Not a triangle
7. 3 9 30 Not a triangle
8. 132 83 153 Scalene
9. 91 121 135 Scalene
10. 23 20 197 Not a triangle
11. 20 18 98 Not a triangle
12. 81 60 13 Not a triangle
13. 140 169 151 Scalene
14. 45 161 93 Not a triangle
15. 167 183 186 Scalene
16. 41 66 73 Scalene
17. 113 34 20 Not a triangle
18. 107 100 195 Scalene
19. 138 196 80 Scalene
20. 93 193 175 Scalene
21. 55 20 80 Not a triangle
22. 33 87 157 Not a triangle
23. 196 98 169 Scalene
24. 136 110 87 Scalene
25. 11 96 49 Not a triangle














Software Testing Lab Manual[2014]

Veermata Jijabai Technological Institute, Mumbai 5

Table 2:
Test Case ID Not a Triangle Isosceles Scalene Equilateral
1. *
2. *
3. *
4. *
5. *
6. *
7. *
8. *
9. *
10. *
11. *
12. *
13. *
14. *
15. *
16. *
17. *
18. *
19. *
20. *
21. *
22. *
23. *
24. *
25. *
Percentage 52% 0% 48% 0%

CONCLUSION:
In this practical, I have written simple codes to generate random numbers to be taken as input by
another program as test case data. By observing outputs for each test data, I have filled up two
tables showing output for each test case and its percentage for each type of triangle. It was my
really interesting to test simple code using C++.

*****






Software Testing Lab Manual[2014]

Veermata Jijabai Technological Institute, Mumbai 6

Experiment No.02

TITLE:
Black Box Testing Techniques:
1. Boundary Value Analysis
2. Equivalence Class Partition
3. Decision Table

PROBLEM:
NextDate :
It is a function of three variables: day, month, year
This function takes input date and it returns the next date. The constraints on day, month
and year integer variables are as follows:
C1 : 1 <= Month <= 12
C2: 1 <= Day <= 31
C3: 1812 <= Year <= 2020
Write a program in C, C++, Java programming language.

Generate Test Cases using :
1) Boundary value Analysis
2) Equivalence Class Partition
3) Decision Table
Test program using the test cases generated by above techniques.
Write percentage for each type of the output generated by the given test cases.

PROGRAM:
1. date.cpp
#include<iostream>
using namespace std;
//to check if month having 30 days
bool isMonthOfThirty(int MonthNum)
{
int i,MonthOfThirty[]={4,6,9,11};
for(i=0;i<(sizeof(MonthOfThirty)/sizeof(int));i++)
{
if(MonthOfThirty[i]==MonthNum)
{
return true;
}
}
Software Testing Lab Manual[2014]

Veermata Jijabai Technological Institute, Mumbai 7

}

//to check if date is valid
bool isDateValid(int dd,int mm,int yyyy)
{
if((dd>=1) && (dd<=31))
{
if((mm>=1)&&(mm<=12))
{
if((yyyy>=1812)&&(yyyy<=2020))
{
if(((yyyy%4==0)&&(yyyy%100!=0)) || (yyyy%400==0))
{
if((mm==2)&&(dd>29))
{
cout<<"Invalid input!!"<<endl;
return false;
}
}
else
{
if((mm==2)&&(dd>28))
{
cout<<"Invalid input!!"<<endl;
return false;
}
}
if(isMonthOfThirty(mm))
{
if(dd>30)
{
cout<<"Invalid input!!"<<endl;
return false;
}
}
return true;
}
else
{
cout<<"Invalid input!!"<<endl;
Software Testing Lab Manual[2014]

Veermata Jijabai Technological Institute, Mumbai 8

return false;
}
}
else
{
cout<<"Invalid input!!"<<endl;
return false;
}
}
else
{
cout<<"Invalid input!!"<<endl;
return false;
}
}

//to find next date
void getNextDate(int d,int m,int y)
{
if((d==28) || (d==29) || (d==30) || (d==31))
{
d=1;
if(m==12)
{
m=1;
y++;
}
else
{
m++;
}
}
else
{
d++;
}
cout<<"Next Date:"<<d<<"-"<<m<<"-"<<y<<endl;
}

//main function
Software Testing Lab Manual[2014]

Veermata Jijabai Technological Institute, Mumbai 9

int main()
{
int day,month,year;
cout<<"Enter date as an input: [dd mm yyyy]"<<endl;
cin>>day>>month>>year;
bool validity=isDateValid(day,month,year);
if(validity == true)
{
getNextDate(day,month,year);
}
return 0;
}

OBSERVATION:
(i) Boundary Value Analysis:
As there are three inputs in this particular program, We will be using 4n+1 = 4*3+1= 13 Test
cases .
Type Day Month Year Expected
Output
Normal BVA 1 2 1990 2-2-1990
2 3 1900 3-3-1900
30 4 2004 1-5-2004
31 5 2010 1-6-2010
7 1 1890 8-1-1890
15 2 2012 16-2-2012
20 11 2004 21-11-2004
5 12 2014 6-12-2014
5 3 1812 6-3-1812
7 5 1813 8-5-1813
15 7 2019 16-7-2019
17 11 2020 18-11-2020
Normal 7 5 1994 8-5-1994
Robust BVA 0 5 1993 Invalid Input!!
32 7 1994 Invalid Input!!
7 0 2000 Invalid Input!!
5 13 2004 Invalid Input!!
4 5 1811 Invalid Input!!
6 10 2021 Invalid Input!!

Valid Output % : 68.4%
Invalid Output %: 31.6%


Software Testing Lab Manual[2014]

Veermata Jijabai Technological Institute, Mumbai 10

(ii) Equivalence Class Partition:[ Valid Output: 33.33% Invalid Output: 66.66%]
Variable Type Day Month Year Output
Day < Min -1 5 1994 Invalid
Normal 7 5 2004 Valid
> Max 32 5 2014 Invalid
Month <Min 7 -1 1900 Invalid
Normal 25 10 1993 Valid
> Max 5 13 2001 Invalid
Year <Min 25 5 1811 Invalid
Normal 7 10 1994 Valid
> Max 5 1 2021 Invalid

(iii) Decision Table:[ Valid Output: 12.5% Invalid Output: 87.5%]
Constraints are:
C1 : 1 <= Day <= 31
C2 : 1 <= Month <=12
C3 : 1812 <= Year <= 2020
C4 : Leap Year OR Not leap year
Test No. C1 C2 C3 C4 Valid Invalid
1 N N N N N Y
2 N N N Y N Y
3 N N Y N N Y
4 N N Y Y N Y
5 N Y N N N Y
6 N Y N Y N Y
7 N Y Y N N Y
8 N Y Y Y N Y
9 Y N N N N Y
10 Y N N Y N Y
11 Y N Y N N Y
12 Y N Y Y N Y
13 Y Y N N N Y
14 Y Y N Y N Y
15 Y Y Y N Y N
16 Y Y Y Y Y N

CONCLUSION:
In this experiment, I have studied about the concept of Black Box Testing. And I have used few
techniques such as Boundary Value Analysis, Equivalence Class Partition & Decision Table to
test simple code in which I am trying to find next date. I have used C language to implement this
particular solution.

*****
Software Testing Lab Manual[2014]

Veermata Jijabai Technological Institute, Mumbai 11

Experiment No.03

TITLE:
Random test data generation.































Software Testing Lab Manual[2014]

Veermata Jijabai Technological Institute, Mumbai 12




































Software Testing Lab Manual[2014]

Veermata Jijabai Technological Institute, Mumbai 13




































Software Testing Lab Manual[2014]

Veermata Jijabai Technological Institute, Mumbai 14




































Software Testing Lab Manual[2014]

Veermata Jijabai Technological Institute, Mumbai 15




































Software Testing Lab Manual[2014]

Veermata Jijabai Technological Institute, Mumbai 16

Experiment No.04

TITLE:
Write a Program In Java To Demonstrate The Working Of Following Statement Controls And
Construct Test Cases:
1. dowhile
2. while
3. ifelse
4. switch case

THEORY:
In this practical we are going to provide inputs of different types and going to check the expected
and observed results . We are going to apply different inputs for control and looping statements
to generate test cases.

PROGRAM:
1. dowhile
//TestDoWhile.java
import java.util.Scanner;

class TestDoWhile
{
public static void main(String args[])
{
try
{
Scanner s=new Scanner(System.in);
int temp=0;
temp=s.nextInt();
do
{
System.out.println("Value of TEMP is->"+temp);
temp--;
} while(temp!=0);
}
catch(Exception e)
{
System.out.println("Error !!!");
}
}
Software Testing Lab Manual[2014]

Veermata Jijabai Technological Institute, Mumbai 17

}
TEST CASES:
Test Case ID temp Expected
Output
Output Result
1 5 Successful Successful Pass
2 -5 Infinite Loop Successful Fail
3 -5 Infinite Loop Infinite Loop Pass
4 A Invalid Input Invalid Input Pass


2. While
//TestWhile.java
import java.util.Scanner;

class TestWhile
{
public static void main(String args[])
{
try
{
Scanner s=new Scanner(System.in);
int temp=0;
temp=s.nextInt();
while(temp!=0)
{
System.out.println("Value of TEMP is->"+temp);
temp--;
}
}
catch(Exception e)
{
System.out.println("Error !!!");
}
}
}






Software Testing Lab Manual[2014]

Veermata Jijabai Technological Institute, Mumbai 18

TEST CASES:
Test Case ID temp Expected
Output
Output Result
1 5 Successful Successful Pass
2 -5 Infinite Loop Successful Fail
3 -5 Infinite Loop Infinite Loop Pass
4 A Invalid Input Invalid Input Pass


3. If Else
//TestIfElse.java
import java.util.Scanner;

class TestIfElse
{
public static void main(String args[])
{
try
{
Scanner s=new Scanner(System.in);
int a=s.nextInt();
if(a==101)
{
System.out.println("A is lucky number");
}
else
{
System.out.println("A is not lucky number");
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}





Software Testing Lab Manual[2014]

Veermata Jijabai Technological Institute, Mumbai 19

TEST CASES:
Test Case ID a Expected
Output
Output Result
1 101 Successful Successful Pass
2 25 Successful Successful Pass
3 abc Invalid Input Successful Fail
4 abc Invalid Input Invalid Input Pass
5 -43 Successful Successful Pass

4. Switch case
//TestSwitch.java
import java.util.Scanner;

class TestSwitch
{
public static void main(String args[])
{
try
{
System.out.println("Enter proper choice: \n 1. Add \n 2. Subtract \n 3. Show \n 4. Exit
\n");
Scanner s=new Scanner(System.in);
int a=s.nextInt();
switch(a)
{
case 1: System.out.println("Your choice is to Add");
break;
case 2: System.out.println("Your choice is to subtract");
break;
case 3: System.out.println("Your choice is to show");
break;
case 4: System.out.println("Your choice is to exit");
break;
default:System.out.println("Enter proper valid choice!!");
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
Software Testing Lab Manual[2014]

Veermata Jijabai Technological Institute, Mumbai 20

}

TEST CASES:
Test Case ID a Expected
Output
Output Result
1 1 Successful Successful Pass
2 2 Successful Successful Pass
3 3 Successful Successful Pass
4 4 Successful Successful Pass
5 5 Successful Successful Pass
6 5 Successful Error Fail
7 x Invalid Input Invalid Input Pass
8 x Invalid Input Successful Fail

CONCLUSION:
In this experiment, I have tried to test simple control statements and looping statements. I have
implemented few programs in Java and tested it by applying different types of inputs to generate
test cases.

*****


















Software Testing Lab Manual[2014]

Veermata Jijabai Technological Institute, Mumbai 21


Experiment No.05

TITLE:
Program for matrix multiplication . Introspect the causes for its failures and write down the
possible reasons for its failures.

THEORY:
The program multiplies two matrices and checks for the valid and invalid output with causes of
failure being the order of the matrix and entries of the matrix.

PROGRAM:
#include<stdio.h>

int main()
{
int row1,col1,row2,col2;int a[10][10];int b[10][10];int c[10][10];
printf("Enter number of rows and colums of both matrix\n");
scanf("%d %d %d %d",&row1,&col1,&row2,&col2);
if(row1>0 && row2>0 && col1>0 && col2>0 && col1==row2 && row1<10 &&
row2<10 && col1<10 && col2<10)
{
int i=0,j=0;
printf("Enter first matrix values:\n");
for(i=0;i<row1;i++)
{
for(j=0;j<col1;j++)
scanf("%d",&a[i][j]);
}

printf("Enter second matrix values:\n");
for(i=0;i<row2;i++)
{
for(j=0;j<col2;j++)
scanf("%d",&b[i][j]);
}

int k=0;
for(i=0;i<row1;i++)
{
Software Testing Lab Manual[2014]

Veermata Jijabai Technological Institute, Mumbai 22

for(j=0;j<col2;j++)
{
int sum=0;
for(k=0;k<col1;k++)
{
sum+=a[i][k]+b[k][j];
}
c[i][j]=sum;
}
}
int i1=0,j1=0;
for(i1=0;i1<row1;i1++)
{
printf("\n");
for(j1=0;j1<col2;j1++)
printf("%d ",c[i1][j1]);
}
printf("\n");
}
else
{
printf("Invalid Input\n");
}
return 1;
}

TEST CASES:
Test
Case
ID
R1 R2 C1 C2 Element
Type
Expected
Output
Output Remark
1 2 3 3 1 Int Success Success Pass
2 2 1 2 3 Int Multiplication
not possible
Multiplication
not possible
Pass
3 3 3 3 3 +ve Int Success Success Pass
4 3 2 2 3 -ve Int Success Success Pass
5 2 3 3 2 +ve/-ve
Float
Garbage Garbage Pass
6 1 2 2 1 Char Multiplication
not possible
Success Fail


Software Testing Lab Manual[2014]

Veermata Jijabai Technological Institute, Mumbai 23


CONCLUSION:
In this experiment, I have examined failure causes by considering variations in rows,columns
and contents of the matrix.

*****





























Software Testing Lab Manual[2014]

Veermata Jijabai Technological Institute, Mumbai 24

Experiment No.06

TITLE:
Program to calculate the root mean square value with reference to three integers a, b, c.
Introspect the causes for its failures and write down the possible reasons for its failures.

THEORY:
The program calculates the RMS value for the valid and invalid output with causes of failure
being the data types of a, b & c.

PROGRAM:
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
//to find RMS value of a,b,c
int main()
{
int a,b,c;
int rms;
printf("Enter the values for A, B and C:");
scanf("%d%d%d",&a,&b,&c);
rms=(a*a)+(b*b)+(c*c);
printf("RMS -> %f \n",sqrt(rms));
return 0;
}

TEST CASES:
Test Case
ID
a b c Expected
Output
Output Remark
1 2 3 4 5.3851 5.3851 Pass
2 2.2 3.3 4.4 Int Values
Expected
Int Values
Expected
Pass
3 -2 -3 -4 5.3851 5.3851 Pass

CONCLUSION:
In this experiment, I have examined different failure causes by considering various data types
and qualifiers for variables a,b and c.

*****

You might also like