File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -160,6 +160,14 @@ OUT:
160
160
return total
161
161
} // Cognitive complexity = 7
162
162
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
+
163
171
func FactRec (n int ) int { // want "cognitive complexity 3 of func FactRec is high \\(> 0\\)"
164
172
if n <= 1 { // +1
165
173
return 1
@@ -168,6 +176,14 @@ func FactRec(n int) int { // want "cognitive complexity 3 of func FactRec is hig
168
176
}
169
177
} // total complexity = 3
170
178
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
+
171
187
func FactLoop (n int ) int { // want "cognitive complexity 1 of func FactLoop is high \\(> 0\\)"
172
188
total := 1
173
189
for n > 0 { // +1
Original file line number Diff line number Diff line change @@ -152,6 +152,14 @@ OUT:
152
152
return total
153
153
} // Cognitive complexity = 7
154
154
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
+
155
163
func FactRec (n int ) int {
156
164
if n <= 1 { // +1
157
165
return 1
@@ -160,6 +168,14 @@ func FactRec(n int) int {
160
168
}
161
169
} // total complexity = 3
162
170
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
+
163
179
func FactLoop (n int ) int {
164
180
total := 1
165
181
for n > 0 { // +1
You can’t perform that action at this time.
0 commit comments