Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PLANNER-458 ScoreVerifier for each score impl
- Loading branch information
Showing
14 changed files
with
856 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
...taplanner/test/impl/score/buildin/bendablebigdecimal/BendableBigDecimalScoreVerifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Copyright 2016 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.optaplanner.test.impl.score.buildin.bendablebigdecimal; | ||
|
||
import java.math.BigDecimal; | ||
|
||
import org.optaplanner.core.api.domain.solution.PlanningSolution; | ||
import org.optaplanner.core.api.score.buildin.bendablebigdecimal.BendableBigDecimalScore; | ||
import org.optaplanner.core.api.solver.SolverFactory; | ||
import org.optaplanner.core.impl.score.buildin.bendablebigdecimal.BendableBigDecimalScoreDefinition; | ||
import org.optaplanner.test.impl.score.AbstractScoreVerifier; | ||
|
||
/** | ||
* To assert the constraints (including score rules) of a {@link SolverFactory} | ||
* that uses a {@link BendableBigDecimalScore}. | ||
* @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation | ||
*/ | ||
public class BendableBigDecimalScoreVerifier<Solution_> extends AbstractScoreVerifier<Solution_> { | ||
|
||
protected final int hardLevelsSize; | ||
|
||
/** | ||
* @param solverFactory never null, the {@link SolverFactory} of which you want to test the constraints. | ||
*/ | ||
public BendableBigDecimalScoreVerifier(SolverFactory<Solution_> solverFactory) { | ||
super(solverFactory, BendableBigDecimalScore.class); | ||
hardLevelsSize = ((BendableBigDecimalScoreDefinition) scoreDirectorFactory.getScoreDefinition()).getHardLevelsSize(); | ||
} | ||
|
||
/** | ||
* Assert that the constraint (which is usually a score rule) of {@link PlanningSolution} | ||
* has the expected weight for that score level | ||
* @param constraintName never null, the name of the constraint, which is usually the name of the score rule | ||
* @param hardLevel {@code 0 <= hardLevel <} {@code hardLevelSize}. | ||
* The {@code scoreLevel} is {@code hardLevel} for hard levels and {@code softLevel + hardLevelSize} for soft levels. | ||
* @param expectedWeight never null, the total weight for all matches of that 1 constraint | ||
* @param solution never null, the actual {@link PlanningSolution} | ||
*/ | ||
public void assertHardWeight(String constraintName, int hardLevel, BigDecimal expectedWeight, Solution_ solution) { | ||
assertHardWeight(null, constraintName, hardLevel, expectedWeight, solution); | ||
} | ||
|
||
/** | ||
* Assert that the constraint (which is usually a score rule) of {@link PlanningSolution} | ||
* has the expected weight for that score level. | ||
* @param constraintPackage sometimes null. | ||
* When null, {@code constraintName} for the {@code scoreLevel} must be unique. | ||
* @param constraintName never null, the name of the constraint, which is usually the name of the score rule | ||
* @param hardLevel {@code 0 <= hardLevel <} {@code hardLevelSize}. | ||
* The {@code scoreLevel} is {@code hardLevel} for hard levels and {@code softLevel + hardLevelSize} for soft levels. | ||
* @param expectedWeight never null, the total weight for all matches of that 1 constraint | ||
* @param solution never null, the actual {@link PlanningSolution} | ||
*/ | ||
public void assertHardWeight(String constraintPackage, String constraintName, | ||
int hardLevel, BigDecimal expectedWeight, | ||
Solution_ solution) { | ||
assertWeight(constraintPackage, constraintName, | ||
hardLevel, expectedWeight, solution); | ||
} | ||
|
||
/** | ||
* Assert that the constraint (which is usually a score rule) of {@link PlanningSolution} | ||
* has the expected weight for that score level. | ||
* @param constraintName never null, the name of the constraint, which is usually the name of the score rule | ||
* @param softLevel {@code 0 <= softLevel <} {@code softLevelSize}. | ||
* The {@code scoreLevel} is {@code hardLevel} for hard levels and {@code softLevel + hardLevelSize} for soft levels. | ||
* @param expectedWeight never null, the total weight for all matches of that 1 constraint | ||
* @param solution never null, the actual {@link PlanningSolution} | ||
*/ | ||
public void assertSoftWeight(String constraintName, int softLevel, BigDecimal expectedWeight, Solution_ solution) { | ||
assertSoftWeight(null, constraintName, softLevel, expectedWeight, solution); | ||
} | ||
|
||
/** | ||
* Assert that the constraint (which is usually a score rule) of {@link PlanningSolution} | ||
* has the expected weight for that score level. | ||
* @param constraintPackage sometimes null. | ||
* When null, {@code constraintName} for the {@code scoreLevel} must be unique. | ||
* @param constraintName never null, the name of the constraint, which is usually the name of the score rule | ||
* @param softLevel {@code 0 <= softLevel <} {@code softLevelSize}. | ||
* The {@code scoreLevel} is {@code hardLevel} for hard levels and {@code softLevel + hardLevelSize} for soft levels. | ||
* @param expectedWeight never null, the total weight for all matches of that 1 constraint | ||
* @param solution never null, the actual {@link PlanningSolution} | ||
*/ | ||
public void assertSoftWeight(String constraintPackage, String constraintName, int softLevel, BigDecimal expectedWeight, | ||
Solution_ solution) { | ||
assertWeight(constraintPackage, constraintName, | ||
hardLevelsSize + softLevel, expectedWeight, solution); | ||
} | ||
|
||
} |
Oops, something went wrong.