mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpimath] Add InterpolatedTreeMap (#4073)
- Add InterpolatedTreeMap for Java from team 254's 2016 MIT licensed code - Add InterpolatedMap for C++ from team 3512's code with @calcmogul (original author) permission Co-authored-by: Tyler Veness <calcmogul@gmail.com>
This commit is contained in:
52
wpiutil/src/test/native/cpp/InterpolatingMapTest.cpp
Normal file
52
wpiutil/src/test/native/cpp/InterpolatingMapTest.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "wpi/interpolating_map.h" // NOLINT(build/include_order)
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(InterpolatingMapTest, Insert) {
|
||||
wpi::interpolating_map<double, double> table;
|
||||
|
||||
table.insert(125, 450);
|
||||
table.insert(200, 510);
|
||||
table.insert(268, 525);
|
||||
table.insert(312, 550);
|
||||
table.insert(326, 650);
|
||||
|
||||
// Key below minimum gives smallest value
|
||||
EXPECT_EQ(450, table[100]);
|
||||
|
||||
// Minimum key gives exact value
|
||||
EXPECT_EQ(450, table[125]);
|
||||
|
||||
// Key gives interpolated value
|
||||
EXPECT_EQ(480, table[162.5]);
|
||||
|
||||
// Key at right of interpolation range gives exact value
|
||||
EXPECT_EQ(510, table[200]);
|
||||
|
||||
// Maximum key gives exact value
|
||||
EXPECT_EQ(650, table[326]);
|
||||
|
||||
// Key above maximum gives largest value
|
||||
EXPECT_EQ(650, table[400]);
|
||||
}
|
||||
|
||||
TEST(InterpolatingMapTest, Clear) {
|
||||
wpi::interpolating_map<double, double> table;
|
||||
|
||||
table.insert(125, 450);
|
||||
table.insert(200, 510);
|
||||
table.insert(268, 525);
|
||||
table.insert(312, 550);
|
||||
table.insert(326, 650);
|
||||
|
||||
table.clear();
|
||||
|
||||
table.insert(100, 250);
|
||||
table.insert(200, 500);
|
||||
|
||||
EXPECT_EQ(375, table[150]);
|
||||
}
|
||||
Reference in New Issue
Block a user