@Test public void nesting() { assertThat(complexity("if (x) a && b;").value()).isEqualTo(2); assertThat(complexity("if (x) if (y) 42;").value()).isEqualTo(3); assertThat(complexity("while (x) if (y) 42;").value()).isEqualTo(3); assertThat(complexity("match (x) { else -> if (y) 42; };").value()).isEqualTo(3); assertThat(complexity("try { x } catch (e) { if (y) 42; };").value()).isEqualTo(3); assertThat(complexity("try { if (y) 42; } catch (e) { x };").value()).isEqualTo(2); assertThat(complexity("fun foo() { if (x) 42; }").value()).isEqualTo(1); assertThat(complexity("fun foo() { f = fun() { if (x) 42; }; }").value()).isEqualTo(2); assertThat(complexity("if (x) { f = fun() { if (x) 42; }; };").value()).isEqualTo(4); }
public int value() { int total = 0; for (Increment increment : increments) { total += increment.nestingLevel + 1; } return total; }
CognitiveComplexity { public int value() { int total = 0; for (Increment increment : increments) { total += increment.nestingLevel + 1; } return total; } }
CognitiveComplexity { public int value() { int total = 0; for (Increment increment : increments) { total += increment.nestingLevel + 1; } return total; } CognitiveComplexity(Tree root); }
CognitiveComplexity { public int value() { int total = 0; for (Increment increment : increments) { total += increment.nestingLevel + 1; } return total; } CognitiveComplexity(Tree root); int value(); List<Increment> increments(); }
CognitiveComplexity { public int value() { int total = 0; for (Increment increment : increments) { total += increment.nestingLevel + 1; } return total; } CognitiveComplexity(Tree root); int value(); List<Increment> increments();  }