James Kuszmaul | 6035c32 | 2024-01-31 22:27:53 -0800 | [diff] [blame] | 1 | #include "frc971/math/interpolate.h" |
| 2 | |
| 3 | #include "gtest/gtest.h" |
| 4 | #include <Eigen/Core> |
| 5 | |
| 6 | namespace frc971::math::testing { |
| 7 | // Tests that when we "interpolate" exactly to the ends of the interpolation |
| 8 | // that we get the correct result. |
| 9 | TEST(InterpolateTest, ExactEnds) { |
| 10 | const Eigen::Vector3d a(1.0, 2.0, 3.0), b(4.0, 5.0, 6.0); |
| 11 | ASSERT_EQ(a, lerp(a, b, 0.0)); |
| 12 | ASSERT_EQ(Eigen::Vector3d(2.5, 3.5, 4.5), lerp(a, b, 0.5)); |
| 13 | ASSERT_EQ(b, lerp(a, b, 1.0)); |
| 14 | |
| 15 | ASSERT_EQ(a, Interpolate(10.0, 20.0, a, b, 10.0)); |
| 16 | ASSERT_EQ(b, Interpolate(10.0, 20.0, a, b, 20.0)); |
| 17 | ASSERT_EQ(Eigen::Vector3d(2.5, 3.5, 4.5), |
| 18 | Interpolate(10.0, 20.0, a, b, 15.0)); |
| 19 | } |
| 20 | } // namespace frc971::math::testing |