This project has moved. For the latest updates, please go here.
3
Vote

Complexity of if-elseif-else is calculated incorrectly

description

Calculation of complexity of "if-else" blocks incorrectly adds one point for else.
// 2 - Correct complexity, just one decision
private void Test1(int x)
{
    if (x == 1)
    {
        x = 2;
        return;
    }

    x = 3;
}

// 3 - Incorrect complexity, still just one decision -> shoud be 2
private void Test2(int x)
{
    if (x == 1)
    {
        x = 2;
    }
    else
    {
        x = 3;
    }
}

// 5 - Incorrect complexity, just two decisions -> shoud be 3
private void Test3(int x)
{
    if (x == 1)
    {
        x = 2;
    }
    else if (x == 2)
    {
        x = 3;
    }
    else
    {
        x = 4;
    }
}
See attachment for screenshot from VS.

file attachments

comments

jirkapok wrote Jul 11, 2014 at 7:04 PM

jirkapok wrote Aug 27, 2015 at 4:39 PM

still present in 0.7.0