Skip to content

Commit

Permalink
Add more recursion test (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
uudashr committed Sep 7, 2023
1 parent bc9ca12 commit 667cb69
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions testdata/src/a/a.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ OUT:
return total
} // Cognitive complexity = 7

func Fibonacci(n int) int { // want "cognitive complexity 3 of func Fibonacci is high \\(> 0\\)"
if n <= 1 { // +1
return n
}

return Fibonacci(n-1) + Fibonacci(n-2) // +1 and +1
} // Cognitive complexity = 3

func FactRec(n int) int { // want "cognitive complexity 3 of func FactRec is high \\(> 0\\)"
if n <= 1 { // +1
return 1
Expand All @@ -168,6 +176,14 @@ func FactRec(n int) int { // want "cognitive complexity 3 of func FactRec is hig
}
} // total complexity = 3

func FactRec_Simplified(n int) int { // want "cognitive complexity 2 of func FactRec_Simplified is high \\(> 0\\)"
if n <= 1 { // +1
return 1
}

return n * FactRec_Simplified(n-1) // +1
} // total complexity = 2

func FactLoop(n int) int { // want "cognitive complexity 1 of func FactLoop is high \\(> 0\\)"
total := 1
for n > 0 { // +1
Expand Down
16 changes: 16 additions & 0 deletions testdata/src/b/b.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ OUT:
return total
} // Cognitive complexity = 7

func Fibonacci(n int) int {
if n <= 1 { // +1
return n
}

return Fibonacci(n-1) + Fibonacci(n-2) // +1 and +1
} // Cognitive complexity = 3

func FactRec(n int) int {
if n <= 1 { // +1
return 1
Expand All @@ -160,6 +168,14 @@ func FactRec(n int) int {
}
} // total complexity = 3

func FactRec_Simplified(n int) int {
if n <= 1 { // +1
return 1
}

return n * FactRec_Simplified(n-1) // +1
} // total complexity = 2

func FactLoop(n int) int {
total := 1
for n > 0 { // +1
Expand Down

0 comments on commit 667cb69

Please sign in to comment.