blob: 680715aea5b4e5e187b09908c13ffb26dd3ee8ba [file] [log] [blame]
Austin Schuhacd335a2017-01-01 16:20:54 -08001#include "frc971/control_loops/runge_kutta.h"
2
3#include "gtest/gtest.h"
4
5namespace frc971 {
6namespace control_loops {
7namespace testing {
8
9// Tests that integrating dx/dt = e^x works.
10TEST(RungeKuttaTest, Exponential) {
11 ::Eigen::Matrix<double, 1, 1> y0;
12 y0(0, 0) = 0.0;
13
14 ::Eigen::Matrix<double, 1, 1> y1 = RungeKutta(
15 [](::Eigen::Matrix<double, 1, 1> x) {
16 ::Eigen::Matrix<double, 1, 1> y;
17 y(0, 0) = ::std::exp(x(0, 0));
18 return y;
19 },
20 y0, 0.1);
21 EXPECT_NEAR(y1(0, 0), ::std::exp(0.1) - ::std::exp(0), 1e-3);
22}
23
24} // namespace testing
25} // namespace control_loops
26} // namespace frc971