Created
April 22, 2016 10:58
-
-
Save citizenmatt/05687be59bfb36fbeb47c0ef0ccff267 to your computer and use it in GitHub Desktop.
Cyclomatic Complexity testing
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace CyclomaticComplexityTest | |
{ | |
class Result | |
{ | |
public string Id { get; set; } | |
public string Text { get; set; } | |
} | |
class Config | |
{ | |
public bool Setting1 { get; set; } | |
public bool Setting2 { get; set; } | |
public bool Setting3 { get; set; } | |
public bool Setting4 { get; set; } | |
public bool Setting5 { get; set; } | |
public bool Setting6 { get; set; } | |
public string Id { get; set; } | |
public string Text { get; set; } | |
} | |
class Req | |
{ | |
public bool performAction; | |
public bool? Setting1 { get; set; } | |
public bool? Setting2 { get; set; } | |
public bool? Setting3 { get; set; } | |
public bool? Setting4 { get; set; } | |
public bool? Setting5 { get; set; } | |
public bool? Setting6 { get; set; } | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
} | |
// VS thinks this has a CC of 1. Nope. | |
// ReSharper thinks this has a CC of 13. Seems reasonable, not sure, though. | |
private static IEnumerable<Result> Update(IEnumerable<Config> configs, Req req) | |
{ | |
foreach (Config config in configs) | |
{ | |
config.Setting1 = req.Setting1 ?? config.Setting1; | |
config.Setting2 = config.Setting2 || (req.Setting2 ?? config.Setting1); | |
config.Setting3 = req.Setting3 ?? config.Setting3; | |
config.Setting4 = req.Setting4 ?? config.Setting4; | |
config.Setting5 = req.Setting5 ?? config.Setting5; | |
config.Setting6 = req.Setting6 ?? config.Setting6; | |
if (req.performAction != true) | |
{ | |
continue; | |
} | |
PerformAction(config); | |
yield return new Result | |
{ | |
Id = config.Id, | |
Text = config.Text | |
}; | |
} | |
} | |
// VS this this has CC of 1 (I'm convinced this is flat out wrong) | |
// ReSharper thinks this has CC of 11 | |
private static IEnumerable<Result> Update2(Config config, Req req) | |
{ | |
{ | |
config.Setting1 = req.Setting1 ?? config.Setting1; | |
config.Setting2 = config.Setting2 || (req.Setting2 ?? config.Setting1); | |
config.Setting3 = req.Setting3 ?? config.Setting3; | |
config.Setting4 = req.Setting4 ?? config.Setting4; | |
config.Setting5 = req.Setting5 ?? config.Setting5; | |
config.Setting6 = req.Setting6 ?? config.Setting6; | |
if (req.performAction != true) | |
{ | |
yield break; | |
} | |
PerformAction(config); | |
yield return new Result | |
{ | |
Id = config.Id, | |
Text = config.Text | |
}; | |
} | |
} | |
private static void PerformAction(Config config) | |
{ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment