|
6 | 6 | "io"
|
7 | 7 | )
|
8 | 8 |
|
| 9 | +type any interface{} |
| 10 | + |
9 | 11 | func HelloWorld() string {
|
10 | 12 | _ = len("hello")
|
11 | 13 | return "Hello, World!"
|
@@ -75,6 +77,41 @@ func ComplexLogicalSeq2(a, b, c, d, e, f bool) string {
|
75 | 77 | return "not ok"
|
76 | 78 | } // total complexity = 3
|
77 | 79 |
|
| 80 | +func ComplexLogicalSeq3(a, b, c, d, e, f bool) string { |
| 81 | + if a && (b && c) { // +1 for `if`, +1 for each `&&` chain |
| 82 | + return "ok" |
| 83 | + } |
| 84 | + |
| 85 | + return "not ok" |
| 86 | +} // total complexity = 3 |
| 87 | + |
| 88 | +func ComplexLogicalSeq4(a, b, c, d, e, f bool) bool { |
| 89 | + return a && b && c || d || e && f // +3 for changing sequence of `&&` `||` `&&` |
| 90 | +} // total complexity = 3 |
| 91 | + |
| 92 | +func ComplexLogicalSeq5(a, b, c, d, e, f bool) bool { |
| 93 | + return a && b && (c && d || e || f) // +1 for `&&` sequence, +2 for `&&` `||` sequence in parentheses |
| 94 | +} // total complexity = 3 |
| 95 | + |
| 96 | +func ExprFunc(a, b, c any) bool { |
| 97 | + if a != nil || b != nil || c != nil { // +1 for `if`, +1 for `||` chain |
| 98 | + return false |
| 99 | + } |
| 100 | + |
| 101 | + return true |
| 102 | +} // total complexity = 2 |
| 103 | + |
| 104 | +func VarFunc(a, b, c any) bool { |
| 105 | + na := a != nil |
| 106 | + nb := b != nil |
| 107 | + nc := c != nil |
| 108 | + if na || nb || nc { // +1 for `if`, +1 for `||` chain |
| 109 | + return false |
| 110 | + } |
| 111 | + |
| 112 | + return true |
| 113 | +} // total complexity = 2 |
| 114 | + |
78 | 115 | func GetWords(number int) string {
|
79 | 116 | switch number { // +1
|
80 | 117 | case 1:
|
|
0 commit comments