Skip to content

Commit

Permalink
Pull in Sleipnir test
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul committed Apr 28, 2024
1 parent f762ee9 commit 2fea7b7
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions wpimath/src/test/native/cpp/SleipnirTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

#include <gtest/gtest.h>
#include <sleipnir/optimization/OptimizationProblem.hpp>

TEST(SleipnirTest, Quartic) {
sleipnir::OptimizationProblem problem;

auto x = problem.DecisionVariable();
x.SetValue(20.0);

problem.Minimize(sleipnir::pow(x, 4));

problem.SubjectTo(x >= 1);

auto status = problem.Solve({.diagnostics = true});

EXPECT_EQ(status.costFunctionType, sleipnir::ExpressionType::kNonlinear);
EXPECT_EQ(status.equalityConstraintType, sleipnir::ExpressionType::kNone);
EXPECT_EQ(status.inequalityConstraintType, sleipnir::ExpressionType::kLinear);
EXPECT_EQ(status.exitCondition, sleipnir::SolverExitCondition::kSuccess);

EXPECT_NEAR(x.Value(), 1.0, 1e-6);
}

0 comments on commit 2fea7b7

Please sign in to comment.