Austin Schuh | 173a159 | 2018-12-19 16:20:54 +1100 | [diff] [blame] | 1 | #include "frc971/control_loops/fixed_quadrature.h" |
| 2 | |
| 3 | #include <cmath> |
| 4 | |
| 5 | #include "gtest/gtest.h" |
| 6 | |
| 7 | namespace frc971 { |
| 8 | namespace control_loops { |
| 9 | namespace testing { |
| 10 | |
| 11 | // Tests that integrating y = cos(x) works. |
| 12 | TEST(GaussianQuadratureTest, Cos) { |
| 13 | double y1 = |
| 14 | GaussianQuadrature5([](double x) { return ::std::cos(x); }, 0.0, 0.5); |
| 15 | |
| 16 | EXPECT_NEAR(y1, ::std::sin(0.5), 1e-15); |
| 17 | } |
| 18 | |
Austin Schuh | a935a08 | 2023-02-20 21:45:54 -0800 | [diff] [blame^] | 19 | // Tests that integrating y = [cos(x), sin(x)] works. |
| 20 | TEST(GaussianQuadratureTest, MatrixCos) { |
| 21 | Eigen::Matrix<double, 2, 1> y1 = MatrixGaussianQuadrature5<2>( |
| 22 | [](double x) { |
| 23 | return Eigen::Matrix<double, 2, 1>(std::cos(x), std::sin(x)); |
| 24 | }, |
| 25 | 0.0, 0.5); |
| 26 | |
| 27 | EXPECT_TRUE(y1.isApprox(Eigen::Matrix<double, 2, 1>( |
| 28 | ::std::sin(0.5), -std::cos(0.5) + std::cos(0)))); |
| 29 | } |
| 30 | |
Austin Schuh | 173a159 | 2018-12-19 16:20:54 +1100 | [diff] [blame] | 31 | } // namespace testing |
| 32 | } // namespace control_loops |
| 33 | } // namespace frc971 |