Austin Schuh | acd335a | 2017-01-01 16:20:54 -0800 | [diff] [blame^] | 1 | #include "frc971/control_loops/runge_kutta.h" |
| 2 | |
| 3 | #include "gtest/gtest.h" |
| 4 | |
| 5 | namespace frc971 { |
| 6 | namespace control_loops { |
| 7 | namespace testing { |
| 8 | |
| 9 | // Tests that integrating dx/dt = e^x works. |
| 10 | TEST(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 |