-
자바 코드의 CC2 측정 예제SW 품질관리 2023. 4. 10. 14:06
출처 : NHN은 이렇게 한다! 소프트웨어 품질관리
다음은 자바 코드의 CC2 측정 예제이다.
- 각 예제에서 CC2 값이 증가하는 부분은 연두색으로 표시했다.
- CC2는 최소 값이 1이다.
1. CC2값이 1인 예제
public void cc1() {
System.out.println(“CC is one”);
}
2. CC2값이 2인 예제
public void cc2(boolean bPrint) {
if (bPrint){
System.out.println(“if”);
}
else {
System.out.println(“if else”);
}
System.out.println(“CC is two”);
}
3. CC2값이 3인 예제 (1)
public void cc3(boolean bFirst, boolean bSecond) {
if (bFirst && bSecond){
System.out.println(“if”);
}
else {
System.out.println(“if else”);
}
System.out.println(“CC is three”);
}
4. CC2값이 4인 예제 (1)
public void cc4(int select) {
switch (select) {
case 1:
System.out.println(“case 1”);
break;
case 2:
System.out.println(“case 2”);
break;
case 3:
System.out.println(“case 3”);
break;
default;
System.out.println(“default”);
}
System.out.println(“CC is four”);
}
5. CC2값이 4인 예제 (2)
public void ccForwithBoolean() {
boolean bContinue = true;
for (int i=0, i<10 && bContinue; ++i) {
if (i==5) {
bContinue = false;
}
System.out.println(i);
}
6. CC2값이 3인 예제 (2)
public void ccWhile() {
int i =0;
while (true) {
if (i>=10) {
break;
}
else {
++i;
}
}
}
7. CC2값이 4인 예제 (3)
public void ccTryCatch() {
int denominatorArray[] = {5, 4, 3, 2, 1, 0};
int quotinent;
try {
for (int i=0, i<10; ++i){
quotient = 10 / denominatorArray[i];
System.out.println(quotinent);
}
} catch (ArithmeticException e){
} catch (ArrayIndexOutOfBoundsException e){
} finally {
}
}
8. CC2 값이 5인 예제
public void ccBooleans(boolean bCondition) {
boolean bCC = bCondition ? true : false;
boolean bNotCC = true & false;
bCC = true && false;
bCC = true || false && true;
bNotCC = true == true;
bNotCC = true != true;
System.out.println(“Booleans”);
}
'SW 품질관리' 카테고리의 다른 글
Verification과 Validation의 차이? (0) 2023.04.13 [경쟁력 있는 소프트웨어 테스터가 되는 법] 현업에서 혼용되는 다양한 용어 풀이 (버그와 에러 차이? 랜덤테스트와 애드혹테스트의 차이? N/A, N/T, N/I 등) (0) 2023.04.12 사이클로매틱 복잡도란? [NHN은 이렇게 한다!] (0) 2023.04.06 [왜 시스템 개발만 하면 싸워댈까] 시스템개발 V모형과 요구사항 추적표 예시 (0) 2023.04.05 [NHN은 이렇게 한다! 소프트웨어 품질관리] NHN 품질 사례, 챕터별 내용 요약 (1) 2023.04.04