공돌이
[Software] Cyclomatic complexity 계산 예제
누룽지82
2023. 5. 31. 02:31
728x90
- Thomas J. McCabe 가 만든 SW 복잡도 측정 metric.
- 측정 대상 프로그램의 control flow graph 를 이용해 계산한다. 즉, control flow graph 를 먼저 그려야 한다.
- 계산식: M = E - N + 2P
- M: Cyclomatic complexity
- E: graph 에서 edge 갯수
- N: graph에서 node 갯수
- P: Connected component 의 갯수. 그래프를 그렸을 때 서로 연결되지 않은 path 들의 갯수를 말함.
- 예를 들어보면,
위 식은 다음의 flow graph 로 표현할 수 있음.
위 flow graph로 다음을 추출.
- E: graph 에서 edge 갯수 = 연결선 갯수 = 8
- N: graph에서 node 갯수 = 7
- P: Connected component 의 갯수. = 1
그러므로, Cyclomatic complexity M = 8 - 7 + (2 * 1) = 3 이다!!!
[참고]
https://www.tutorialspoint.com/software_testing_dictionary/cyclomatic_complexity.htm
https://en.wikipedia.org/wiki/Component_(graph_theory)
반응형