BCS - Software Engineering - Short note04092015.docx
Dry
Run
•
You can test your program without
using a computer by dry running it on paper
•
You act as the computer – following
the instructions of the program, recording the valves of the variables at each
stage
•
You can do this with a table
•
The table with have column headed
with the names of the variables in the program
•
Each row in the table will be
labelled with a line number form the program.
•
The entries of each row in th e table
will be values of the variables after the execution of the statement on that
line
•
You don’t need a row for every line
in the program, just those lines where some significant change to the state of
the program occurs e.g a variable gets a new value
•
In this table you can record all
relevant changes to the variables as the program progresses, thereby test the
logic of the program / algorithm
•
Do a dry run before you code your
program on computer this way any logic errors will come to light during the dry
run
•
L1
Declare two variables , first num second num
•
L2
Initialise both variables to 0
•
L3
first num = 0 second num = 0
•
L4
Ask user to enter first number
•
L5
Assign user input to first num variable
•
L6
Ask user to enter second number
•
L7
Assign user input to second num variable
•
L8
Add first num to second num
•
L9
Print result
•
Do a Dry run for this program
assuming the user enters 17 for first number and 24 for the second
|
After
execution
|
First num
|
Second num
|
Result
|
|
Line 2
|
0
|
0
|
|
|
Line 5
|
17
|
0
|
|
|
Line 7
|
17
|
24
|
|
|
Line 8
|
17
|
24
|
41
|
White
box testing
1. White-box testing (also
known as clear box testing, glass box testing,
transparent box testing, and structural testing) is a
method of testing software that tests internal
structures or workings of an application, as opposed to its functionality (i.e.
black-box testing).
2.
4.
|
Criteria
|
Black Box Testing
|
White Box Testing
|
|
Definition
|
Black Box Testing is a software testing
method in which the internal structure/ design/ implementation of the item
being tested is NOT known to the tester
|
White Box Testing is a software testing
method in which the internal structure/ design/ implementation of the item
being tested is known to the tester.
|
|
Levels Applicable To
|
|
|
|
Responsibility
|
Generally, independent Software Testers
|
Generally, Software Developers
|
|
Programming Knowledge
|
Not Required
|
Required
|
|
Implementation Knowledge
|
Not Required
|
Required
|
|
Basis for Test Cases
|
Requirement Specifications
|
Detail Design
|
Sorting
algorithms
|
|
|
Bubble Sort
|
In the bubble sort, as
elements are sorted they gradually "bubble" (or rise) to
their proper location in the array, like bubbles rising in a glass of
soda. The bubble sort repeatedly compares adjacent elements of an array. The first
and second elements are compared and swapped if out of order.
Then the second and third elements are compared and swapped if out of
order. This sorting process continues until the last two elements
of the array are compared and swapped if out of order.
|
|
When
this first pass through the array is complete, the bubble sort returns
to elements one and two and starts the process all over again.
So, when does it stop? The
bubble sort knows that it is finished when it examines the entire array
and no "swaps" are needed (thus the list is in proper order). The bubble sort keeps
track of the occurring swaps by the use of a flag.
The table below follows an array of numbers before, during, and after a
bubble sort fordescending order. A "pass"
is defined as one full trip through the array comparing and if
necessary, swapping, adjacent elements. Several
passes have to be made through the array before it is finally
sorted.
|
|
Array
at beginning:
|
84
|
69
|
76
|
86
|
94
|
91
|
|
After
Pass #1:
|
84
|
76
|
86
|
94
|
91
|
69
|
|
After
Pass #2:
|
84
|
86
|
94
|
91
|
76
|
69
|
|
After
Pass #3:
|
86
|
94
|
91
|
84
|
76
|
69
|
|
After
Pass #4:
|
94
|
91
|
86
|
84
|
76
|
69
|
|
After
Pass #5 (done):
|
94
|
91
|
86
|
84
|
76
|
69
|
The bubble sort is an easy
algorithm to program, but it is slower than many other sorts. With
a bubble sort, it is always necessary to make one final "pass"
through the array to check to see that no swaps are made to ensure that
the process is finished.
|
|
|
|
|
|
|
Exchange
Sort
|
The exchange sort is
similar to its cousin, the bubble sort, in that it compares elements of
the array and swaps those that are out of order. (Some people
refer to the "exchange sort" as a "bubble
sort".) The difference between these two sorts is the manner
in which they compare the elements. The
exchange sort compares the first element with each following element of
the array, making any necessary swaps.
|
When the first pass through the
array is complete, the exchange sort then takes the second element and
compares it with each following element of the array swapping elements that
are out of order. This sorting process continues until the entire
array is ordered.
Let's examine our same table of
elements again using an exchange sort for descending order.
Remember, a "pass" is defined as one full trip through the
array comparing and if necessary, swapping elements
|
Array
at beginning:
|
84
|
69
|
76
|
86
|
94
|
91
|
|
After
Pass #1:
|
94
|
69
|
76
|
84
|
86
|
91
|
|
After
Pass #2:
|
94
|
91
|
69
|
76
|
84
|
86
|
|
After
Pass #3:
|
94
|
91
|
86
|
69
|
76
|
84
|
|
After
Pass #4:
|
94
|
91
|
86
|
84
|
69
|
76
|
|
After
Pass #5 (done):
|
94
|
91
|
86
|
84
|
76
|
69
|
|
|
|
|
|
|
Selection Sort
|
The selection sort is a combination of
searching and sorting.
During each pass, the unsorted element with
the smallest (or largest) value is moved to its proper position in the
array.
The number of times the sort passes through the array is one less
than the number of items in the array. In the selection sort, the
inner loop finds the next smallest (or largest) value and the outer loop
places that value into its proper location.
Let's look at our same table of
elements using a selection sort for descending order. Remember, a
"pass" is defined as one full trip through the array comparing
and if necessary, swapping elements.
|
|
|
|
Array at beginning:
|
84
|
69
|
76
|
86
|
94
|
91
|
|
After Pass #1:
|
84
|
91
|
76
|
86
|
94
|
69
|
|
After Pass #2:
|
84
|
91
|
94
|
86
|
76
|
69
|
|
After Pass #3:
|
86
|
91
|
94
|
84
|
76
|
69
|
|
After Pass #4:
|
94
|
91
|
86
|
84
|
76
|
69
|
|
After Pass #5 (done):
|
94
|
91
|
86
|
84
|
76
|
69
|
|
|
|
|
Insertion
Sort
|
The insertion sort, unlike the other
sorts, passes through the array only
once. The insertion
sort is commonly compared to organizing a handful of playing cards.
You pick up the random cards one at a time. As you pick up each
card, you insert it into its correct position in your hand of organized
cards.
The insertion sort splits an array into two sub-arrays. The first
sub-array (like the cards in your hand) is always sorted and increases in
size as the sort continues. The second sub-array (like the cards to be
picked up) is unsorted, contains all the elements yet to be inserted into
the first sub-array, and decreases in size as the sort continues.
|
|
Let's look at our same example
using the insertion sort for descending order.
|
|
Array at beginning:
|
84
|
69
|
76
|
86
|
94
|
91
|
|
|
84
|
69
|
76
|
86
|
94
|
91
|
|
|
84
|
69
|
76
|
86
|
94
|
91
|
|
|
84
|
76
|
69
|
86
|
94
|
91
|
|
|
86
|
84
|
76
|
69
|
94
|
91
|
|
|
94
|
86
|
84
|
76
|
69
|
91
|
|
2nd sub-array empty
|
94
|
91
|
86
|
84
|
76
|
69
|
|
The insertion sort maintains the two sub-arrays within the same
array. At the beginning of the sort, the first element of the first
sub-array is considered the "sorted array". With each
pass through the loop, the next element in the unsorted second sub-array
is placed into its proper position in the first sorted sub-array.
The insertion sort can be very
fast and efficient when used with smaller arrays. Unfortunately, it
loses this efficiency when dealing with large amounts of data
|
|
|
|
|
|
|
|
|
No comments:
Post a Comment