Subscribe by Email


Showing posts with label Simple Loops. Show all posts
Showing posts with label Simple Loops. Show all posts

Saturday, May 19, 2012

Explain simple loops in detail?


Loops are such an important programming constructs for various object oriented languages that they cannot be neglected. All of us are aware of the looping constructs that we have in programming languages like C and C++. We have three basic loops:
  1. For loop
  2. While loop
  3. Do while loop

Why Loops are Important?


- Loops find extensive use in programming and they are a means to tell the program to keep executing a set of statements until some break condition is encountered.
- Loops come to be a very handy tool when it comes to the repetition of the whole block of code. 
- It can be done to reduce the length of the code and the task of the programmer or developer of writing the same code again and again innumerable times. 
- In some cases it also happens that the number of times for which the loop is to be executed is obtained from the user, in such cases looping of the particular block of code becomes extremely important. 
-There are many software programs or applications that perform very complex tasks or calculations all by the virtue of the looping constructs. 

Before taking on the loops in to your software program you should be well versed with the true and false concept of the programming language that you are using. Let us discuss all the above mentioned three loops one by one:

                1.  For Loop: 
               Here’s the syntax of the for loop:

For (initialization of the variable; test condition; increment condition)
{
Statement 1;
Statement 2; (code to be executed)
.
.
.
Statement n;
}
In the expression for the initialization of the variable one can declare the variable for the loop and initialize it with the required value. Secondly the test condition is responsible for checking the whether the loop should be executed or not on the basis of the true or false value. The increment condition lastly helps the loop to increment the value of the initialized variable. All of these 3 expressions are separated from each other by semicolon. An empty condition is evaluated to false value.

2. While Loop: 
Here’s the syntax for the while loop:

While( test condition)
{
Statement 1;
.
.
Statement n;
}
According to some programmers the while loops are perhaps the easiest to operate. While loops are supposed to be entry controlled loop since the condition is checked up on the entry itself and based on its true value it is executed. While loops are somewhat like the for loops except that they contain the initialization expression and the update expression inside their body. But the drawback with this loop is that it is quite length. This loop won’t allow the execution of the statements even once if the test condition is evaluated to be false.
      
          3. Do while loop
          Here’s the syntax for the do – while loop:
Do
{
Statement 1;
Statement 2;
.
.
.
Statement n;
} while (test condition)
This loop holds good for the programs in which the execution of a particular block of statements is required at least once irrespective of whether the test condition is true or false. The test condition is encountered in the last and is evaluated. If it is found to be false, then the loop won’t be eligible for a second iteration. Because of this factor the do while loop is commonly known as the exit controlled lop. 


Thursday, May 17, 2012

Explain concatenated loops in detail?


Loops as we all know are quite an essential programming constructs in the program that involve solving the complex problems with the repetition of the simple statements. With the loops it has been possible to reduce the drudgery of the programmers and developers of writing the same code again and again innumerable number of times. Everyone is familiar with the three types of loops namely:
   (i)  For loop
   (ii) While loop and lastly
   (iii) The do while loop
Based up on the structure of the loops, they have been categorized as mentioned below:
   (i)  Structured loops and
   (ii) The unstructured loops

There are various kinds of other loops like the nested loops and simple loops. Yet there is one more kind of loops that we are going to discuss in this article namely “the concatenated loops”. Before going to the discussion regarding the concatenated loops let us clear up with the meaning of the concatenation. 

What is meant by Concatenation and Concatenated Loops


- To concatenate means to join two things mostly statements or words or strings together end by end to make them in to one single statement, word or string respectively as the case may be. 
- Concatenated loops are the loops that occur in following to the preceding loop in the code of the program.
- The execution of the next loop begins only after the termination of the previous loop. 
Concatenated loops are usually found to be the independent loops since the number of times they have to be iterated does not depends on the iterations of any other loop.
- They are treated normally as the other simple loops in the sequence.

Guidelines for testing concatenated loops


For testing these loops separate guidelines are followed rather than the simple loops.
- For the first and the last loop in the concatenated sequence, simple loop tests are conducted at the minimum possible values. 
- For the successive loops also the simple loop tests are carried out and keeping minimal values for the upper loops and typical values for the lower loops.
- Loop concatenation along with another looping technique called loop replication is used for increasing the network capacity. 
- The above mentioned approach is to be used only if the concatenated loops are found to be independent loops.
- If they are not found to be independent than the nested approach for testing is to be followed. 
- If there are two concatenated loops say loop 1 and loop 2 and if the loop counter of the loop1 is used as the initial value for the loop 2 or vice versa, then the loops are not said to be independent. 

More about Concatenated Loops


- The concatenated loops are quite easy to maintain as compared to the other types of loops except the simple loops.
- Concatenated loops form the basis of most of the program algorithms.
- The testing of these loops is carried out in accordance with the white box testing techniques. 
- The testing techniques are applied based up on the validity of the loop constructs.
- It depends up on the programmer whether the loops are tested independently or in groups. 
- The following tests can be applied to the concatenated loops:
  1. Skipping of the entire loop
  2. Giving one pass to the loop
  3. Giving m passes to the loop where the m is less than n.
  4. Giving, n, n + 1, n – 1 passes through the loop.
In the third test the n is the number of maximum passes allowed for the loop.


Monday, April 23, 2012

How does a loop free path segment play a role in data flow testing?


The loop free path segments form a very important terminology in the path of data flow testing. But many of us are not well familiar with the concept of loop free path segments and the role that they have got to play in the data flow testing or path testing. In this article we have tried to explain in the easiest way possible the concept of the loop free path and the role it plays in the data flow testing. 

Before taking up the topic of the loop free path segment and its role in data flow testing we shall discuss a little about the data flow testing. 

The control flow graph is the best tool that the data flow testing can use in exploring all the weird or unreasonable things that can affect the data objects. These weird and unreasonable things are nothing but the anomalies.

Till now nine types of anomalies have been defined as mentioned below:

  1. dd: harmless but suspicious
  2. dk: might be a bug
  3. du: a normal case
  4. kd: a normal situation
  5. kk: harmless but might be containing bugs
  6. ku: a bug or error
  7. ud: not a bug because of re- assignment
  8. uk: a normal situation
  9. uu: a normal situation
 - If these anomalies are taken in to consideration, one can develop very effective and reliable path selection strategies which can be then used in filling the gaps that are present in between the branch testing and the complete path testing. 
- The strategies that are followed for carrying out a data flow test are based up on the selection of the paths via the flow of control of the software system or application.
- These path selection strategies are quite useful when it comes to exploring the sequences of the events that are in a way related to the status of the data objects. 
- The paths are so selected that they cover up all the objects, i.e. they ensure the initialization of each and every data object before it is used in the program and also that they are used for a minimum of one time. 

Categories of Data Objects


- The data objects have been categorized in to three different categories for making the path selection process easier:
  1. Defined, created, initialized (d)
  2. Killed, undefined, released (k)
  3. Used:
(a)    In calculations (c)
(b)   In predicates (p)

- An object is said to be defined whenever it has an occurrence in a data declaration or is assigned with a new value or is dynamically allocated. 
- On the other hand an object is said to be used whenever it becomes a part of a predicate or a calculation. - The anomaly detection process relies heavily on the following two anomaly detection techniques:
  1. Static anomaly detection (responsible for syntax errors) and
  2. Dynamic anomaly detection (responsible for logical errors).

What are Loop Free Path Segments


- Now coming to the loop free path segments, this is a terminology that is usually used under the context of the data flow modelling. 
- Loop free path segments are discovered using the control flow graph.
- The loop free path segments are basically a derivative of the simple path segments.
- It depends on the simple path segment that whether or not it is a loop free path segment also. 
- If the simple path segment consisting of two nodes A and B is having loop in both the nodes, then it cannot be called as a loop free path. 
- Loop free paths are the simple paths segments consisting of loop only in one of the either nodes.


How does a simple path segment play a role in data flow testing?

Whenever you have discussed about the data flow testing you must have came across the term simple path segments while discussing about the strategies for data flow testing. Many of us are not quite clear with the concept of the simple path segments and what role have they got to play in the data flow testing. This article is all about the simple path segments and the role that they have got to play in the data flow testing. 

First we shall brief up ourselves with the concepts of the data flow testing before moving on to the topic of the simple path segments and their role. 

What is Data Flow Testing


- Data flow testing includes all those strategies that have been based up on the selection of the paths via the control flow of the program for discovering the sequence in which the events related to the object’s status take place.

- A primary bug assumed during the data flow testing is that though the control flow is generally correct, there is some fault with the software system or application since the data objects are not available when they are supposed to be or weird things happen to the data objects. 

- Even if some problem is found to preside in the control flow of the program it is initially detected by the data flow analysis. 

- One of the most aiding tool in the data flow testing are the control flow graphs which are the graphs consisting of directed links and nodes. 

- The objective of the data flow testing is to discover the deviations in the data flow. Three types of data objects have been defined namely:


  1. Killed or undefined
  2. Defined
  3. Usage
And some nine kinds of anomalies have been defined:

  1. dd: harmless but suspicious
  2. dk: might be a bug
  3. du: a normal case
  4. kd: a normal situation
  5. kk: harmless but might be containing bugs
  6. ku: a bug or error
  7. ud: not a bug because of re- assignment
  8. uk: a normal situation
  9. uu: a normal situation
These anomalies are detected by the means of two anomaly detection techniques namely:

  1. static anomaly detection technique and
  2. dynamic anomaly detection technique
All the strategies involved in the process of data flow testing are structural. Data flow testing and path testing strategies have so many things in common. But one of difference between them is made by what one takes in to account for testing. Path and data flow testing both are emphasized up on the raw connectivity of the graph but in addition to this the data flow testing also focuses up on what happens to the data objects. There are so many terminologies associated with the data flow testing and simple path segment is one of them. The others are:

  1. definition clear path segment
  2. loop free path segment
  3. du path segment

What is Simple Path Segment


We shall now define what a simple path segment is! 

- Any path in which the same node is visited twice at the most, such a path is called a simple path segment. 
- One can easily make out why a simple path segment is called so! 
- It is called so because it does not consists of loops in both the nodes.
- Only one node holds the loop. 
- One of the problems that are faced by the testers is of finding the simple paths. 
- This problem can be overcome by following a lower bound max- flow approach. 
- The simple path segments though being, are important in the data flow testing just like all the other path segments. 


Thursday, March 22, 2012

Loop testing is a white box testing technique - Explain?

Loop testing is also one of the white box testing techniques and thus requires a very deep knowledge about the software system or application. Loop testing methodology has been designed exclusively for the checking of the validation of the iterative constructs which are nothing but the loops.

Types of Loop Constructs
These loop constructs are 4 types as mentioned below:
1. Unstructured loops
2. Simple loops
3. Nested loops and
4. Concatenated loops

Tests applied to different Loop Constructs
Now we shall define some of the tests that can be applied to the above mentioned types of loop constructs under the context of the loop testing:

1. For unstructured loops only one thing is possible which is that they should be redesigned in order to form a structured construct and then can be tested accordingly.

2. For simple loops a number of allowable passes through them is specified first and then the following tests are applied:

(a) Skipping of the entire loop.
(b) Making only one pass through the loop.
(c) Making two passes through the loop.
(d) Making “p” passes through the loop where p is the maximum number of passes.
(e) Making “n-1”, “n”, “n+1” passes through the loop.

3. For nested loops simply the testing approach of the simple loops is extended but, the number of the test cases increases geometrically as per the number of the nested loops and the level of nesting. Usually the following steps are followed:

(a) The inner most loop is the starting point for the testing.
(b) All other loops are set to minimum possible values.
(c) Simple loop tests are conducted for the inner most loop and the outer loops or the nesting loops are kept in their minimum values only till the testing of the inner most loop is complete.
(d) For the excluded values more tests are added.
(e) Now once the testing of the inner most loop is complete, this loop including all the other nested loops are set to typical values and the testing moves outwards. The other nesting loops are held with their minimum values.
(f) The testing in this manner continues until and unless all the loops have been tested.

4. For concatenated loops also the approach that has been defined for the testing of the simple loops can be used but only if the either loops are independent of each other i.e., if the loop counter for one of concatenated loop is 1 and it is used as the executing value for the other loop, then the two loops are said to be dependent on each other and hence the simple loop approach cannot be followed for them.

More about Loop Testing

- It has been observed so many times that most of the semantic bugs preside over the loops.

- It becomes difficult for the path testing also to commence since there are so many paths generated via a loop and an infected loop leads to infected paths which makes even further difficult to track the bug.

- Some of testers believe that it is just enough to test the loop only two times but this is not a good practice.

- A loop should be tested at the following three instances:
a) At the entry of the loop
b) During the execution of the loop and
c) At the exit of the loop

- Loop testing is aimed at testing a resource multiple numbers of times by executing it under a loop and this whole process is controlled by a diagnostic controller.

- However, one rule has been defined for the loop testing which is that the user can interact only at the entry and exit of the loop and nowhere in between.


Saturday, October 9, 2010

Loop testing - a white box testing technique and types of loop testing.

Loop testing is a kind of white box testing technique that focuses exclusively on the validity of loop constructs. Four classes of loops can be defined: Simple loops, Concatenated loops, Nested loops, and unstructured loops.

- Simple Loops: The following sets of tests can be applied to simple loops, where 'n' is the maximum number of allowable passes through the loop.
a) Skip the loop entirely.
b) Only one pass through the loop.
c) Two passes through the loop.
d) 'm' passes through the loop where m < n.
e) n-1,n,n+1 passes through the loop.

- Nested Loops: If we extend the test approach from simple loops to nested loops, the number of possible tests would grow geometrically as the level of nesting increases.
a) Start at the innermost loop. Set all other loops to minimum values.
b) Conduct simple loop tests for the innermost loop while holding the outer loops at their minimum iteration parameter values. Add other tests for out-of-range or exclude values.
c) Work outward, conducting tests for the next loop, but keep all other outer loops at minimum values and other nested loops to typical values.
d) Continue until all loops have been tested.

- Concatenated Loops: These loops can be tested using the approach defined for simple loops,If each of these loops is independent of the other. However, if two loops are concatenated and the loop counter for loop one is used as the initial value for loop two, then the loops are not independent.

- Unstructured Loops: Whenever possible, this class of loops should be redesigned to reflect the use of the structured programming constructs.


Facebook activity