Skip to content

Commit 98032fd

Browse files
committed
Add tests for GetNumberOfConstraints()
1 parent e535afb commit 98032fd

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

tsplp/src/MtspModel.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,7 @@ void tsplp::MtspModel::BranchAndCutSolve(
342342
auto top = queue.Pop(threadId);
343343
if (!top.has_value())
344344
{
345-
SPDLOG_INFO(
346-
"{}: thread {} exited because Pop returned nothing..", m_name, threadId);
345+
SPDLOG_INFO("{}: thread {} exited because Pop returned nothing.", m_name, threadId);
347346
break;
348347
}
349348

tsplp/test/tsplp-test.cpp

+14-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ TEST_CASE("3 variables, 3 constraints", "[lp]")
1212
{
1313
tsplp::Model model(3);
1414

15+
REQUIRE(model.GetBinaryVariables().size() == 3);
16+
CHECK(model.GetNumberOfConstraints() == 0);
17+
1518
auto x1 = model.GetBinaryVariables()[0];
1619
auto x2 = model.GetBinaryVariables()[1];
1720
auto x3 = model.GetBinaryVariables()[2];
@@ -26,20 +29,25 @@ TEST_CASE("3 variables, 3 constraints", "[lp]")
2629
auto objective = x1 + 4 * x2 + 9 * x3 - 10;
2730
model.SetObjective(objective);
2831

32+
CHECK(model.GetNumberOfConstraints() == 0);
33+
2934
auto c1 = x1 + x2 <= 5;
3035
auto c2 = x1 + x3 >= 10;
3136
auto c3 = -x2 + x3 == 7;
3237

33-
std::vector<tsplp::LinearConstraint> constraints { c1, c2, c3 };
38+
const std::vector<tsplp::LinearConstraint> constraints { c1, c2, c3 };
3439

3540
model.AddConstraints(constraints.cbegin(), constraints.cend());
3641

42+
CHECK(model.GetNumberOfConstraints() == 3);
43+
3744
using namespace std::chrono_literals;
3845
auto status = model.Solve(std::chrono::steady_clock::now() + 10ms);
3946

40-
REQUIRE(status == tsplp::Status::Optimal);
41-
REQUIRE(c1.Evaluate(model));
42-
REQUIRE(c2.Evaluate(model));
43-
REQUIRE(c3.Evaluate(model));
44-
REQUIRE(objective.Evaluate(model) == Approx(44));
47+
CHECK(model.GetNumberOfConstraints() == 3);
48+
CHECK(status == tsplp::Status::Optimal);
49+
CHECK(c1.Evaluate(model));
50+
CHECK(c2.Evaluate(model));
51+
CHECK(c3.Evaluate(model));
52+
CHECK(objective.Evaluate(model) == Approx(44));
4553
}

0 commit comments

Comments
 (0)