Skip to content

Commit 53921ff

Browse files
GCI97 OptimizeSquareComputation update: add integrations/real tests
Co-authored-by: DataLabGroupe-CreditAgricole <[email protected]>
1 parent 5fe0adf commit 53921ff

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12-
- Add rule GCI99 Optimize square computation (scalar vs vectorized method)
12+
- Add rule GCI97 Optimize square computation (scalar vs vectorized method)
13+
- Add rule GCI97 units tests
14+
- Add rule GCI97 integration tests
1315

1416
### Changed
1517

src/it/java/org/greencodeinitiative/creedengo/python/integration/tests/GCIRulesIT.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,4 +273,19 @@ void testGCI203_compliant() {
273273

274274
}
275275

276+
@Test
277+
void testGCI97(){
278+
String filePath = "src/optimizeSquareComputation.py";
279+
String ruleId = "creedengo-python:GCI97";
280+
String ruleMsg = "Use x*x instead of x**2 or math.pow(x,2) to calculate the square of a value";
281+
int[] startLines = new int[]{
282+
4, 7, 19, 20, 25, 26, 31, 38
283+
};
284+
int[] endLines = new int[]{
285+
4, 7, 19, 20, 25, 26, 31, 38
286+
};
287+
288+
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_1MIN);
289+
}
290+
276291
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import math
2+
3+
x = 5
4+
result1 = x**2 # Noncompliant {{Use x*x instead of x**2 or math.pow(x,2) to calculate the square of a value}}
5+
6+
z = 7
7+
result4 = math.pow(z, 2) # Noncompliant {{Use x*x instead of x**2 or math.pow(x,2) to calculate the square of a value}}
8+
9+
a = 3
10+
result5 = a*a
11+
12+
b = 4
13+
result6 = b*3
14+
result7 = 5*b
15+
result8 = math.pow(b, 3)
16+
result9 = b**3
17+
18+
c = 2.5
19+
result10 = c**2 # Noncompliant {{Use x*x instead of x**2 or math.pow(x,2) to calculate the square of a value}}
20+
result11 = math.pow(c, 2) # Noncompliant {{Use x*x instead of x**2 or math.pow(x,2) to calculate the square of a value}}
21+
22+
23+
d = 8
24+
e = 9
25+
result12 = math.pow(d+e, 2) # Noncompliant {{Use x*x instead of x**2 or math.pow(x,2) to calculate the square of a value}}
26+
result13 = (d+e)**2 # Noncompliant {{Use x*x instead of x**2 or math.pow(x,2) to calculate the square of a value}}
27+
result14 = (d+e)*(d+e)
28+
29+
30+
def square(x):
31+
return x**2 # Noncompliant {{Use x*x instead of x**2 or math.pow(x,2) to calculate the square of a value}}
32+
33+
def better_square(x):
34+
return x*x
35+
36+
37+
import math as m
38+
result15 = m.pow(d, 2) # Noncompliant {{Use x*x instead of x**2 or math.pow(x,2) to calculate the square of a value}}
39+
40+
result16 = math.sqrt(d)
41+
result17 = math.sin(d)
42+
result18 = math.pow(d, 1.5)

src/main/resources/org/greencodeinitiative/creedengo/python/creedengo_way_profile.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"GCI74",
1212
"GCI89",
1313
"GCI203",
14-
"GCI404"
14+
"GCI404",
15+
"GCI97"
1516
]
1617
}

0 commit comments

Comments
 (0)