Skip to content

Commit 4bbe022

Browse files
test: Add test for PythonValueRangeFactory and use correct token name in Sonarcloud action (#64)
1 parent bc237c8 commit 4bbe022

File tree

3 files changed

+90
-4
lines changed

3 files changed

+90
-4
lines changed

.github/workflows/sonarcloud.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,5 @@ jobs:
110110
working-directory: ./timefold-solver-python
111111
env:
112112
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
113-
SONARCLOUD_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }}
113+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
114114
run: mvn -B -Psonarcloud-analysis validate org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.organization=timefold -Dsonar.projectKey=TimefoldAI_timefold-solver-python -Dsonar.host.url=https://sonarcloud.io -Dsonar.pullrequest.key=${{ github.event.pull_request.number }} -Dsonar.pullrequest.branch=${{ github.event.pull_request.head.ref }} -Dsonar.scm.revision=${{ github.event.pull_request.head.sha }}

pom.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@
1515
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1616
<version.apache.collections4>4.4</version.apache.collections4>
1717
<maven.compiler.release>17</maven.compiler.release>
18-
<sonar.moduleKey>${project.artifactId}</sonar.moduleKey>
19-
<sonar.organization>timefold</sonar.organization>
18+
<sonar.moduleKey>${project.groupId}:${project.artifactId}</sonar.moduleKey>
2019
<sonar.sources>src/main/java,src/main/python</sonar.sources>
2120
<sonar.tests>src/test/java,tests</sonar.tests>
22-
<sonar.python.version>3.9,3.10,3.11</sonar.python.version>
21+
<sonar.python.version>3.10,3.11,3.12</sonar.python.version>
2322
<sonar.python.coverage.reportPaths>target/coverage.xml,jpyinterpreter/target/coverage.xml</sonar.python.coverage.reportPaths>
2423
</properties>
2524

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package ai.timefold.solver.python;
2+
3+
import static org.assertj.core.api.Assertions.as;
4+
import static org.assertj.core.api.Assertions.assertThat;
5+
6+
import java.math.BigDecimal;
7+
import java.math.BigInteger;
8+
9+
import ai.timefold.jpyinterpreter.types.numeric.PythonBoolean;
10+
import ai.timefold.jpyinterpreter.types.numeric.PythonFloat;
11+
import ai.timefold.jpyinterpreter.types.numeric.PythonInteger;
12+
import ai.timefold.solver.core.api.domain.valuerange.CountableValueRange;
13+
14+
import org.assertj.core.api.InstanceOfAssertFactories;
15+
import org.junit.jupiter.api.Test;
16+
17+
class PythonValueRangeFactoryTest {
18+
19+
@Test
20+
void createIntValueRange() {
21+
assertThat(PythonValueRangeFactory.createIntValueRange(BigInteger.valueOf(10), BigInteger.valueOf(15)))
22+
.extracting(CountableValueRange::createOriginalIterator,
23+
as(InstanceOfAssertFactories.iterator(PythonInteger.class)))
24+
.toIterable()
25+
.containsExactly(
26+
PythonInteger.valueOf(10),
27+
PythonInteger.valueOf(11),
28+
PythonInteger.valueOf(12),
29+
PythonInteger.valueOf(13),
30+
PythonInteger.valueOf(14));
31+
}
32+
33+
@Test
34+
void createIntValueRangeWithStep() {
35+
assertThat(PythonValueRangeFactory.createIntValueRange(BigInteger.valueOf(10), BigInteger.valueOf(20),
36+
BigInteger.valueOf(2)))
37+
.extracting(CountableValueRange::createOriginalIterator,
38+
as(InstanceOfAssertFactories.iterator(PythonInteger.class)))
39+
.toIterable()
40+
.containsExactly(
41+
PythonInteger.valueOf(10),
42+
PythonInteger.valueOf(12),
43+
PythonInteger.valueOf(14),
44+
PythonInteger.valueOf(16),
45+
PythonInteger.valueOf(18));
46+
}
47+
48+
@Test
49+
void createFloatValueRange() {
50+
assertThat(PythonValueRangeFactory.createFloatValueRange(BigDecimal.valueOf(10), BigDecimal.valueOf(15)))
51+
.extracting(CountableValueRange::createOriginalIterator,
52+
as(InstanceOfAssertFactories.iterator(PythonFloat.class)))
53+
.toIterable()
54+
.containsExactly(
55+
PythonFloat.valueOf(10),
56+
PythonFloat.valueOf(11),
57+
PythonFloat.valueOf(12),
58+
PythonFloat.valueOf(13),
59+
PythonFloat.valueOf(14));
60+
}
61+
62+
@Test
63+
void createFloatValueRangeWithStep() {
64+
assertThat(PythonValueRangeFactory.createFloatValueRange(BigDecimal.valueOf(10), BigDecimal.valueOf(20),
65+
BigDecimal.valueOf(2)))
66+
.extracting(CountableValueRange::createOriginalIterator,
67+
as(InstanceOfAssertFactories.iterator(PythonFloat.class)))
68+
.toIterable()
69+
.containsExactly(
70+
PythonFloat.valueOf(10),
71+
PythonFloat.valueOf(12),
72+
PythonFloat.valueOf(14),
73+
PythonFloat.valueOf(16),
74+
PythonFloat.valueOf(18));
75+
}
76+
77+
@Test
78+
void createBooleanValueRange() {
79+
assertThat(PythonValueRangeFactory.createBooleanValueRange())
80+
.extracting(CountableValueRange::createOriginalIterator,
81+
as(InstanceOfAssertFactories.iterator(PythonBoolean.class)))
82+
.toIterable()
83+
.containsExactly(
84+
PythonBoolean.FALSE,
85+
PythonBoolean.TRUE);
86+
}
87+
}

0 commit comments

Comments
 (0)