Thursday, September 15, 2022

Git Commands You Need To Know


Git Commands You Need To Know

The most popular version control program is called Git. Git keeps track of the changes you make to files so that you have a record of what has been done and may go back to particular versions if necessary. Git also facilitates cooperation by enabling the merging of several contributors' edits into a single repository.

Therefore, Git will be helpful for you whether you develop code that only you will view or work in a team.

Git Commands

git init -> Initializes git in any folder/repository (Needs only if you are not cloning a repository)

git clone -> https://github.com/<your-user-name>/<repo-name> -> Clones the repository in your local system.

git status -> Shows the current status of the repository.

git add <file-name> -> Adds specific file to staging area

git diff / git whatchanged -> Gives the recent changes in the repository

git add . -> Adds all changed files to staging area

git commit -m "<your-message>" -> Gives a message to your current files and takes their snapshot to commit history

git log -> Shows the commit history

git revert <commit-token> -> Discards the specific commit (Deletes the committed files but keeps a trace in history)

git reset --soft HEAD~<no-of-commits-to-revert> -> Undo's the commit and brings the changes back in the staging area

git restore --staged <file> -> Brings back the specific file in the changes made section which is added to the staging area.

git remote -v -> Shows all the remote connection

git remote add origin https://github.com/<your-user-name>/<repo-name> -> adds your forked branch as the origin (No need to do if the repo is cloned)

git remote add upstream https://github.com/<parent-user-name>/<repo-name> -> Adds parent repository as upstream.

git pull origin -> fetches the changes made in origin to your local system

git pull upstream -> fetches the changes made in origin to your local system

git branch <branch-name> -> Creates a branch with branch-name

git checkout <branch-name> -> This now allows you to make changes in the specified branch

git checkout -b <branch-name> -> This is combination of git branch and git checkout

git merge <branch-name> -> merges its children branch-name into its parent branch.

git branch -d <branch-name> -> Deletes the specified branch. And if the changes in the branch-name are not merged in the parent branch then the changes are deleted.

git push origin <branch-name> -> Pushes the recent commits to the new branch

 



I appreciate you reading thus far. You can view my Github. Good Bye.

Friday, August 12, 2022

Cyclomatic Complexity Metric

 Cyclomatic Complexity Metric




Introduction to Cyclomatic Complexity (CC) metric

 

Cyclomatic Complexity in Software Testing is a testing metric used for measuring the complexity of a software program. It is a quantitative measure of independent paths in the source code of a software program. Cyclomatic complexity can be calculated by using control flow graphs or with respect to functions, modules, methods or classes within a software program.

 

Independent path is defined as a path that has at least one edge which has not been traversed before in any other paths.

 

This metric was developed by Thomas J. McCabe in 1976 and it is based on a control flow representation of the program. Control flow depicts a program as a graph which consists of Nodes and Edges.

Proposed enhancement factors, reasons for the selection of enhancement factors and modification for CC metric with each enhancement factor

                            Factor 1 - Find Type of basic control structures.

 Reason –  Complexity α Type of Basic controlstructures


When type of Basic control structure increase complexity of the program also increases.


Find Type of Basic Control Structure

Complexity of basic control structures (BCS) = Σ(Size of executable statement X Type of basic control structure value according to the amount of contribution to the complexity (CS))

Find Cyclomatic Complexity of Basic Control Structure

Cyclomatic Complexity of Basic Control Structure (CCBCS) = Cyclomatic complexity (CC) + Complexity of basic control structures (BCS)

Factor 2 - Measuring the Nesting level of control structures

Reason -   Complexity α Nesting level of control structures

When Nesting level of executable statement increase complexity of the program also increase.

This metric calculates the complexity at the nesting level considering the internal structure of the method and considers nesting to calculate the complexity of the class hierarchy

Find Complexity of Nesting level of CS

Complexity of Nesting level of Cs(CNL) = Σ(Size of executable statement (S) X Nesting level of control structure value according to the amount of contribution to the complexity (N))

Find Cyclomatic Nesting level of CS

Cyclomatic Complexity of Nesting levels of Cs(CCNL) = Cyclomatic complexity (CC) + Complexity of Nesting level of CS(CNL)


Factor 3 - Measuring the Complexity due to Inheritance

Reason         Complexity α Inheritance(I)

When inheritance count increase in program , as per that complexity of the program also increase.

This metric calculates the complexity at the method level considering the internal structure of the method and considers inheritance to calculate the complexity of the class hierarchy.

The proposed metric is validated both theoretically and empirically.

Find Complexity of Inheritance

Complexity of Inheritance (CI) =Σ(Size of executable statement (S) X Value given for the level of inheritance (I) )

Find Cyclomatic Complexity of Inheritance

Cyclomatic Complexity of Inheritance (CCI) =Cyclomatic complexity (CC) + Complexity of Inheritance (CI)

Factor 4 - Find Size of executable statement

Reason      Complexity α Size of executable statement (S)

When size of executable statement count increase in program , as per that complexity of the program also increase.

Size of a class is used to evaluate the ease of understanding of code by developers and maintainers.

Size can be measured in a variety of ways. These include counting all physical lines of

code, the number of statements, the number of blank lines, and the number of comments

lines. Lines of Code(LOC) counts all lines. Non-comment Non-blank (NCNB) is sometimes

referred to as Source Lines of Code and counts all lines that are not comments and not

blanks. Executable Statements (EXEC) is a count of executable statements regardless of

number of physical lines of code


Therefore, the proposed metrics is helping to enhanced reliability, understandability and

maintainability of executable statements of every program with high performance.

Find Complexity of Size

Complexity of size (CS) = Σ( Size of executable statement (S) )

Find Cyclomatic Complexity of Size

Cyclomatic Complexity of Size (CCS) = Cyclomatic complexity (CC) + Complexity of size (CS)

Final modified equation(FME) by considering all enhancement factors proposed


FME= ( C.Complexity of Size) + (C.Complexity of inheritance) +(C.Complexity of basic control structure) + (C.Complexity of coupling)

FME = CCS + CCI + CCBCS + CCNL


Example of calculating the complexity using final modified equation

Example 01


            Flow Graph

                

                            Cyclomatic Complexity Calculation

                                E = number of edges  = 11

                                N = number of nodes  = 11

                                P = number of nodes that have exit = 1

                                CC       =E – N + 2*P

                                            = 11 -11 + 2*1

                                            = 2

                                CC       =2


                



                                                CC = 2

Enhanced Cyclomatic Complexity for each factors.

            CCS = CC + CS = 2 + 120 =122

            CCI = CC + CI = 2 + 3 = 5

            CCBCS = CC + BCS = 2 + 19 = 21

            CCNL = CC + CNL = 2 + 0 = 2

Final Modified Equation for Cyclomatic Complexity(FME ) =CCS + CCI + CCBCS + CCNL

 

                                                                         =122 + 5 + 21 + 2

                                        FME     =150

Final Modified Equation for Software Complexity (FME) = CS + CI + BCS + NL

 

                                                                                             = 120 + 3 + 19

                                                                     FME =142

Example 02

Flow graph


Cyclomatic Complexity Calculation

 E = number of edges  = 8

N = number of nodes  = 7

                                 P = number of nodes that have exit points  = 1

 

                         CC     =E – N + 2*P

                                    = 8 -7 + 2*1

         CC     =3


CC =3

Enhanced Cyclomatic Complexity for each factors.

 CCS = CC + CS = 3 + 69 = 72

CCI = CC + CI = 3 + 4 = 7

 CCBCS = CC + BCS = 3 + 12 = 15

 CCNL = CC + CNL = 3 + 0 = 3

Final Modified Equation for Cyclomatic Complexity(FME)  = CCS + CCI + CCBCS +CCNL

                                                                          = 72 + 7 + 15 + 3

                                         FME     = 97

Final Modified Equation for Software Complexity (FME) = CS + CI + BCS + NL

                                                                                      = 69 + 4 + 12 + 0

                                                         FME = 85

Conclusion

Example

FME(cc)

FME(sc)

1

150

142

2

97

85

And when Cyclomatic complexity factors enhanced Total Cyclomatic complexity also increased

                                            References

Cyclomatic Complexity - an overview | ScienceDirect Topics

https://www.sciencedirect.com/topics/computer-science/cyclomatic-complexity

Cyclomatic Complexity | IEEE Journals & Magazine

https://ieeexplore.ieee.org/document/7725232

McCabe’s Cyclomatic Complexity with Flow Graph

https://www.guru99.com/cyclomatic-complexity.html



That's all for the Cyclomatic Complexity Metric. Thank you for reading this Post. Good Bye.












MVC Architecture