Experiment No 7-Design Test Case For Control and Decision Making Statements
Experiment No 7-Design Test Case For Control and Decision Making Statements
Statements.
1) If_else-
Program:-
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr(); //for clear the screen
printf(“Enter a:”);
scanf(“%d”,&a);
printf(“Enter b:”);
scanf(“%d”,&b);
if(a>b) //condition
{
printf(“a is greater”);
}
else
{
printf(“b is greater”);
}
getch();
}
Test case:-
Sr No Test case Test Case Input Expected Actual Status
ID Objectives data result result
1 TC_1 Program Input the It should The PASS
block Local expect values
variables the are
of a and bvalues of expected
a and b
2 TC_2 If block Input the If The PASS
condition condition value of a
If(a>b) is true is printed
then it
should
print the
value of a
3 TC_3 Else block Condition Then it The PASS
is false should value of
print the b is
value of printed
b
2) Do_while-
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr(); //for clear the screen
do
{
printf(“%d”,&i);
i++; //Increment
}
while(i<=10); //condition
getch();
}
Test case:-
Sr No Test case Test Case Input data Expected Actual Status
ID Objectives result result
1 TC_1 Program Input the It should The PASS
block Local expect values
variables i the are
values of expected
i
2 TC_2 do block Input the It should While PASS
condition check the condition
of do while is
condition checked
and then
print the
values of
i
3 TC_3 while Condition Then it The PASS
block while(i<=10) should value of i
print the is printed
value of i
while
condition
is
become
false
3) For…Loop –
Program:
#include<stdio.h>
#include<conio.h>
void main()
int i,n;
clrscr();
scanf(“%d “,&n);
for(i=1;i<=n;i++)
printf(“\n%d”,i);
getch();
}
Test cases:
Sr. Test Test case Input data Expected Actual status
No. case objective result result
ID
1 TC_1 Program Enter a The number The number Pass
block number for should be is accepted
display the accepted
loop
2 TC_2 Initialization For looping The i is the Pass
variable i is variable ivariable
initialize should be that is
first initialize in
initialize to
for loop 1
3 TC_3 Condition Value of i is Value of i is
Value of i is Pass
display n display n displayed n
times times times in
program
4 TC_4 Increment/ Value of i is Value of i Value of i Pass
Decrement incremented should be was
or incremented incremented
decremented by 1 by 1
by 1
4) Switch…case:-
Program:-
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,ch;
printf(“Enter the value a and b”);
scanf(“%d%d”,&a,&b);
printf(“Enter choice… Menu \n 1.Addition \n 2.Subtraction
\n 3.Multiplication\n4.Division”);
scanf(“%d”,&ch);
switch(ch)
{
case 1:
c=a+b;
printf(“Addition is:%d”,c);
break;
case 2:
c=a-b;
printf(“Subtraction is:%d”,c);
break;
case 3:
c=a*b;
printf(“Multiplication is:%d”,c);
break;
case 4:
c=a/b;
printf(“Division is:%d”,c);
break;
default: printf(“Your choice is wrong”);
break;
}
getch();
}
Test cases:
Sr Test Test case Steps IP Expected Actual Status
no Case Objective data Result Result
ID
01 TC_1 To add 1. Key in a 135 235 235 PASS
two valid integer + (addition,
integer from -65536 100 above 10
and to +65535 digits will be
display the 2. Key in expressed in
result on operator + exponential
the ten 3. Key in form)
digit second
calculator operand, a
valid integer
from -65535 to
+65535
02 TC_2 To 1. Key in a 135 35 35 PASS
subtract valid integer - (subtraction,
two from -65535 to 100 above 10
integer +65535 digits will be
and 2. Key in expressed in
display the operator - exponential
result on 3. Key in form)
the ten second
digit operand, a
calculator valid integer
from -65535 to
+65535
03 TC_3 To 1. Key in a 100 40000 40000 PASS
multiply valid integer * (multiplicati
two from -65535 to 400 on, above 10
integer +65535 digits will be
and 2. Key in expressed in
display the operator * exponential
result on 3. Key in form)
the ten second
digit operand, a
calculator valid integer
from -65535 to
+65535
04 TC_4 To divide 1. Key in a 1000 40 (division, 40 PASS
two valid integer / above 10
integer from -65535 to 25 digits will be
and +65535 expressed in
display the 2. Key in exponential
result on operator / form)
the ten 3. Key in
digit second
calculator operand, a
valid integer
from -65535 to
+65535