blob: 120975d3b859b90ab7146c2f14b1647085be006f [file] [log] [blame]
Philipp Schradere8ad6382017-04-09 21:51:21 +00001#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
11namespace frc971 {
12namespace shooter_interpolation {
13
14bool 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
20TEST(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
32TEST(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
44TEST(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