Arunkumar Khannur's Software Testing Knowledge Center
   
 

7.4. Properties Associated with Code

Quality of structural form of software is affected by two characteristics, viz., Correctness and Style. Correctness properties are focusing on extent to which structural forms are syntactically and semantically correct, where as, style properties focus on high and low level design, and the extent to which the software's functionality at all levels is specified, described, characterized and documented. Two characteristics- Correctness and Style along with their associated properties are represented in Fig. 4.1 Properties Associated with Code.
Correctness properties address characteristics that deal with the specification-independent minimum requirements for correctness

Style related properties have three categories: structural properties focus on low-level, intra-module design issues; modularity properties deal with high-level, inter-module design issues; descriptive properties focus on various forms of specification/documentation. Following sections describe: Correctness, Structural, Modularity, and Descriptive Properties.

7.4.1. Correctness Properties
Structural elements shall be checked for correctness properties. Table 7.1 Code - Correctness Properties presents each property along with description, applicable structure, and examples of defects in each property.

Table 7.1 Code - Correctness Properties
Property   Description   Applicable Structure or Code Construct   Examples of defects
Computable   Result obeys laws of arithmetic and also, hierarchy rules of programming rules are followed while making translation from mathematical expression into programming construct.   Expressions   Division by zero or other impossible computation
Subscript out-of-range
Writing to an unopened file
Division by a variable of unknown status
Square root of a negative number or number of unknown status
Complete   All the necessary elements of structural form are defined and implemented to fulfill its intended role in a way that will not impact reliability or functionality.   Objects, Modules, Statements   If-statements that may abort (language-specific) Self-assignment
( eg, a := a)
Unreachable code in a selection mechanism
Module that generates no output
Assigned   Variable given value by assignment, input, or parameter assignment prior to its use   Variables   Use of a variable in a term or expression that has not been previously assigned a value.
Precise   Adequate accuracy preserved in computations by providing appropriate length, number of spaces, digits before and after decimal point   Variables and Constants   Number of digits after decimal point
Selection of variable with a specific type to hold min and max value
Use of an integer when problem demands only in the range 0 . . 9.
Initialized   Assignments of initial value to a variable, constant, or index of loops   Loops and Constants   Underinitialized, or overinitialized of loop index Assigning value to constant
Progressive   Each branch/ iteration or recursive algorithm is progressive if there is clear evidence that the structure makes progress towards termination with each iteration or recursive call   Modules (recursive), Loops   Nested loop where outer loop variables are only changed and inner loop remains unchanged
Variant   Loop index whose value varies after each execution   Index variable (or guard) of Loops and Recursive Structures   Use of Boolean variable flag as a loop index
Consistent   No improper use or side effects in structural form   Modules, Statements, Guards, Expressions, Variables and Records   Using a variable for more than one purpose in a given scope
Modifying a loop variable on exit from a loop
Using a variable as a constant
Changing a variable in an expression (is a side-effect)
Unused input ( read(x); . . . : read(x) )
Output of a variable twice without change
Use of variables/constants of different precision/type in a computation

7.4.2. Structural Properties
In structured programming the composition of each of structural elements like statements, compound statements, loops and their nesting play an important role in ensuring better quality structure. Also, while structuring, one shall ensure no redundancy in logical, computational, representation and declaration. Also, there shall be no inefficiency. Also all statements shall be represented with proper naming convention, direct and simple to understand. Also, every declared structural form should be utilized.

These structural properties are summarized in Table 7.2 Code - Structural Properties along with details, structure to which applicable, and examples of defects.

Table 7.2 Code - Structural Properties
Property   Description   Applicable Structure or Code Construct   Examples of defects
Structured   Single-entry/single-exit   sequences, guards and expressions   • exit from the middle of a loop using gotos
• multiple returns from a function
• loop guard with too many conditions
Resolved   A structural form is resolved if the data structure/control structure matches the structure of the data or the problem   loops   • use of a single loop to process a two-dimensional array
Homogeneous   Only conjunctive invariants for loops   loops, recursive modules   ̺ a loop structure with functionality that is not cohesive
Effective   No computational redundancy with structural forms formed by all and required elements only.   expressions, statements   • Expression with unnecessary initiation x := x.
• Unnecessary computation a := a +1+1
Non-redundant   No logical redundancy. Structural form with all the necessary logical Elements and only the necessary elements to define the structural form.   guards   • Checking a condition that has already been established
Direct   Structural form that is meaningful and when read its purpose is obvious   statements, expressions, variables, constants, types   • Use of numbers to gender
Parameterized   Structural form with no undeclared constants and also, variables with unique purpose   module calls, expressions   • If a structural form contains numbers instead of defined constants
Range-independent   Structural form whose lower and upper bounds are not fixed numeric or character constants   Arrays, loops  
Utilized   Using defined structural forms at least once   objects, modules, all forms of declared data   • a variable that has been declared but not used
• a function is declared but not used

7.4.3. Modularity Properties
Well written code is modular with many sub-programs to be interfaced to deliver a result. Modularity property deals with how a module encapsulates its data; how it is data coupled to other modules; how loose its functionality is, how flexible it is and what potential does it have for reuse. Following Table 7.3 Code - Modular Properties summarizes modularity related properties along with details, structure to which applicable, and examples of defects.

Table 7.3 Code - Modular Properties
Property   Description   Applicable Structure or Code Construct   Examples of defects
Parameterized   Module with exact and required number of parameters for inputs and outputs to characterize a particular well-defined function/procedure.   modules   un-parameterized
over-parameterized
ill-parameterized
Loosely coupled (Data coupled)   A module or a program is loosely coupled if all module calls are data-coupled to the
calling program/module
  module calls   - control-coupled
- stamp-coupled
- content-coupled
- common-coupled
- externally coupled
Encapsulated   Uses no global variables. Defining and using variables restricting it within defined scope. Encouraging local variables, private, protected, friends class usage   variables, constants and types   Modules with global variables or side-effects
Cohesive   Binding all elements of structural form tightly bound so as to
Achieve a single objective or function. This maximizes relationships between the elements of an entity are maximized
  sequencing of elements   - a module with a lot of parameter
Generic   A module is generic if its computations are abstracted to a type-parameterized form. This makes module as independent of the type of its inputs and outputs   modules   - primitive type-dependent
Abstract   Module/object with no obvious, useful higher level concept that encompasses the structural form   objects   - specialized module/object (e.g. declaring a telephone object class instead of communication equipment object class)


 
 
Khannur's Book
Arunkumar Khannur, Software Testing - Techniques and Applications, Published by Pearson Publications, 2011 (ISBN:978-81-317-5836-6; Pages:341 + xxii)
Follow Khannur
         
Khannur's Company
ISQT Process & Consulting Services Pvt. Ltd., Bangalore, INDIA
Khannur's Software Testing Forum
STEP-AUTO Forum
 Contact Khannur
ISQT Process & Consulting Services Pvt. Ltd.
#732, 1st Floor, 12th Main,
3rd Block, Rajajinagar,
Bangalore - 560010, INDIA
Phone: +91 80 23012511
URL: www.isqtinternational.com
Email: khannur@isqtinternational.com
Skype: arun.isqt