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

Commit

Permalink
chore: Use properties to define score properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher-Chianelli committed Apr 25, 2024
1 parent 5e8c0bd commit 1eab762
Show file tree
Hide file tree
Showing 16 changed files with 177 additions and 119 deletions.
2 changes: 1 addition & 1 deletion tests/test_anchors.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
# ChainedEntity('3'),
# ]
# ))
# assert solution.score.score() == 9
# assert solution.score.score == 9
# anchor = solution.entities[0].anchor
# assert anchor is not None
# anchor_value_count = 0
Expand Down
6 changes: 3 additions & 3 deletions tests/test_collectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,23 +271,23 @@ def define_constraints(constraint_factory: ConstraintFactory):
entity_d.value = value_7
entity_e.value = value_9

assert score_manager.explain(problem).score.score() == 5
assert score_manager.explain(problem).score.score == 5

entity_a.value = value_1
entity_b.value = value_2
entity_c.value = value_3
entity_d.value = value_4
entity_e.value = value_5

assert score_manager.explain(problem).score.score() == 25
assert score_manager.explain(problem).score.score == 25

entity_a.value = value_1
entity_b.value = value_2
entity_c.value = value_3
entity_d.value = value_5
entity_e.value = value_6

assert score_manager.explain(problem).score.score() == 13
assert score_manager.explain(problem).score.score == 13


def test_to_list():
Expand Down
96 changes: 48 additions & 48 deletions tests/test_constraint_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ def define_constraints(constraint_factory: ConstraintFactory):

problem = Solution([entity_a, entity_b], [value_1])

assert score_manager.explain(problem).score.score() == 0
assert score_manager.explain(problem).score.score == 0

entity_a.value = value_1

assert score_manager.explain(problem).score.score() == 1
assert score_manager.explain(problem).score.score == 1

entity_b.value = value_1

assert score_manager.explain(problem).score.score() == 2
assert score_manager.explain(problem).score.score == 2


def test_filter_uni():
Expand All @@ -97,16 +97,16 @@ def define_constraints(constraint_factory: ConstraintFactory):

problem = Solution([entity_a, entity_b], [value_1, value_2])

assert score_manager.explain(problem).score.score() == 0
assert score_manager.explain(problem).score.score == 0
entity_a.value = value_1

assert score_manager.explain(problem).score.score() == 1
assert score_manager.explain(problem).score.score == 1

entity_b.value = value_2
assert score_manager.explain(problem).score.score() == 1
assert score_manager.explain(problem).score.score == 1

entity_b.value = value_1
assert score_manager.explain(problem).score.score() == 2
assert score_manager.explain(problem).score.score == 2


def test_filter_bi():
Expand All @@ -129,16 +129,16 @@ def define_constraints(constraint_factory: ConstraintFactory):

problem = Solution([entity_a, entity_b], [value_1, value_2])

assert score_manager.explain(problem).score.score() == 0
assert score_manager.explain(problem).score.score == 0
entity_a.value = value_1

assert score_manager.explain(problem).score.score() == 0
assert score_manager.explain(problem).score.score == 0

entity_b.value = value_1
assert score_manager.explain(problem).score.score() == 0
assert score_manager.explain(problem).score.score == 0

entity_b.value = value_2
assert score_manager.explain(problem).score.score() == 1
assert score_manager.explain(problem).score.score == 1


def test_filter_tri():
Expand All @@ -164,19 +164,19 @@ def define_constraints(constraint_factory: ConstraintFactory):

problem = Solution([entity_a, entity_b, entity_c], [value_1, value_2, value_3])

assert score_manager.explain(problem).score.score() == 0
assert score_manager.explain(problem).score.score == 0
entity_a.value = value_1

assert score_manager.explain(problem).score.score() == 0
assert score_manager.explain(problem).score.score == 0

entity_b.value = value_2
assert score_manager.explain(problem).score.score() == 0
assert score_manager.explain(problem).score.score == 0

entity_c.value = value_1
assert score_manager.explain(problem).score.score() == 0
assert score_manager.explain(problem).score.score == 0

entity_c.value = value_3
assert score_manager.explain(problem).score.score() == 1
assert score_manager.explain(problem).score.score == 1


def test_filter_quad():
Expand Down Expand Up @@ -206,22 +206,22 @@ def define_constraints(constraint_factory: ConstraintFactory):

problem = Solution([entity_a, entity_b, entity_c, entity_d], [value_1, value_2, value_3, value_4])

assert score_manager.explain(problem).score.score() == 0
assert score_manager.explain(problem).score.score == 0
entity_a.value = value_1

assert score_manager.explain(problem).score.score() == 0
assert score_manager.explain(problem).score.score == 0

entity_b.value = value_2
assert score_manager.explain(problem).score.score() == 0
assert score_manager.explain(problem).score.score == 0

entity_c.value = value_3
assert score_manager.explain(problem).score.score() == 0
assert score_manager.explain(problem).score.score == 0

entity_d.value = value_1
assert score_manager.explain(problem).score.score() == 0
assert score_manager.explain(problem).score.score == 0

entity_d.value = value_4
assert score_manager.explain(problem).score.score() == 1
assert score_manager.explain(problem).score.score == 1


def test_join_uni():
Expand All @@ -248,7 +248,7 @@ def define_constraints(constraint_factory: ConstraintFactory):

entity_a1.value = value_1

assert score_manager.explain(problem).score.score() == 0
assert score_manager.explain(problem).score.score == 0

entity_a1.value = value_1
entity_a2.value = value_1
Expand All @@ -257,13 +257,13 @@ def define_constraints(constraint_factory: ConstraintFactory):
entity_b2.value = value_2

# 1 * 1 + 1 * 1 + 2 * 2 + 2 * 2
assert score_manager.explain(problem).score.score() == 10
assert score_manager.explain(problem).score.score == 10

entity_a1.value = value_2
entity_b1.value = value_1

# 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2
assert score_manager.explain(problem).score.score() == 8
assert score_manager.explain(problem).score.score == 8


def test_map():
Expand All @@ -285,19 +285,19 @@ def define_constraints(constraint_factory: ConstraintFactory):

problem = Solution([entity_a, entity_b], [value_1, value_2])

assert score_manager.explain(problem).score.score() == 0
assert score_manager.explain(problem).score.score == 0

entity_a.value = value_1

assert score_manager.explain(problem).score.score() == 1
assert score_manager.explain(problem).score.score == 1

entity_b.value = value_1

assert score_manager.explain(problem).score.score() == 2
assert score_manager.explain(problem).score.score == 2

entity_b.value = value_2

assert score_manager.explain(problem).score.score() == 3
assert score_manager.explain(problem).score.score == 3


def test_multi_map():
Expand All @@ -319,19 +319,19 @@ def define_constraints(constraint_factory: ConstraintFactory):

problem = Solution([entity_a, entity_b], [value_1, value_2])

assert score_manager.explain(problem).score.score() == 0
assert score_manager.explain(problem).score.score == 0

entity_a.value = value_1

assert score_manager.explain(problem).score.score() == 11
assert score_manager.explain(problem).score.score == 11

entity_b.value = value_1

assert score_manager.explain(problem).score.score() == 23
assert score_manager.explain(problem).score.score == 23

entity_b.value = value_2

assert score_manager.explain(problem).score.score() == 33
assert score_manager.explain(problem).score.score == 33


def test_expand():
Expand All @@ -353,19 +353,19 @@ def define_constraints(constraint_factory: ConstraintFactory):

problem = Solution([entity_a, entity_b], [value_1, value_2])

assert score_manager.explain(problem).score.score() == 0
assert score_manager.explain(problem).score.score == 0

entity_a.value = value_1

assert score_manager.explain(problem).score.score() == 1
assert score_manager.explain(problem).score.score == 1

entity_b.value = value_1

assert score_manager.explain(problem).score.score() == 2
assert score_manager.explain(problem).score.score == 2

entity_b.value = value_2

assert score_manager.explain(problem).score.score() == 3
assert score_manager.explain(problem).score.score == 3


def test_multi_expand():
Expand All @@ -387,19 +387,19 @@ def define_constraints(constraint_factory: ConstraintFactory):

problem = Solution([entity_a, entity_b], [value_1, value_2])

assert score_manager.explain(problem).score.score() == 0
assert score_manager.explain(problem).score.score == 0

entity_a.value = value_1

assert score_manager.explain(problem).score.score() == 11
assert score_manager.explain(problem).score.score == 11

entity_b.value = value_1

assert score_manager.explain(problem).score.score() == 23
assert score_manager.explain(problem).score.score == 23

entity_b.value = value_2

assert score_manager.explain(problem).score.score() == 33
assert score_manager.explain(problem).score.score == 33


def test_concat():
Expand All @@ -423,19 +423,19 @@ def define_constraints(constraint_factory: ConstraintFactory):

problem = Solution([entity_a, entity_b], [value_1, value_2, value_3])

assert score_manager.explain(problem).score.score() == 0
assert score_manager.explain(problem).score.score == 0

entity_a.value = value_1

assert score_manager.explain(problem).score.score() == 1
assert score_manager.explain(problem).score.score == 1

entity_b.value = value_2

assert score_manager.explain(problem).score.score() == 2
assert score_manager.explain(problem).score.score == 2

entity_b.value = value_3

assert score_manager.explain(problem).score.score() == 1
assert score_manager.explain(problem).score.score == 1


def test_custom_indictments():
Expand Down Expand Up @@ -471,7 +471,7 @@ def define_constraints(constraint_factory: ConstraintFactory):
value_indictment = indictments[1]

assert a_indictment.indicted_object == MyIndictment('A')
assert a_indictment.score.score() == 1
assert a_indictment.score.score == 1
assert a_indictment.constraint_match_count == 1
assert a_indictment.constraint_match_set == {
ConstraintMatch(constraint_ref=ConstraintRef(package_name='my_package', constraint_name='Maximize value'),
Expand All @@ -484,7 +484,7 @@ def define_constraints(constraint_factory: ConstraintFactory):
}

assert b_indictment.indicted_object == MyIndictment('B')
assert b_indictment.score.score() == 1
assert b_indictment.score.score == 1
assert b_indictment.constraint_match_count == 1
assert b_indictment.constraint_match_set == {
ConstraintMatch(constraint_ref=ConstraintRef(package_name='my_package', constraint_name='Maximize value'),
Expand All @@ -497,7 +497,7 @@ def define_constraints(constraint_factory: ConstraintFactory):
}

assert value_indictment.indicted_object == 1
assert value_indictment.score.score() == 2
assert value_indictment.score.score == 2
assert value_indictment.constraint_match_count == 2
assert value_indictment.constraint_match_set == {
ConstraintMatch(constraint_ref=ConstraintRef(package_name='my_package', constraint_name='Maximize value'),
Expand Down
4 changes: 2 additions & 2 deletions tests/test_custom_shadow_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class MySolution:
solver = solver_factory.build_solver()
problem = MySolution([MyPlanningEntity()], [1, 2, 3])
solution: MySolution = solver.solve(problem)
assert solution.score.score() == 1
assert solution.score.score == 1
assert solution.entity_list[0].value == 2
assert solution.entity_list[0].value_squared == 4

Expand Down Expand Up @@ -117,6 +117,6 @@ class MySolution:
solver = solver_factory.build_solver()
problem = MySolution([MyPlanningEntity()], [1, 2, 3])
solution: MySolution = solver.solve(problem)
assert solution.score.score() == 1
assert solution.score.score == 1
assert solution.entity_list[0].value == 2
assert solution.entity_list[0].value_squared == 4
Loading

0 comments on commit 1eab762

Please sign in to comment.