Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more recursion test #32

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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