2
2
3
3
import static ai .timefold .solver .core .impl .score .director .InnerScoreDirector .getConstraintAnalysis ;
4
4
import static org .assertj .core .api .AssertionsForClassTypes .assertThat ;
5
+ import static org .assertj .core .api .AssertionsForClassTypes .assertThatThrownBy ;
5
6
import static org .assertj .core .api .SoftAssertions .assertSoftly ;
6
7
7
8
import java .util .Arrays ;
@@ -31,9 +32,9 @@ void empty() {
31
32
var summary = scoreAnalysis .summarize ();
32
33
assertThat (summary )
33
34
.isEqualTo ("""
34
- Explanation of score (0):
35
- Constraint matches:
36
- """ );
35
+ Explanation of score (0):
36
+ Constraint matches:
37
+ """ );
37
38
}
38
39
39
40
@ Test
@@ -62,7 +63,7 @@ void summarize() {
62
63
var constraintAnalysisMap = Map .of (
63
64
constraintMatchTotal .getConstraintRef (), getConstraintAnalysis (constraintMatchTotal , true ),
64
65
constraintMatchTotal2 .getConstraintRef (), getConstraintAnalysis (constraintMatchTotal2 , true ),
65
- emptyConstraintMatchTotal1 .getConstraintRef (), getConstraintAnalysis (emptyConstraintMatchTotal1 , false ));
66
+ emptyConstraintMatchTotal1 .getConstraintRef (), getConstraintAnalysis (emptyConstraintMatchTotal1 , true ));
66
67
var scoreAnalysis = new ScoreAnalysis <>(SimpleScore .of (67 ), constraintAnalysisMap );
67
68
68
69
// Single constraint analysis
@@ -80,6 +81,7 @@ Explanation of score (27):
80
81
81
82
// Complete score analysis
82
83
var summary = scoreAnalysis .summarize ();
84
+ assertThat (scoreAnalysis .getConstraintAnalysis (constraintPackage , constraintName1 ).matchCount ()).isEqualTo (5 );
83
85
assertThat (summary )
84
86
.isEqualTo ("""
85
87
Explanation of score (67):
@@ -98,6 +100,25 @@ Explanation of score (67):
98
100
""" );
99
101
}
100
102
103
+ @ Test
104
+ void failFastSummarize () {
105
+ var constraintPackage = "constraintPackage" ;
106
+ var constraintName1 = "constraint1" ;
107
+ var constraintId1 = ConstraintRef .of (constraintPackage , constraintName1 );
108
+
109
+ var constraintMatchTotal = new DefaultConstraintMatchTotal <>(constraintId1 , SimpleScore .of (1 ));
110
+ addConstraintMatch (constraintMatchTotal , SimpleScore .of (2 ), "A" , "B" , "C" );
111
+ var constraintAnalysisMap = Map .of (
112
+ constraintMatchTotal .getConstraintRef (), getConstraintAnalysis (constraintMatchTotal , false ));
113
+ var scoreAnalysis = new ScoreAnalysis <>(SimpleScore .of (3 ), constraintAnalysisMap );
114
+
115
+ assertThatThrownBy (scoreAnalysis ::summarize )
116
+ .hasMessageContaining ("The constraint matches must be non-null" );
117
+
118
+ assertThatThrownBy (() -> constraintAnalysisMap .values ().stream ().findFirst ().get ().matchCount ())
119
+ .hasMessageContaining ("The constraint matches must be non-null" );
120
+ }
121
+
101
122
@ Test
102
123
void compareWithConstraintMatchesWithoutMatchAnalysis () {
103
124
var constraintPackage = "constraintPackage" ;
0 commit comments