Skip to content
This repository was archived by the owner on Jul 17, 2024. It is now read-only.

Commit 78aec72

Browse files
committed
feat: sync Indictment API
1 parent 0c1f6cc commit 78aec72

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

tests/test_solution_manager.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class Entity:
3131
def my_constraints(constraint_factory: ConstraintFactory):
3232
return [
3333
constraint_factory.for_each(Entity)
34-
.reward(SimpleScore.ONE, lambda entity: entity.value)
35-
.as_constraint('package', 'Maximize Value'),
34+
.reward(SimpleScore.ONE, lambda entity: entity.value)
35+
.as_constraint('package', 'Maximize Value'),
3636
]
3737

3838

@@ -204,6 +204,7 @@ def test_score_manager_diff():
204204
constraint_analyses = score_analysis.constraint_analyses
205205
assert len(constraint_analyses) == 1
206206

207+
207208
def test_score_manager_constraint_analysis_map():
208209
solution_manager = SolutionManager.create(SolverFactory.create(solver_config))
209210
problem: Solution = Solution([Entity('A', 1), Entity('B', 1), Entity('C', 1)], [1, 2, 3])
@@ -230,24 +231,33 @@ def test_score_manager_constraint_analysis_map():
230231
'compareTo',
231232
}
232233

234+
ignored_java_functions_per_class = {
235+
'Indictment': {'getJustification'} # deprecated
236+
}
237+
233238

234239
def test_has_all_methods():
235240
missing = []
236241
for python_type, java_type in ((ScoreExplanation, JavaScoreExplanation),
237242
(ScoreAnalysis, JavaScoreAnalysis),
238243
(ConstraintAnalysis, JavaConstraintAnalysis),
239244
(ScoreExplanation, JavaScoreExplanation),
240-
(ConstraintMatch, JavaConstraintMatch),
241-
(ConstraintMatchTotal, JavaConstraintMatchTotal),
242245
(Indictment, JavaIndictment)):
246+
type_name = python_type.__name__
247+
ignored_java_functions_type = ignored_java_functions_per_class[
248+
type_name] if type_name in ignored_java_functions_per_class else {}
249+
243250
for function_name, function_impl in inspect.getmembers(java_type, inspect.isfunction):
244-
if function_name in ignored_java_functions:
251+
if function_name in ignored_java_functions or function_name in ignored_java_functions_type:
245252
continue
246253

247254
snake_case_name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', function_name)
248255
snake_case_name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', snake_case_name).lower()
249-
snake_case_name_without_prefix = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', function_name[3:] if function_name.startswith("get") else function_name)
250-
snake_case_name_without_prefix = re.sub('([a-z0-9])([A-Z])', r'\1_\2', snake_case_name_without_prefix).lower()
256+
snake_case_name_without_prefix = re.sub('(.)([A-Z][a-z]+)', r'\1_\2',
257+
function_name[3:] if function_name.startswith(
258+
"get") else function_name)
259+
snake_case_name_without_prefix = re.sub('([a-z0-9])([A-Z])', r'\1_\2',
260+
snake_case_name_without_prefix).lower()
251261
if not hasattr(python_type, snake_case_name) and not hasattr(python_type, snake_case_name_without_prefix):
252262
missing.append((java_type, python_type, snake_case_name))
253263

timefold-solver-python-core/src/main/python/score/_score_analysis.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ class Indictment(Generic[Score_]):
243243
The object that was involved in causing the constraints to match.
244244
It is part of `ConstraintMatch.indicted_objects` of every `ConstraintMatch`
245245
in `constraint_match_set`.
246+
246247
"""
247248
def __init__(self, delegate: '_JavaIndictment[Score_]'):
248249
self._delegate = delegate

0 commit comments

Comments
 (0)