계산할 그래프 방식을 보여주기 위해 C# 프로젝트의 각 메서드에 대한 컨트롤 흐름 다이어그램 (노드와 가장자리가있는 간단한 흐름 그래프)을 만들어야합니다. 순환 복잡성.C# 코드의 전체 목록 (순환 복소수 +1 +1)
먼저 VS 2010을 사용하여 순환 복잡도를 계산 한 다음 결과 값이 VS에서 계산 된 값과 동일한 지 확인하기 위해 그래프를 구성합니다. 그러나 어떤식이 순환 적 복잡성에 대해 실제로 +1인지는 확실하지 않기 때문에 여기서 몇 가지 문제를 만났습니다.
의 여기에 하나의 예를 살펴 보자 :이 방법
public ActionResult Edit(string id, string value)
{
string elementId = id;
// Use to get first 4 characters of the id to indicate which category the element belongs
string fieldToEdit = elementId.Substring(0, 4);
// Take everything AFTER the 1st 4 characters, this will be the ID
int idToEdit = Convert.ToInt32(elementId.Remove(0, 4));
// The value to be return is simply a string:
string newValue = value;
var food = dbEntities.FOODs.Single(i => i.FoodID == idToEdit);
// Use switch to perform different action according to different field
switch (fieldToEdit)
{
case "name": food.FoodName = newValue; break;
case "amnt": food.FoodAmount = Convert.ToInt32(newValue); break;
case "unit": food.FoodUnitID = Convert.ToInt32(newValue); break;
// ** DateTime format need to be modified in both view and plugin script
case "sdat": food.StorageDate = Convert.ToDateTime(newValue); break;
case "edat": food.ExpiryDate = Convert.ToDateTime(newValue); break;
case "type": food.FoodTypeID = Convert.ToInt32(newValue); break;
default: throw new Exception("invalid fieldToEdit passed");
}
dbEntities.SaveChanges();
return Content(newValue);
}
, VS, 나는 다른 표현이에 기여하는 것을 이해하지 못하고 단지 7 case 문이있다, 그러나 (10)과 복잡성을 계산 복잡성.
많은 소스를 통해 검색했지만 전체 수를 계산할 수있는 목록을 가져올 수 없습니다.
아무도 도와 드릴 수 있습니까? 아니면 C# 코드에서 제어 흐름 다이어그램을 생성 할 수있는 도구가 있습니까?
는
이 질문에 대한 답변이 없지만 스위치 분기 이외에 VS 예외가 발생할 수있는 경우를 계산합니다. 예를 들어,'elementId == null'의 경우, 메소드는 두 번째 행을 실행하려고하는 NullReferenceException을 던집니다. 이것은 별도의 실행 경로로 간주 될 수 있습니다. – Gebb