/* * Copyright 2015 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.core.api.score.buildin.simpledouble; import org.junit.Test; import org.kie.api.runtime.rule.RuleContext; import org.optaplanner.core.api.score.holder.AbstractScoreHolderTest; import static org.junit.Assert.*; public class SimpleDoubleScoreHolderTest extends AbstractScoreHolderTest { @Test public void addConstraintMatchWithConstraintMatch() { addConstraintMatch(true); } @Test public void addConstraintMatchWithoutConstraintMatch() { addConstraintMatch(false); } public void addConstraintMatch(boolean constraintMatchEnabled) { SimpleDoubleScoreHolder scoreHolder = new SimpleDoubleScoreHolder(constraintMatchEnabled); RuleContext scoreRule1 = mockRuleContext("scoreRule1"); scoreHolder.addConstraintMatch(scoreRule1, -10.00); RuleContext scoreRule2 = mockRuleContext("scoreRule2"); scoreHolder.addConstraintMatch(scoreRule2, -2.00); callOnDelete(scoreRule2); RuleContext scoreRule3 = mockRuleContext("scoreRule3"); scoreHolder.addConstraintMatch(scoreRule3, -0.30); callOnUpdate(scoreRule3); scoreHolder.addConstraintMatch(scoreRule3, -0.03); // Overwrite existing assertEquals(SimpleDoubleScore.valueOfUninitialized(0, -10.03), scoreHolder.extractScore(0)); assertEquals(SimpleDoubleScore.valueOfUninitialized(-7, -10.03), scoreHolder.extractScore(-7)); if (constraintMatchEnabled) { assertEquals(SimpleDoubleScore.valueOf(-10.00), findConstraintMatchTotal(scoreHolder, "scoreRule1").getScoreTotal()); } } }