我正在尝试计算我的软件的圈复杂度,但我有点困惑。据我了解,这是覆盖整个软件需要测试的路径数量。通常有 if 语句和循环会导致决策并因此增加路径但是我下面的代码没有循环或 if 语句,因此它只是 1 的复杂度吗?
btn_length.addEventListener (MouseEvent.CLICK, LengthFunc);
function LengthFunc (e: MouseEvent):void
{
gotoAndStop (1,"Scene 2");
}
btn_speed.addEventListener (MouseEvent.CLICK, SpeedFunc);
function SpeedFunc (e: MouseEvent):void
{
gotoAndStop (1,"Scene 6");
}
btn_currency.addEventListener (MouseEvent.CLICK, CurrencyFunc);
function CurrencyFunc (e: MouseEvent):void
{
gotoAndStop (1,"Scene 10");
}
btn_weight.addEventListener (MouseEvent.CLICK, WeightFunc);
function WeightFunc (e: MouseEvent):void
{
gotoAndStop (1,"Scene 11");
}
btn_data.addEventListener (MouseEvent.CLICK, dataFunc);
function dataFunc (e: MouseEvent):void
{
gotoAndStop (1,"Scene 16");
}
stop();
我相信这个类的复杂度也为 1。
import fl.data.DataProvider;
var dpcurr:DataProvider = new DataProvider();
var fromVal:Number;
var toVal:Number;
var inputValcurr:Number
var resultValcurr:Number;
input_txt.restrict = "0-9\\.\\";
dpcurr.addItem( { label: "EUR, Euro", data: 1.18 });
dpcurr.addItem( { label: "GBP, British Pound", data: 1 });
dpcurr.addItem( { label: "USD, US Dollar", data:1.54});
fromList.dataProvider = dpcurr;
toList.dataProvider = dpcurr;
fromList.addEventListener(Event.CHANGE, calculateResultcurr);
toList.addEventListener(Event.CHANGE, calculateResultcurr);
input_txt.addEventListener(Event.CHANGE, calculateResultcurr);
fromList.selectedIndex = 0;
toList.selectedIndex = 2;
fromVal = fromList.selectedItem.data;
toVal = toList.selectedItem.data;
function calculateResultcurr(e:Event):void{
fromVal = fromList.selectedItem.data;
toVal = toList.selectedItem.data;
inputValcurr = Number(input_txt.text);
resultValcurr = inputValcurr * (fromVal / toVal);
convert_btn.addEventListener(MouseEvent.CLICK, convertcurr);
function convertcurr(evt:MouseEvent):void {
result_txt.text = resultValcurr.toString()}
}
home_btn. addEventListener (MouseEvent. CLICK, homecurr);
function homecurr ( e: MouseEvent ): void {
gotoAndStop (1, "Scene 1" );
}
stop();
如果有人可以让我知道我是对还是错,我将不胜感激。这是一个 Flash 项目,因此代码是用 ActionScript 3 编写的。