Templatize interpolation table to make it more geneirc.
Change-Id: I7da0698486775b3e2482fa99fa172d6e1b6028ac
diff --git a/frc971/shooter_interpolation/interpolation_test.cc b/frc971/shooter_interpolation/interpolation_test.cc
index 120975d..fd99124 100644
--- a/frc971/shooter_interpolation/interpolation_test.cc
+++ b/frc971/shooter_interpolation/interpolation_test.cc
@@ -11,44 +11,57 @@
namespace frc971 {
namespace shooter_interpolation {
-bool operator==(ShotParams a1, ShotParams a2) {
+struct TestShotParams {
+ double angle;
+ double power;
+ static TestShotParams BlendY(double x, const TestShotParams& a, const TestShotParams& b) {
+ return TestShotParams{
+ Blend(x, a.angle, b.angle),
+ Blend(x, a.power, b.power)
+ };
+ }
+};
+
+bool operator==(TestShotParams a1, TestShotParams a2) {
return a1.angle == a2.angle && a1.power == a2.power;
}
+using TestInterpolationTable = InterpolationTable<TestShotParams>;
+
// Tests to see if distances whose values are on the table are processed
// correctly
TEST(InterpolationTable, ExactNumbers) {
- ::std::vector<::std::pair<double, ShotParams>> data{
+ ::std::vector<::std::pair<double, TestShotParams>> data = {
{1, {10, 10}}, {3, {20, 20}}, {2, {15, 12345678}}, {4, {10, 567.323}},
};
- InterpolationTable interpolation(data);
- ASSERT_EQ(data[1].second, interpolation.GetShooterData(3));
- ASSERT_EQ(data[3].second, interpolation.GetShooterData(4));
+ TestInterpolationTable interpolation(data);
+ ASSERT_EQ(data[1].second, interpolation.Get(3));
+ ASSERT_EQ(data[3].second, interpolation.Get(4));
}
// Tests to see if distances whose values are off the table are processed
// correctly
TEST(InterpolationTable, InexactNumbers) {
- ::std::vector<::std::pair<double, ShotParams>> data{
+ ::std::vector<::std::pair<double, TestShotParams>> data = {
{1, {10, 10}}, {3, {20, 20}}, {2, {15, 15}}, {4, {10, 567.323}},
};
- InterpolationTable interpolation(data);
- ASSERT_EQ(ShotParams({12.5, 12.5}), interpolation.GetShooterData(1.5));
- ASSERT_EQ(ShotParams({10, 10}), interpolation.GetShooterData(0));
+ TestInterpolationTable interpolation(data);
+ ASSERT_EQ(TestShotParams({12.5, 12.5}), interpolation.Get(1.5));
+ ASSERT_EQ(TestShotParams({10, 10}), interpolation.Get(0));
}
// Tests to see if distances whose values are beyond the range of the table are
// processed correctly
TEST(InterpolationTable, OutOfScopeNumbers) {
- ::std::vector<::std::pair<double, ShotParams>> data{
+ ::std::vector<::std::pair<double, TestShotParams>> data = {
{1, {10, 10}}, {3, {20, 20}}, {2, {15, 12345678}}, {4, {10, 567.323}},
};
- InterpolationTable interpolation(data);
- ASSERT_EQ(ShotParams({10, 10}), interpolation.GetShooterData(0));
- ASSERT_EQ(ShotParams({10, 567.323}), interpolation.GetShooterData(5));
+ TestInterpolationTable interpolation(data);
+ ASSERT_EQ(TestShotParams({10, 10}), interpolation.Get(0));
+ ASSERT_EQ(TestShotParams({10, 567.323}), interpolation.Get(5));
}
} // namespace shooter_interpolation