Skip to content

Commit 30864f8

Browse files
committed
Add more gocognit tests.
1 parent 50cfc34 commit 30864f8

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

test/testdata/gocognit.go

+32-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//config: linters-settings.gocognit.min-complexity=2
33
package testdata
44

5-
func GocognitGetWords(number int) string { // ERROR "cognitive complexity 4 of func .* is high .*"
5+
func GoCognit_CC4_GetWords(number int) string { // ERROR "cognitive complexity 4 of func .* is high .*"
66
if number == 1 { // +1
77
return "one"
88
} else if number == 2 { // +1
@@ -14,10 +14,39 @@ func GocognitGetWords(number int) string { // ERROR "cognitive complexity 4 of f
1414
}
1515
} // total complexity = 4
1616

17-
func GoCognitFact(n int) int { // ERROR "cognitive complexity 3 of func .* is high .*"
17+
func GoCognit_CC1_GetWords(number int) string {
18+
switch number { // +1
19+
case 1:
20+
return "one"
21+
case 2:
22+
return "a couple"
23+
case 3:
24+
return "a few"
25+
default:
26+
return "lots"
27+
}
28+
} // Cognitive complexity = 1
29+
30+
func GoCognit_CC3_Fact(n int) int { // ERROR "cognitive complexity 3 of func .* is high .*"
1831
if n <= 1 { // +1
1932
return 1
2033
} else { // +1
21-
return n + GoCognitFact(n-1) // +1
34+
return n + GoCognit_CC3_Fact(n-1) // +1
2235
}
2336
} // total complexity = 3
37+
38+
func GoCognit_CC7_SumOfPrimes(max int) int { // ERROR "cognitive complexity 7 of func .* is high .*"
39+
var total int
40+
41+
OUT:
42+
for i := 1; i < max; i++ { // +1
43+
for j := 2; j < i; j++ { // +2 (nesting = 1)
44+
if i%j == 0 { // +3 (nesting = 2)
45+
continue OUT // +1
46+
}
47+
}
48+
total += i
49+
}
50+
51+
return total
52+
} // Cognitive complexity = 7

0 commit comments

Comments
 (0)