Examples pdf
Examples pdf
Examples pdf
Example 2:
Let us consider an example of an online shopping site. In this site, each of
products has a specific product ID and product name. We can search for
product either by using name of product or by product ID. Here, we consider
search field that accepts only valid product ID or product name.
Let us consider a set of products with product IDs and users wants to search
for Mobiles. Below is a table of some products with their product Id.
Product Product ID
Mobiles 45
Laptops 54
Product Product ID
Pen Drives 67
Keyboard 76
Headphones 34
Example-3 :
Let us consider an example of software application. There is function of
software application that accepts only particular number of digits, not even
greater or less than that particular number.
Consider an OTP number that contains only 6 digit number, greater and
even less than six digits will not be accepted, and the application will redirect
customer or user to error page. If password entered by user is less or more
than six characters, that equivalence partitioning method will show an invalid
OTP. If password entered is exactly six characters, then equivalence
partitioning method will show valid OTP.
How to Calculate Cyclomatic Complexity?
Steps that should be followed in calculating cyclomatic complexity and test
cases design are:
Construction of graph with nodes and edges from code.
Identification of independent paths.
Cyclomatic Complexity Calculation
Design of Test Cases
Let a section of code as such:
A = 10
IF B > C THEN
A = B
ELSE
A = C
ENDIF
Print A
Print B
Print C
Control Flow Graph of the above code:
Cyclomatic Complexity
The cyclomatic complexity calculated for the above code will be from the
control flow graph.
The graph shows seven shapes(nodes), and seven lines(edges), hence
cyclomatic complexity is 7-7+2 = 2.