Subscribe by Email


Showing posts with label Loop testing. Show all posts
Showing posts with label Loop testing. 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. 


Friday, May 18, 2012

Explain unstructured loops in detail?


Loops are one of the most important of the languages like C and C++. They have greatly reduced the drudgery of the programmers and developers which would otherwise have made the programming of a software system or application more hectic. The necessity of the loops cannot be ignored when it comes to the repetition of a particular executable statement or a block of statements in a program. 

In other words,
Say we have the below written statement in C++ programming language that we need to print only one time:
“hello! Welcome to C++ programming”
To print it one time we shall write the code like this:
Cout<<”hello! Welcome to C++ programming\n”;
Say now you need to print this statement a 100 times! What you are going to do- write the above C++ statement a 100 times? No! Certainly not! This is unfeasible and a complete waste of time! So what is the alternative that we have? Yes of course we have the “loops”. 
Using loop we will have to write only a small code instead of writing that C++ statement again and again for 100 times. Using loop we shall write like this:

For( int i = 1; i <=100; i++ )
{
Cout<<”hello! Welcome to C++ programming\n”;
}

The above loop is a for loop and it will the statement that we wish to be printed 100 times. See to how much extent our task has been reduced! This would not have been possible without loops. 

Loops generally are classified based on their types namely in to:
  1. The while loop
  2. The for loop
  3. The do – while loop
But based up on their structure, they are classified in to two types:
  1. Structured loops and
  2. Unstructured loops
This article is all about the unstructured loops. We shall discuss them in detail. 

The Unstructured Loops


- The unstructured loops can be defined as the loops that are void of a single header or a node in the control flow graph that has all the nodes dominating the whole loop body. 
- The main problem that arises with these unstructured loops is of managing them.
- Managing them is such a hectic task.
- For analyzing the unstructured loops the programmers, developers and researchers have come up with so many ways but none of them seems to be so efficient.
- One of the ways is to use a control flow graph along with the scope graph corresponding to the function containing the unstructured loop to be analyzed. 
- This method involves attaching of each and every iteration counter with each of the loop header.
- Attaching the iteration counters in such a way can cause over estimation of the control flow. 
- So to overcome this problem, the iteration counters are attached to each basic block and this helps a great deal in achieving a lot of flow information. Even this way results in some disadvantage! 
Therefore another method of managing the unstructured loops has been developed. 
- Another method has been developed for transforming the unstructured loops in structured ones. 
- If one looks at the unstructured loop with a view of the control flow graph they seem to have entry edges to one or more than one node all over the loop. 
- In another way we can say that an unstructured consists of parts of several different loops. 
Several structured loops can also be merged in to an unstructured loop with the help of a code size optimizing compiler.
- A straight way has been developed for the elimination of the unstructured loops which is creating a scope with a single header for each entry of the loop. 


Thursday, May 17, 2012

Explain nested loops in detail?



Why Loops are Important?


- Loops are an extremely important entity when it comes to the programming in languages like C and C++ i.e., to say the object orient languages. 
Loops are used to handle many other program constructs and execute the same statement or a block of statement as many times as required by the program or as specified by the user.
- Loops are either manually included in to the source code of the program or are generated in to the code by the state machine code generators or by an optimizing compiler. 

There are various types of loops but this article is limited only to the discussion regarding the nested loops. Let us see what the nested loops in detail are.
What the phrase “to nest” means?  
It means to keep one object inside the other object.  This holds good when it comes to the context of the loops also. All the types of loops can be nested in to the similar types of loops irrespective of their type.

What are Nested Loops?


- Nested loops are the loops that have been declared inside another loop which may or may not be of the same type as that of the nested loop.
- The loop which is placed inside the another loop is called the nested loop and the loop which holds this nested loop is called the parent loop.
- It is not necessary that the nested loop and the parent loop should be of similar types.
- Nesting the loops falls under the context of combining the looping procedures.
- Whenever a loop is nested, its parent loop is said to take the control of it that is the parent loop decides how many times the inner loop is to be executed. 
- Although the nesting holds good for all the types of loop, it is the for loop that dominates the line. - Once the parent loop has been iterated once, the control is transferred to the inner loop.
- After this the parent loop iterates for a second time only when the execution and iteration of the inner loop is wholly complete. 
- To say it other way round, the inner or the nested loop is triggered by the first pass of the outer or parent loop which is then executed to completion. 
- Then, the inner loop is again triggered by the second pass of the parent loop which is then executed till its complete iteration.
- This process continues till the test condition for the outer parent loop is evaluated to a false value. - If a break statement has been incorporated inside the inner loop then it may come out of the loop before all the iterations of the outer loop are complete. 
- The continue and the break commands are the two commands affecting the behavior of the both nested loops and the outer parent loops. 

Basically the nested loops find their use in the problems that involve working with matrices. Let us illustrate the working of nested with the help of the code written below:

// this code has been written to accept elements in to a 3 x 3 matrix
For ( int r = 0; r < 3; r++)
{
For (int c = 0; c < 3; c++)
{
Scanf(“%d”, &A [r] [c]);
}
}
In the above written c code two loops have been used to accept the elements for a matrix among which one is nested in to the another. The variables r and c denote the rows and columns respectively. Nested loops can be thought of as a logical structures which consist of two repeating statements are placed in the nested that is one inside the other. 


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.


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.


Sunday, February 6, 2011

Control Structure Testing - Condition Testing, Data Flow Testing, Loop Testing

Control structure testing is a group of white-box testing methods.
CONDITION TESTING
- It is a test case design method.
- It works on logical conditions in program module.
- It involves testing of both relational expressions and arithmetic expressions.
- If a condition is incorrect, then at least one component of the condition is incorrect.
- Types of errors in condition testing are boolean operator errors, boolean variable errors, boolean parenthesis errors, relational operator errors, and arithmetic expression errors.
- Simple condition: Boolean variable or relational expression, possibly proceeded by a NOT operator.
- Compound condition: It is composed of two or more simple conditions, Boolean operators and parentheses.
- Boolean expression: It is a condition without Relational expressions.

DATA FLOW TESTING
- Data flow testing method is effective for error protection because it is based on the relationship between statements in the program according to the definition and uses of variables.
- Test paths are selected according to the location of definitions and uses of variables in the program.
- It is unrealistic to assume that data flow testing will be used extensively when testing a large system, However, it can be used in a targeted fashion for areas of software that are suspect.

LOOP TESTING
- Loop testing method concentrates on validity of the loop structures.
- Loops are fundamental to many algorithms and need thorough testing.
- Loops can be defined as simple, concatenated, nested, and unstructured.
- In simple loops, test cases that can be applied are skip loop entirely, only one or two passes through loop, m passes through loop where m is than n, (n-1), n, and (n+1) passes through the loop where n is the maximum number of allowed passes.
- In nested loops, start with inner loop, set all other loops to minimum values, conduct simple loop testing on inner loop, work outwards and continue until all loops tested.
- In concatenated loops, if loops are independent, use simple loop testing. If dependent, treat as nested loops.
- In unstructured loops, redesign the class of loops.


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.


Monday, November 23, 2009

Control Structure Testing : Loop testing

Loops are the basis of most algorithms implemented using software. However, often we do consider them when conducting testing. Loop testing is a white box testing approach that concentrates on the validity of loop constructs. Four loops can be defined: simple loops, concatenate loops, nested loops, and unstructured loops.

- Simple Loops, where n is the maximum number of allowable passes through the loop.
o Skip loop entirely.
o Only one pass through loop.
o Two passes through loop.
o m passes through loop where m o n-1, n, and n+1 passes through the loop.
- Nested Loops
o Start with inner loop. Set all other loops to minimum values.
o Conduct simple loop testing on inner loop.
o Work outwards.
o Continue until all loops tested.
- Concatenated Loops
o If independent loops, use simple loop testing.
o If dependent, treat as nested loops.
- Unstructured loops
o Don't test - redesign.

Types of Loop


Facebook activity