Examples pdf

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Example-1:

Let us consider an example of any college admission process. There is a


college that gives admissions to students based upon their percentage.
Consider percentage field that will accept percentage only between 50 to 90
%, more and even less than not be accepted, and application will redirect
user to an error page. If percentage entered by user is less than 50 %or
more than 90 %, that equivalence partitioning method will show an invalid
percentage. If percentage entered is between 50 to 90 %, then equivalence
partitioning method will show valid percentage.

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

If the product ID entered by user is invalid then application will redirect


customer or user to error page. If product ID entered by user is valid i.e. 45
for mobile, then equivalence partitioning method will show a valid product
ID.

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.

Use of Cyclomatic Complexity


 Determining the independent path executions thus proven to be very
helpful for Developers and Testers.
 It can make sure that every path has been tested at least once.
 Thus help to focus more on uncovered paths.
 Code coverage can be improved.
 Risks associated with the program can be evaluated.
 These metrics being used earlier in the program help in reducing the
risks.
Advantages of Cyclomatic Complexity
 It can be used as a quality metric, given the relative complexity of various
designs.
 It is able to compute faster than Halstead’s metrics.
 It is used to measure the minimum effort and best areas of concentration
for testing.
 It is able to guide the testing process.
 It is easy to apply.
Disadvantages of Cyclomatic Complexity
 It is the measure of the program’s control complexity and not the data
complexity.
 In this, nested conditional structures are harder to understand than non-
nested structures.
 In the case of simple comparisons and decision structures, it may give a
misleading figure.

Follow the link for more examples


https://www.gatevidyalay.com/cyclomatic-complexity-calculation-examples/

You might also like