Skip to content

Commit b35b1f4

Browse files
committed
C++: Adjust the tests with thresholds so as to test the extremes, not the tuning of the threshold.
1 parent c8a09a0 commit b35b1f4

6 files changed

Lines changed: 44 additions & 90 deletions

File tree

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
void complex_block_one() {
1+
void complex_block() {
22
while (true) {
33
int a = 1;
44
int b = 2;
@@ -7,6 +7,9 @@ void complex_block_one() {
77
int e = 5;
88
int f = 6;
99
int g = 7;
10+
int h = 8;
11+
int i = 9;
12+
int j = 10;
1013
}
1114
while (true) {
1215
int a = 1;
@@ -16,6 +19,9 @@ void complex_block_one() {
1619
int e = 5;
1720
int f = 6;
1821
int g = 7;
22+
int h = 8;
23+
int i = 9;
24+
int j = 10;
1925
}
2026
while (true) {
2127
int a = 1;
@@ -25,6 +31,9 @@ void complex_block_one() {
2531
int e = 5;
2632
int f = 6;
2733
int g = 7;
34+
int h = 8;
35+
int i = 9;
36+
int j = 10;
2837
}
2938
while (true) {
3039
int a = 1;
@@ -34,74 +43,44 @@ void complex_block_one() {
3443
int e = 5;
3544
int f = 6;
3645
int g = 7;
46+
int h = 8;
47+
int i = 9;
48+
int j = 10;
3749
}
38-
} // $ Alert
39-
40-
void complex_block_two() {
41-
for (;;) {
42-
int a = 1;
43-
int b = 2;
44-
int c = 3;
45-
int d = 4;
46-
int e = 5;
47-
int f = 6;
48-
int g = 7;
49-
}
50-
for (;;) {
51-
int a = 1;
52-
int b = 2;
53-
int c = 3;
54-
int d = 4;
55-
int e = 5;
56-
int f = 6;
57-
int g = 7;
58-
}
59-
for (;;) {
60-
int a = 1;
61-
int b = 2;
62-
int c = 3;
63-
int d = 4;
64-
int e = 5;
65-
int f = 6;
66-
int g = 7;
67-
}
68-
for (;;) {
50+
while (true) {
6951
int a = 1;
7052
int b = 2;
7153
int c = 3;
7254
int d = 4;
7355
int e = 5;
7456
int f = 6;
7557
int g = 7;
58+
int h = 8;
59+
int i = 9;
60+
int j = 10;
7661
}
7762
} // $ Alert
7863

79-
void three_complex_statements_is_not_enough() {
64+
void not_complex_block() {
8065
while (true) {
8166
int a = 1;
8267
int b = 2;
8368
int c = 3;
8469
int d = 4;
8570
int e = 5;
86-
int f = 6;
87-
int g = 7;
8871
}
8972
while (true) {
9073
int a = 1;
9174
int b = 2;
9275
int c = 3;
9376
int d = 4;
9477
int e = 5;
95-
int f = 6;
96-
int g = 7;
9778
}
9879
while (true) {
9980
int a = 1;
10081
int b = 2;
10182
int c = 3;
10283
int d = 4;
10384
int e = 5;
104-
int f = 6;
105-
int g = 7;
10685
}
10786
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
| BlockWithTooManyStatements.cpp:1:26:38:1 | { ... } | Block with too many statements (4 complex statements in the block). |
2-
| BlockWithTooManyStatements.cpp:40:26:77:1 | { ... } | Block with too many statements (4 complex statements in the block). |
1+
| BlockWithTooManyStatements.cpp:1:22:62:1 | { ... } | Block with too many statements (5 complex statements in the block). |
Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
void complex_condition_one(bool a, bool b, bool c, bool d, bool e, bool f, bool g, bool h, bool i, bool j,
2-
bool k, bool l) {
3-
if (a && b || c && d || e && f || g && h || i && j || k && l) { // $ Alert
1+
void complex_condition(bool a, bool b, bool c, bool d, bool e, bool f, bool g, bool h, bool i, bool j,
2+
bool k, bool l, bool m, bool n, bool o) {
3+
if (a || b && c || d && e || f && g || h && i || j && k || l && m || n && o) { // $ Alert
44
}
55
}
66

7-
void complex_condition_two(bool a, bool b, bool c, bool d, bool e, bool f, bool g, bool h, bool i, bool j,
8-
bool k, bool l, bool m) {
9-
if (a || b && c || d && e || f && g || h && i || j && k || l && m) { // $ Alert
10-
}
11-
}
12-
13-
void five_logical_operations_is_not_enough(bool a, bool b, bool c, bool d, bool e, bool f) {
7+
void not_complex_condition(bool a, bool b, bool c, bool d, bool e, bool f) {
148
if (a && b || c && d || e && f) {
159
}
1610
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
| ComplexCondition.cpp:3:7:3:62 | ... \|\| ... | Complex condition: too many logical operations in this expression. |
2-
| ComplexCondition.cpp:9:7:9:67 | ... \|\| ... | Complex condition: too many logical operations in this expression. |
1+
| ComplexCondition.cpp:3:7:3:77 | ... \|\| ... | Complex condition: too many logical operations in this expression. |
Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,25 @@
1-
void multiple_forward_and_backward_targets_one() { // $ Alert
2-
goto forward_one;
3-
goto forward_two;
4-
forward_one:
5-
;
6-
forward_two:
7-
;
1+
bool cond();
2+
3+
void multiple_forward_and_backward_goto() { // $ Alert
84
backward_one:
9-
;
5+
if (cond()) goto forward_one;
106
backward_two:
11-
;
12-
goto backward_one;
13-
goto backward_two;
7+
if (cond()) goto forward_two;
8+
forward_one:
9+
if (cond()) goto backward_one;
10+
forward_two:
11+
if (cond()) goto backward_two;
1412
}
1513

16-
void multiple_forward_and_backward_targets_two() { // $ Alert
17-
goto next_one;
18-
goto next_two;
19-
next_one:
20-
;
21-
next_two:
22-
;
23-
earlier_one:
24-
;
25-
earlier_two:
26-
;
27-
goto earlier_one;
28-
goto earlier_two;
29-
}
14+
void only_forward_goto() {
15+
if (cond()) goto end;
3016

31-
void one_forward_target_is_not_enough() {
32-
goto forward;
33-
forward:
34-
;
35-
backward_one:
36-
;
37-
backward_two:
38-
;
39-
goto backward_one;
40-
goto backward_two;
17+
// ...
18+
19+
if (cond()) goto end;
20+
21+
// ...
22+
23+
end:
24+
// ...
4125
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
| UseOfGoto.cpp:1:6:1:46 | definition of multiple_forward_and_backward_targets_one | Multiple forward and backward goto statements may make function multiple_forward_and_backward_targets_one hard to understand. |
2-
| UseOfGoto.cpp:16:6:16:46 | definition of multiple_forward_and_backward_targets_two | Multiple forward and backward goto statements may make function multiple_forward_and_backward_targets_two hard to understand. |
1+
| UseOfGoto.cpp:3:6:3:39 | definition of multiple_forward_and_backward_goto | Multiple forward and backward goto statements may make function multiple_forward_and_backward_goto hard to understand. |

0 commit comments

Comments
 (0)