Created
October 9, 2012 14:13
-
-
Save retran/3859063 to your computer and use it in GitHub Desktop.
Cyclomatic complexity test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Cyclomatic complexity: 8. Maintanability: 80. | |
// Coupling: 2 | |
using System; | |
class Foo | |
{ | |
private readonly int _mode; | |
public Foo(int mode) | |
{ | |
_mode = mode; | |
} | |
public void DoConfigurableOperation() | |
{ | |
switch (_mode) | |
{ | |
case 0: | |
Console.WriteLine(0); | |
break; | |
case 1: | |
Console.WriteLine(1); | |
break; | |
case 2: | |
Console.WriteLine(2); | |
break; | |
case 3: | |
Console.WriteLine(3); | |
break; | |
} | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var foo = new Foo(1); | |
foo.DoConfigurableOperation(); | |
Console.ReadKey(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Cyclomatic complexity: 15. Maintanability: 95. | |
// Coupling: 4 | |
using System; | |
interface IOperation | |
{ | |
void Do(); | |
} | |
class ZeroOperation : IOperation | |
{ | |
public void Do() | |
{ | |
Console.WriteLine(0); | |
} | |
} | |
class OneOperation : IOperation | |
{ | |
public void Do() | |
{ | |
Console.WriteLine(1); | |
} | |
} | |
class TwoOperation : IOperation | |
{ | |
public void Do() | |
{ | |
Console.WriteLine(2); | |
} | |
} | |
class ThreeOperation : IOperation | |
{ | |
public void Do() | |
{ | |
Console.WriteLine(3); | |
} | |
} | |
class Foo | |
{ | |
private readonly IOperation _operation; | |
public Foo(IOperation operation) | |
{ | |
_operation = operation; | |
} | |
public void DoConfigurableOperation() | |
{ | |
_operation.Do(); | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var foo = new Foo(new OneOperation()); | |
foo.DoConfigurableOperation(); | |
Console.ReadKey(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment