Philipp Schrader | e8ad638 | 2017-04-09 21:51:21 +0000 | [diff] [blame^] | 1 | #include <unistd.h> |
| 2 | |
| 3 | #include <memory> |
| 4 | #include <random> |
| 5 | #include <utility> |
| 6 | |
| 7 | #include "gtest/gtest.h" |
| 8 | |
| 9 | #include "frc971/shooter_interpolation/interpolation.h" |
| 10 | |
| 11 | namespace frc971 { |
| 12 | namespace shooter_interpolation { |
| 13 | |
| 14 | bool operator==(ShotParams a1, ShotParams a2) { |
| 15 | return a1.angle == a2.angle && a1.power == a2.power; |
| 16 | } |
| 17 | |
| 18 | // Tests to see if distances whose values are on the table are processed |
| 19 | // correctly |
| 20 | TEST(InterpolationTable, ExactNumbers) { |
| 21 | ::std::vector<::std::pair<double, ShotParams>> data{ |
| 22 | {1, {10, 10}}, {3, {20, 20}}, {2, {15, 12345678}}, {4, {10, 567.323}}, |
| 23 | }; |
| 24 | |
| 25 | InterpolationTable interpolation(data); |
| 26 | ASSERT_EQ(data[1].second, interpolation.GetShooterData(3)); |
| 27 | ASSERT_EQ(data[3].second, interpolation.GetShooterData(4)); |
| 28 | } |
| 29 | |
| 30 | // Tests to see if distances whose values are off the table are processed |
| 31 | // correctly |
| 32 | TEST(InterpolationTable, InexactNumbers) { |
| 33 | ::std::vector<::std::pair<double, ShotParams>> data{ |
| 34 | {1, {10, 10}}, {3, {20, 20}}, {2, {15, 15}}, {4, {10, 567.323}}, |
| 35 | }; |
| 36 | |
| 37 | InterpolationTable interpolation(data); |
| 38 | ASSERT_EQ(ShotParams({12.5, 12.5}), interpolation.GetShooterData(1.5)); |
| 39 | ASSERT_EQ(ShotParams({10, 10}), interpolation.GetShooterData(0)); |
| 40 | } |
| 41 | |
| 42 | // Tests to see if distances whose values are beyond the range of the table are |
| 43 | // processed correctly |
| 44 | TEST(InterpolationTable, OutOfScopeNumbers) { |
| 45 | ::std::vector<::std::pair<double, ShotParams>> data{ |
| 46 | {1, {10, 10}}, {3, {20, 20}}, {2, {15, 12345678}}, {4, {10, 567.323}}, |
| 47 | }; |
| 48 | |
| 49 | InterpolationTable interpolation(data); |
| 50 | ASSERT_EQ(ShotParams({10, 10}), interpolation.GetShooterData(0)); |
| 51 | ASSERT_EQ(ShotParams({10, 567.323}), interpolation.GetShooterData(5)); |
| 52 | } |
| 53 | |
| 54 | } // namespace shooter_interpolation |
| 55 | } // namespace frc971 |