cyclomatic complexity for ActionScript 3

174 views Asked by At

i am trying to calculate the cyclomatic complexity of my software but i am a bit confused. From what i understand it is the amounts of paths that are needed to be tested to cover the whole software. Usually there are if statements and loops which cause decisions and therefor increase the path however my code below has no loops or if statements and therefore is it just a complexity of 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();

also this class has also a complexity of 1 i believe.

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();

if some could just let me know if i am right or wrong i would be grateful. It was a flash project and therefore the code is written in ActionScript 3.

2

There are 2 answers

1
user3074883 On

Cyclomatic complexity is driven by decision density. The higher the decision density, the higher the complexity will be. If you have no embedded decisions the Cyclomatic Complexity will be 1. There is only an associative relationship with code size but a causative relationship with decision density. In Tom McCabe's research, he shows that once the Cyclomatic Complexity goes over 10, the module becomes error prone, and the error-proneness goes up exponentially as the Cyclomatic Complexity number goes up linearly. When the module complexity becomes too high, the module becomes untestable, unmaintainable, and undocumentable. Using Cyclomatic Complexity analysis in combination with Fagan Inspections is a very powerful combination to produce very high quality software, as well as drive total development cost down. Cyclomatic Complexity evaluates the structure of the code (the complexity graphs give you a picture of what can be described as the skeleton of the code) and the Fagan Inspections address the functional correctness of the code. Just using an analyzer that gives you the Cyclomatic Complexity number and nothing else is not nearly as useful as one that also produces the complexity graphs.

0
AudioBubble On

Yes as long as you do not have any control statement (if, else, while, for, do, break, && etc.) in your code there is an only path through the code, therefore the cyclomatic number is one.