Skip to content

Commit 667cb69

Browse files
authored
Add more recursion test (#32)
1 parent bc9ca12 commit 667cb69

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

testdata/src/a/a.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,14 @@ OUT:
160160
return total
161161
} // Cognitive complexity = 7
162162

163+
func Fibonacci(n int) int { // want "cognitive complexity 3 of func Fibonacci is high \\(> 0\\)"
164+
if n <= 1 { // +1
165+
return n
166+
}
167+
168+
return Fibonacci(n-1) + Fibonacci(n-2) // +1 and +1
169+
} // Cognitive complexity = 3
170+
163171
func FactRec(n int) int { // want "cognitive complexity 3 of func FactRec is high \\(> 0\\)"
164172
if n <= 1 { // +1
165173
return 1
@@ -168,6 +176,14 @@ func FactRec(n int) int { // want "cognitive complexity 3 of func FactRec is hig
168176
}
169177
} // total complexity = 3
170178

179+
func FactRec_Simplified(n int) int { // want "cognitive complexity 2 of func FactRec_Simplified is high \\(> 0\\)"
180+
if n <= 1 { // +1
181+
return 1
182+
}
183+
184+
return n * FactRec_Simplified(n-1) // +1
185+
} // total complexity = 2
186+
171187
func FactLoop(n int) int { // want "cognitive complexity 1 of func FactLoop is high \\(> 0\\)"
172188
total := 1
173189
for n > 0 { // +1

testdata/src/b/b.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ OUT:
152152
return total
153153
} // Cognitive complexity = 7
154154

155+
func Fibonacci(n int) int {
156+
if n <= 1 { // +1
157+
return n
158+
}
159+
160+
return Fibonacci(n-1) + Fibonacci(n-2) // +1 and +1
161+
} // Cognitive complexity = 3
162+
155163
func FactRec(n int) int {
156164
if n <= 1 { // +1
157165
return 1
@@ -160,6 +168,14 @@ func FactRec(n int) int {
160168
}
161169
} // total complexity = 3
162170

171+
func FactRec_Simplified(n int) int {
172+
if n <= 1 { // +1
173+
return 1
174+
}
175+
176+
return n * FactRec_Simplified(n-1) // +1
177+
} // total complexity = 2
178+
163179
func FactLoop(n int) int {
164180
total := 1
165181
for n > 0 { // +1

0 commit comments

Comments
 (0)