테스트 가능한 JS에 관한 책을 읽었으며 순환 적 복잡성에 대한 장이 있지만 실제 계산 방법은 나와 있지 않습니다. 그냥순환 복잡도 경로 개수
된 Cyclomatic 복잡성이 코드를 통해 독립적 인 경로의 수를 측정이라고 말했다.
그리고 그것은 2의 복잡성을 가지고 주장이 예제를 제공합니다 :이 예제를 만들어 있는지 궁금하네요 따라서
function sum(a, b) {
if (typeof(a) !== typeof(b)) {
throw new Error("Cannot sum different types!");
} else {
return a + b;
}
}
을 가지고 3의 복잡성을 :
function madeup(a) {
if (typeof(a) === "string") {
if (a === "some") {
console.log("is a some");
} else {
console.log("not a some");
}
} else {
console.log("not a string");
}
}
그리고 4 :
function madeup(a) {
if (typeof(a) === "string") {
if (a === "some") {
console.log("is a some");
} else {
console.log("not a some");
}
} else {
if (a === 5) {
console.log("is a 5");
} else {
console.log("not a 5");
}
}
}
?
당신이 말했듯이, 당신은 단지 경로를 계산합니다. 당신이 옳은 것으로 계산했습니다. – AbcAeffchen