Documente Academic
Documente Profesional
Documente Cultură
(Approved by AICTE, New Delhi, and Affiliated to Jawaharalal Nehru Technological University:
Kakinada(AP)
LABORATORY MANUAL
For
Prepared by :
DEPARTMENT OF
MON
L
TUE STM LAB
U
WED N
C
THU STM LAB
H
FRI
SAT
GUIDELINES FOR STUDENTS:
1. Students should be regular and come prepared for the lab practice.
2. In case a student misses a class, it is his/her responsibility to complete that missed experiment(s).
3. Students should bring the observation book, lab journal and lab manual. Prescribed textbook and
class notes can be kept ready for reference if required.
4. They should implement the given Program individually.
5. While conducting the experiments students should see that their programs would meet the
following criteria:
Programs should be interactive with appropriate prompt messages, error messages if any,
and descriptive messages for outputs.
Programs should perform input validation (Data type, range error, etc.) and give appropriate
error messages and suggest corrective actions.
Comments should be used to give the statement of the problem and every function should
indicate the purpose of the function, inputs and outputs
Statements within the program should be properly indented
Use meaningful names for variables and functions.
Make use of Constants and type definitions wherever needed.
6. Once the experiment(s) get executed, they should show the program and results to the instructors
and copy the same in their observation book.
7. Questions for lab tests and exam need not necessarily be limited to the questions in the manual,
but could involve some variations and / or combinations of the questions.
LAB OBJECTIVES:
8 GB RAM , 500 MB of free disk space, Win 2K3 server, Selenium tool, MS Access/Oracle
7.x,8.x,9/MS SQL
Turn off the system once you are done using it.
Read and understand how to carry out an activity thoroughly before coming to laboratory.
Know the location of the fire extinguisher and the first aid box and how to use them in case
of emergency.
Report fires or accidents to your lecture/laboratory technician immediately.
Report any broken plugs or exposed electrical wires to your lecture/laboratory technician
immediately.
DON’T ’S:
LIST OF EXPERMENTS
1. Consider an automated banking application. The user can dial the bank from a personal
computer, provide a six-digit password, and follow with a series of keyword commands that
activate the banking function. The software for the application accepts data in the following
form:
Design the test cases to test the system using following Black Box testing technique:
BVA, Worst BVA, Robust BVA, Robust Worst BVA Equivalence class testing (Input/Output
domain).
3. Consider an application that is required to validate a number according to the following simple rules:
a. A number can start with an optional sign.
b. The optional sign can be followed by any number of digits.
c. The digits can be optionally followed by a decimal point, represented by a period.
d. If there is a decimal point, then there should be two digits after the decimal.
e. Any number-whether or not it has a decimal point, should be terminated a blank.
f. A number can start with an optional sign.
g. The optional sign can be followed by any number of digits.
h. The digits can be optionally followed by a decimal point, represented by a period.
i. If there is a decimal point, then there should be two digits after the decimal.
j. Any number-whether or not it has a decimal point, should be terminated a blank. Generate
test cases to test valid and invalid numbers.
(HINT) Use Decision table and cause-effect graph to generate test cases.
4. Generate test cases using Black box testing technique to Calculate Standard Deduction on
Taxable Income. The standard deduction is higher for tax payers who are 65 or older or
blind. Use the method given below to calculate tax.
1. The first factor that determines the standard deduction is the filing status. The basic
standard deduction for the various filing status are:
Single $4,750
Married, filing a joint return $9,500
Married, filing a separate return $7,000
2. If a married couple is filing separate returns and one spouse is not taking standard
Deduction, the other spouse also is not eligible for standard deduction.
3. An additional $1,000 is allowed as standard deduction, if either the filer is 65 yrs or the
spouse is 65 yrs or older (the latter case applicable when the filing status is “Married”
and filing “joint”).
4. An additional $1,000 is allowed as standard deduction, if either the filer is blind or the
spouse is blind (the latter case applicable when the filing status is “married” and filing
“joint”).
(HINT):
From the above description, it is clear that the calculation of standard deduction depends
on the following 3 factors:
1. Status of filing of the filer
2. Age of the filer
3. Whether the filer is blind or not
In addition, in certain cases, the following additional factors also come into play in
calculating the standard deduction.
1. Whether spouse has claimed standard deduction
2. Whether spouse is blind
3. Whether the spouse is more than 65 years old
5. Consider the following program segment:
1. int max (int i, int j, int k)
2. {
3. int max;
4. if (i>j) then
5. if (i>k) then max=i;
6. else max=k;
7. else if (j > k) max=j
8. else max=k
9. return (max);
10. }
a) Draw the control flow graph for this program segment.
b) Determine the cyclomatic complexity for this program.
c) Determine the independent paths.
6. Source code of simple insertion sort implementation using array in ascending order in c
programming language.
#include<stdio.h>
int main(){
int i,j,s,temp,a[20];
Printf ("Enter total elements: "); Scanf ("%d",&s);
printf("Enter %d elements: ",s); for(i=0;i<s;i++) scanf("%d",&a[i]); for(i=1;i<s;i++){
temp=a[i]; j=i-1; while((temp<a[j])&&(j>=0)){ a[j+1]=a[j];
j=j-1;
}
a[j+1]=temp;
}
printf("After sorting: ");
for(i=0;i<s;i++)
printf(" %d",a[i]);
return 0;
}
HINT: for loop is represented as while loop
a) Draw the program graph for given program segment b) Determine the DD path graph
c) Determine the independent paths
d) Generate the test cases for each independent path
7. Consider a system having an FSM for a stack having the following states and transitions:
States
Initial: Before creation
Empty: Number of elements = 0
Holding: Number of elements > 0, but less than the maximum capacity
Full: Number elements = maximum
Final: After destruction
Initial to Empty: Create
Empty to Holding, Empty to Full, Holding to Holding, Holding to Full: Add
Empty to Final, Full to Final, Holding to Final: Destroy
Holding to Empty, Full to Holding, Full to Empty: Delete
Design test cases for this FSM using state table-based testing.
8. Given the following fragment of code, how many tests are required for 100% decision coverage?
Give the test cases.
if width > length
then biggest_dimension = width if height > width
then biggest dimension = height end_if
else if biggest dimension = length then if height > length
then biggest_dimension = height end_if
end_if end_if
Hint 04 test cases
9. Given the following code, how much minimum number of test cases is required for full statement
and branch coverage?
read p read q
if p+q> 100
then print "Large" endif
if p > 50
then print "p Large" endif
Hint 1 test for statement coverage, 2 for branch coverage
10. Consider a program to input two numbers and print them in ascending order given below. Find
all du paths and identify those du-paths that are not feasible. Also find all dc paths and generate the
test cases for all paths (dc paths and non dc paths).
#include<stdio.h>
#include<conio.h>
1. void main ()
2. {
3 int a, b, t;
4. Clrscr ();
5. Printf (“Enter first number”);
6. scanf (“%d”,&a);
7. printf(“Enter second number”);
8. scanf(“%d”,&b);
9. if (a<b){
10. t=a;
11a=b;
12 b=t;
13}
14. printf (“%d %d”, a, b);
15 getch ();
}
11. Consider the above program and generate possible program slices for all variables. Design at
least one test case from every slice.
12. Consider the code to arrange the nos. in ascending order. Generate the test cases for relational
coverage, loop coverage and path testing. Check the adequacy of the test cases through mutation
testing and also compute the mutation score
for each.
i = 0;
n=4; //N-Number of nodes present in the graph
While (i<n-1) do j = i + 1;
While (j<n) do
if A[i]<A[j] then swap (A[i], A[j]); end do;
i=i+1;
end do
1. Study of any Web Testing Tool (Eg. Selenium)
PROCEDURE:
Selenium Introduction
Automation
Automation is making a process automatic eliminating the need for human intervention. It is a self-
controlling or self-moving process. Automation Software offers automation wizards and commands of its
own in addition to providing a task recording and re-play capabilities. Using these programs you can record
an IT or business task.
Benefits of Automation
Fast
Reliable
Repeatable
Programmable
Reusable
Makes Regression testing easy
Enables 24*78 Testing
Robust verification
History of Selenium
• In 2004 invented by Jason R. Huggins and team.
• Original name is JavaScript Functional Tester [JSFT]
• Open source browser based integration test framework built originally by Thought works.
• 100% JavaScript and HTML
• Web testing tool
• That supports testing Web 2.0 applications
• Supports for Cross-Browser Testing(ON Multiple Browsers)
• And multiple Operating Systems
• Cross browser – IE 6/7, Firefox .8+, Opera, Safari 2.0+
What is Selenium?
• Acceptance Testing tool for web-apps
• Tests run directly in browser
• Selenium can be deployed on Windows, Linux, and Macintosh.
• Implemented entirely using browser technologies -
JavaScript
DHTML
Frames
Selenium Components
– Selenium IDE
– Selenium Core
– Selenium RC
– Selenium Grid
Selenium IDE
• The Selenium-IDE (Integrated Development Environment) is the tool you use to develop your Selenium
test cases.
• It is Firefox plug-in
• Firefox extension which allows record/play testing paradigm
• Automates commands, but asserts must be entered by hand
• Creates the simplest possible Locator
• Based on Selenese
Overview of Selenium IDE:
A.Test Case Pane
B. Toolbar
C.Menu Bar
D.Log/Reference/UI-Element/Rollup Pane
Menu Bar
The File menu has options for Test Case and Test Suite (suite of Test Cases). Using these you can add a new
Test Case, open a Test Case, save a Test Case, export Test Case in a language of your choice. You can also
open the recent Test Case. All these options are also available for Test Suite.
The Edit menu allows copy, paste, delete, undo, and select all operations for editing the commands in your
test case. The Options menu allows the changing of settings. You can set the timeout value for certain
commands, add user-defined user extensions to the base set of Selenium commands, and specify the format
(language) used when saving your test cases. The Help menu is the standard Firefox Help menu; only one
item on this menu–UI-Element Documentation–pertains to Selenium-IDE.
Toolbar
The toolbar contains buttons for controlling the execution of your test cases, including a step feature for
debugging your test cases. The right-most button, the one with the red-dot, is the record button.
Run All: Runs the entire test suite when a test suite with multiple test cases is loaded.
Run: Runs the currently selected test. When only a single test is loaded this button and the Run All button
have the same effect.
Step: Allows you to “step” through a test case by running it one command at a time. Use for debugging test
cases.
TestRunner Mode: Allows you to run the test case in a browser loaded with the Selenium-Core TestRunner.
The TestRunner is not commonly used now and is likely to be deprecated. This button is for evaluating test
cases for backwards compatibility with the TestRunner. Most users will probably not need this button.
Apply Rollup Rules: This advanced feature allows repetitive sequences of Selenium commands to be
grouped into a single action. Detailed documentation on rollup rules can be found in the UI-Element
Documentation on the Help menu.
Your script is displayed in the test case pane. It has two tabs, one for displaying the command and their
parameters in a readable “table” format.
The other tab - Source displays the test case in the native format in which the file will be stored. By default,
this is HTML although it can be changed to a programming language such as Java or C#, or a scripting
language like Python. See the Options menu for details. The Source view also allows one to edit the test case
in its raw form, including copy, cut and paste operations.
The Command, Target, and Value entry fields display the currently selected command along with its
parameters. These are entry fields where you can modify the currently selected command. The first
parameter specified for a command in the Reference tab of the bottom pane always goes in the Target field.
If a second parameter is specified by the Reference tab, it always goes in the Value field.
If you start typing in the Command field, a drop-down list will be populated based on the first characters you
type; you can then select your desired command from the drop-down.
Log/Reference/UI-Element/Rollup Pane
The bottom pane is used for four different functions–Log, Reference, UI-Element, and Rollup–depending on
which tab is selected.
Log
When you run your test case, error messages and information messages showing the progress are displayed
in this pane automatically, even if you do not first select the Log tab. These messages are often useful for test
case debugging. Notice the Clear button for clearing the Log. Also notice the Info button is a drop-down
allowing selection of different levels of information to log.
Reference
The Reference tab is the default selection whenever you are entering or modifying Selenese commands and
parameters in Table mode. In Table mode, the Reference pane will display documentation on the current
command. When entering or modifying commands, whether from Table or Source mode, it is critically
important to ensure that the parameters specified in the Target and Value fields match those specified in the
parameter list in the Reference pane. The number of parameters provided must match the number specified,
the order of parameters provided must match the order specified, and the type of parameters provided must
match the type specified. If there is a mismatch in any of these three areas, the command will not run
correctly.
While the Reference tab is invaluable as a quick reference, it is still often necessary to consult the Selenium
Reference document.
Detailed information on these two panes (which cover advanced features) can be found in the UI-Element
Documentation on the Help menu of Selenium-IDE.
2. Immediately pause the executing test case with the Pause button.
Stop and Start The Pause button can be used to stop the test case while it is running. The icon of this button
then changes to indicate the Resume button. To continue click Resume.
Stop in the Middle You can set a breakpoint in the test case to cause it to stop on a particular command. This
is useful for debugging your test case. To set a breakpoint, select a command, right-click, and from the
context menu select Toggle Breakpoint.
Start from the Middle You can tell the IDE to begin running from a specific command in the middle of the
test case. This also is used for debugging. To set a startpoint, select a command, right-click, and from the
context menu select Set/Clear Start Point.
Run Any Single Command Double-click any single command to run it by itself.
This is useful when writing a single command. It lets you immediately test a command you are constructing,
when you are not sure if it is correct. You can double-click it to see if it runs correctly. This is also available
from the context menu.
Test Suite:
A test suite is a collection of tests. Often one will run all the tests in a test suite as one continuous batch-job.
When using Selenium-IDE, test suites also can be defined using a simple HTML file. The syntax again is
simple. An HTML table defines a list of tests where each row defines the filesystem path to each test.
1. Consider an automated banking application. The user can dial the bank from a personal computer,
provide a six-digit password, and follow with a series of keyword commands that activate the
banking function. The software for the application accepts data in the following form:
Sample1.html
<html>
<head>
<script type="text/javascript">
function validation()
{
if(areavalidation())
{
if(prefixvalidation())
{
if(suffixvalidation())
{
if(passvalidation())
{
if(commandvalidation())
{
}
}
}
}
}
return false;
}
function passvalidation()
{
var a = document.form.pass.value;
if(a.match(paswd))
{
//alert("Correct, try another...") ;
return true;
}
else
{
alert("Wrong...! password should contain atleast one loweralphabet,one number,one specialcharacterand
length 6");
return false;
}
}
function suffixvalidation()
{
var b = document.form.suffix.value;
return true;
}
else
{
alert("Please suffixinput numeric characters only of length 4");
return false;
}
function areavalidation()
{
var c = document.form.area.value;
if(c.length==3)
{
return true;
}
else
{
alert("only enter numbers for area");
return false ;
}
}
else if(c.length<=0)
{
//alert(" u entered blank area code");
return true;
}
else
{
alert("area should be either balnk or three digit number");
return false;
}
}
function prefixvalidation()
{
var d = document.form.prefix.value;
return true;
}
else
{
alert("Please prefixinput numeric characters only of length 3 and not begin with 0 or 1");
return false;
}
}
function commandvalidation()
{
if( document.form.command.value == "-1" )
{
alert( "Please provide your command!" );
return false;
}
window.location = "main.html";
return true;
}
</script>
</head>
<body>
<form name="form" method="post" onsubmit="return validation()">
<tr>
<td> AreaCode:</td>
<td><input type="text" name="area""></td>
</tr>
<tr>
<td> prefix:</td>
<td><input type="text" name="prefix""></td>
</tr>
<tr>
<td> suffix:</td>
<td><input type="text" name="suffix""></td>
</tr>
<tr>
<td> password:</td>
<td><input type="text" name="pass""></td>
</tr>
<tr>
<td align="right">command</td>
<td>
<select name="command">
<option value="-1" selected>[choose yours]</option>
<option value="1">checkstatus</option>
<option value="2">deposit</option>
<option value="3">withdrawal</option>
</select>
</td>
</tr>
<tr>
main.html:
<html>
<body>
<p>
hii</p>
</body>
</html>
TEST CASES:
Test case 1: Areacode Blank
</tbody></table>
</body>
</html>
LOG:
</tbody></table>
</body>
</html>
Log:
[info] Playing test case Untitled
</tbody></table>
</body>
</html>
LOG:
[info] Playing test case Untitled
</tbody></table>
</body>
</html>
Log:
[info] Playing test case Untitled
</tbody></table>
</body>
</html>
LOG:
[info] Playing test case Untitled
</tbody></table>
</body>
</html>
LOG:
[info] Playing test case Untitled
Test case 7: SUFFIX THREE DIGIT NOT VALID & ONLY 4 DIGIT&PASSWORD NOT NULL
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="file:///home/aliet/sample.html" />
<title>New Test</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">New Test</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>file:///home/aliet/sample.html</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>name=suffix</td>
<td>123</td>
</tr>
<tr>
<td>click</td>
<td>name=sub</td>
<td></td>
</tr>
<tr>
<td>assertAlert</td>
<td>Please suffixinput numeric characters only of length 4</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>name=suffix</td>
<td>1234</td>
</tr>
<tr>
<td>click</td>
<td>name=sub</td>
<td></td>
</tr>
<tr>
<td>assertAlert</td>
<td>Please Enter Your Password</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
Test case 8: WITH OUT PREFIX VALUE GIVE SUFFIX VALUE 123:TEST SUTE
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="file:///home/aliet/sample.html" />
<title>New Test</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">New Test</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>file:///home/aliet/sample.html</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>name=suffix</td>
<td>123</td>
</tr>
<tr>
<td>click</td>
<td>name=sub</td>
<td></td>
</tr>
<tr>
<td>assertAlert</td>
<td>Please suffixinput numeric characters only of length 4</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>name=suffix</td>
<td>1234</td>
</tr>
<tr>
<td>click</td>
<td>name=sub</td>
<td></td>
</tr>
<tr>
<td>assertAlert</td>
<td>Please Enter Your Password</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
Log:
[info] Playing test case Untitled
</tbody></table>
</body>
</html>
Test case 10: provide at least one command and command sucessful:
</tbody></table>
</body>
</html>
screenshots:
EXPERIMENT 2:
Consider an automated banking application. The user can dial the bank from a personal computer,
provide a six-digit password, and follow with a series of keyword commands that activate the banking
function. The software for the application accepts data in the following form:
Design the test cases to test the system using following Black Box testing technique:
BVA, Worst BVA, Robust BVA, Robust Worst BVA, Equivalence class testing (Input/Output domain)
DESCRIPTION:
•
It is a Black Box testing/ Functional/Behavioral Testing technique
•
Objective of any Test Cases is to have max coverage and capability to discover more and more
errors.
•
Number of test cases generated in Boundary Value Analysis (BVA) for ‘n’ input variables is 4n+1.
•
Test cases for two input variables are 4(2)+1=9
1. Anom, Bmin
2. Anom, Bmin+
3. Anom, Bmax
4. Anom, Bmax-
5. Amin, Bnom
6. Amin+, Bnom
7. Amax, Bnom
8. Amax-, Bnom
9. Anom, Bnom
Given problem is
# AREA CODE -
Number of test cases generated in Boundary Value Analysis (BVA) for ‘n’ input variables is
= 4n+1
= 4(1)+1 [ Here, input variable is ‘1’ ]
=5
Test Suite is
TESTCASE:
</tbody></table>
</body>
</html>
Robust BVAMethod
Number of test cases generated in Robust BVA for ‘n’ input variables is
= 6n+1
= 6(1)+1 [ Here, input variable is ‘1’ ]
= 7
Test Cases for single input variable using Robust BVC are
min = 100
min- = 99
min+ = 101
max = 999
max- = 998
max+ = 1000
nominal value = 500-555
Test Suite is
Number of test cases generated in Worst Case BVA for ‘n’ input variables is
= 5n
= 51 [ Here, input variable is ‘1’ ]
= 5
Test cases in a Test Suite are same as that of BVC
# PREFIX -
Number of test cases generated in Boundary Value Analysis (BVA) for ‘n’ input variables is
= 4n+1
= 4(1)+1 [ Here, input variable is ‘1’ ]
=5
Test Cases for single input variable using BVC are
min = 200
min+ = 201
max = 999
max- = 998
nominal value = 500-555
Test Suite is
Test Case ID Input Value Expected Output
1 200 Valid Prefix
2 201 Valid Prefix
3 999 Valid Prefix
4 998 Valid Prefix
5 553 Valid Prefix
Number of test cases generated in Robust BVA for ‘n’ input variables is
= 6n+1
= 6(1)+1 [ Here, input variable is ‘1’ ]
= 7
Test Cases for single input variable using Robust BVC are
min = 200
min- = 199
min+ = 201
max = 999
max- = 998
max+ = 1000
nominal value = 500-555
Number of test cases generated in Worst Case BVA for ‘n’ input variables is
= 5n
= 51 [ Here, input variable is ‘1’ ]
= 5
</tbody></table>
</body>
</html>
# SUFFIXFIX -
Number of test cases generated in Boundary Value Analysis (BVA) for ‘n’ input variables is
= 4n+1
= 4(1)+1 [ Here, number of input input variable i.e n=1 ]
=5
min = 1000
min+ = 1001
max = 9999
max- = 9998
nominal = 5000-5555
Number of test cases generated in Robust BVA for ‘n’ input variables is
= 6n+1
= 6(1)+1 [ Here, input variable is ‘1’ ]
= 7
Test Cases for single input variable using Robust BVC are
min = 1000
min- = 999
min+ = 1001
max = 9999
max- = 9998
max+ = 10000
nominal value = 5000-5555
Number of test cases generated in Worst Case BVA for ‘n’ input variables is
= 5n
= 51 [ Here, input variable is ‘1’ ]
= 5
</tbody></table>
</body>
</html>
# PASSWORDWORD
Number of test cases generated in Boundary Value Analysis (BVA) for ‘n’ input variables is
= 4n+1
= 4(1)+1 [ Here, input variable is ‘1’ ]
=5
Robust BVAMethod
Number of test cases generated in Robust BVA for ‘n’ input variables is
= 6n+1
= 6(1)+1 [ Here, input variable is ‘1’ ]
= 7
Test Cases for single input variable using Robust BVC are
Total number of Test Cases in Test Suite for the range [0-9] is
Number of test cases generated in Worst Case BVA for ‘n’ input variables is
= 5n
= 51 [ Here, input variable is ‘1’ ]
= 5
command:
InputRage:[checkstatus,deposit,withdrawal]
Testcaseid Inputvalue expectedOutput
1 checkstatus Valid command
2 deposit Valid command
3 withdrawal Valid command
4 chooseoption Invalid command
# EQUIVALENCE CLASSES
DESCRIPTION:
Equivalence partitioning testing is a software testing technique which divides the application input test data
into each partition at least once of equivalent data from which test cases can be derived as shown in the
below diagram. By this testing method it reduces the time required for software testing.
PROCEDURE:
The number of Classes generated using Equivalence class technique for the given problem is
Aim:
Generate test cases using Black box testing technique to Calculate Standard Deduction on Taxable
Income. The
standard deduction is higher for tax payers who are 65 or older or blind. Use the method given below to
calculate tax.
1. The first factor that determines the standard deduction is the filing status. The basic standard deduction for
the various filing status are:
Single $4,750
Married, filing a joint return $9,500
Married, filing a separate return $7,000
2. If a married couple is filing separate returns and one spouse is not taking standard Deduction, the other
spouse also is not eligible for standard deduction.
3. An additional $1,000 is allowed as standard deduction, if either the filer is 65 yrs or the spouse is 65 yrs or
older(the latter case applicable when the filing status is “Married” and filing “joint”).
4. An additional $1,000 is allowed as standard deduction, if either the filer is blind or the spouse is blind (the
latter case applicable when the filing status is “married” and filing “joint”).
(HINT):
From the above description, it is clear that the calculation of standard deduction depends on the following 3
factors:
1. Status of filing of the filer
2. Age of the filer
3. Whether the filer is blind or not
In addition, in certain cases, the following additional factors also come into play in calculating the standard
deduction.
1. Whether spouse has claimed standard deduction
2. Whether spouse is blind
3. Whether the spouse is more than 65 years old
Source Code:
import java.util.Scanner;
double grossIncome;
int numApplicants;
double taxableIncome;
double STANDARD_DEDUCTION=0;
double incomeTax;
String status;
String accstatus;
String ph;
String sd;
int age1,age2;
if(status.equals("single"))
{
STANDARD_DEDUCTION = 4750.0;
System.out.println(STANDARD_DEDUCTION);
}
else
{
System.out.print("Enter the account status joint/separate: ");
accstatus = reader.next();
if(accstatus.equals("joint"))
{
Output
Test case 1:
Tax payer is single
Test case 2:
Tax payer is married, filing separate returns, spouse is taking standard deduction
Test case 3:
Tax payer is married, filing separate returns, spouse is not taking standard deduction
Test case 4:
Tax payer is married, filing joint returns, filer’s age>65
Test case 5:
Tax payer is married, filing joint returns, spouse’s age>65
Test case 6:
Tax payer is married, filing joint returns, filer/spouse age is not greater than 65
Test case 8:
Tax payer is married, filing joint returns, spouse is blind
Test case 9:
Tax payer is married, filing joint returns, filer is blind
Solution:
Cyclomatic Complexity:
V(G) = E - N + 2
Where,
E - Number of edges
N - Number of Nodes
From the above graph,
No. Of edges (E)=12
No. Of nodes(N)=10
Cyclomatic Complexity = E-N+2
=12-10+2
=4
Paths:
1) 0-1-2-3-8-9
2) 0-1-2-4-8-9
3) 0-1-5-6-8-9
4) 0-1-5-7-8-9
EXPERIMENT 06 :
Source code of simple insertion sort implementation using array in ascending order in c programming
language
#include<stdio.h>
int main()
{
int i,j,s,temp,a[20];
Printf ("Enter total elements: ");
Scanf ("%d",&s);
printf("Enter %d elements: ",s);
for(i=0;i<s;i++)
scanf("%d",&a[i]);
for(i=1;i<s;i++)
{
temp=a[i];
j=i-1;
while((temp<a[j])&&(j>=0))
{
a[j+1]=a[j];
j=j-1;
}
a[j+1]=temp;
}
printf("After sorting: ");
for(i=0;i<s;i++)
printf(" %d",a[i]);
return 0;
}
HINT: for loop is represented as while loop
a) Draw the program graph for given program segment
b) Determine the DD path graph
c) Determine the independent paths
d) Generate the test cases for each independent path
Solution:
Consider a system having an FSM for a stack having the following states and transitions:
States
Initial: Before creation
Empty: Number of elements = 0
Holding: Number of elements > 0, but less than the maximum capacity
Full: Number elements = maximum
Final: After destruction
Initial to Empty: Create
Empty to Holding, Empty to Full, Holding to Holding, Holding to Full: Add
Empty to Final, Full to Final, Holding to Final: Destroy
Holding to Empty, Full to Holding, Full to Empty: Delete
Design test cases for this FSM using state table-based testing.
Given the following fragment of code, how many tests are required for 100% decision
coverage? Give the test cases.
Source Code:
import java.util.Scanner;
double width;
double length;
double height;
double bigdimension;
Output:
Test case1: width>length && Width>height
L=6,w=9,h=5 9 9 success
Given the following code, how much minimum number of test cases is required for full
statement and branch coverage?
read p read q
if p+q> 100
then print "Large" endif
if p > 50
then print "p Large" endif
Hint 1 test for statement coverage, 2 for branch coverage
Solution:
Statement Coverage:
In this the test case is executed in such a way that every statement of the code is executed at least
once.
Branch/Decision Coverage:
Test coverage criteria requires enough test cases such that each condition in a decision takes on all
possible outcomes at least once, and each point of entry to a program or subroutine is invoked at
least once. That is, every branch (decision) taken each way, true and false. It helps in validating all
the branches in the code making sure that no branch leads to abnormal behavior of the application
Path Coverage:
In this the test case is executed in such a way that every path is executed at least once. All possible
control paths taken, including all loop paths taken zero, once, and multiple (ideally, maximum)
items in path coverage technique, the test cases are prepared based on the logical complexity
measure of a procedural design. In this type of testing every statement in the program is guaranteed
to be executed at least one time. Flow Graph, Cyclomatic Complexity and Graph Metrics are used
to arrive at basis path
Example:
Read P
Read Q
IF P+Q > 100 THEN
Print “Large”
ENDIF
If P > 50 THEN
Print “P Large”
ENDIF
Statement Coverage (SC):
To calculate Statement Coverage, find out the shortest number of paths following which all
the nodes will be covered. Here by traversing through path 1A-2C-3D-E-4G-5H all the nodes are
covered. So by traveling through only one path all the nodes 12345 are covered, so the Statement
coverage in this case is 1.
Branch Coverage (BC):
To calculate Branch Coverage, find out the minimum number of paths which will ensure
covering of all the edges. In this case there is no single path which will ensure coverage of all the
edges at one go. By following paths 1A-2C-3D-E-4G-5H, maximum numbers of edges (A, C, D, E,
G and H) are covered but edges B and F are left. To covers these edges we 3 www.ajoysinigha.info
can follow 1A-2B-E-4F. By the combining the above two paths we can ensure of traveling through
all the paths. Hence Branch Coverage is 2. The aim is to cover all possible true/false decisions.
Path Coverage (PC):
Path Coverage ensures covering of all the paths from start to end.
All possible paths are-
1A-2B-E-4F
1A-2B-E-4G-5H
1A-2C-3D-E-4G-5H
1A-2C-3D-E-4F
So path coverage is 4.
Thus for the above example SC=1, BC=2 and PC=4.