From ac29b5213f2c242fccec51a019416ef40ab86e5f Mon Sep 17 00:00:00 2001 From: "Alinson S. Xavier" Date: Thu, 1 Apr 2021 07:21:44 -0500 Subject: [PATCH] Objective: Add tests --- tests/components/test_objective.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/components/test_objective.py b/tests/components/test_objective.py index 1a5835b..a0f9215 100644 --- a/tests/components/test_objective.py +++ b/tests/components/test_objective.py @@ -8,11 +8,12 @@ from unittest.mock import Mock import numpy as np from numpy.testing import assert_array_equal +from miplearn import GurobiPyomoSolver, LearningSolver from miplearn.instance import Instance from miplearn.classifiers import Regressor from miplearn.components.objective import ObjectiveValueComponent from miplearn.types import TrainingSample, Features -from tests.fixtures.knapsack import get_test_pyomo_instances +from tests.fixtures.knapsack import get_test_pyomo_instances, get_knapsack_instance def test_x_y_predict() -> None: @@ -151,3 +152,13 @@ def test_xy_sample_without_lp() -> None: x_actual, y_actual = xy assert x_actual == x_expected assert y_actual == y_expected + + +def test_usage(): + solver = LearningSolver(components=[ObjectiveValueComponent()]) + instance = get_knapsack_instance(GurobiPyomoSolver()) + solver.solve(instance) + solver.fit([instance]) + stats = solver.solve(instance) + assert stats["Lower bound"] == stats["Objective: predicted LB"] + assert stats["Upper bound"] == stats["Objective: predicted UB"]