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