diff --git a/wpilibcIntegrationTests/src/main/native/cpp/CircularBufferTest.cpp b/wpilibc/src/test/native/cpp/CircularBufferTest.cpp similarity index 94% rename from wpilibcIntegrationTests/src/main/native/cpp/CircularBufferTest.cpp rename to wpilibc/src/test/native/cpp/CircularBufferTest.cpp index 276bc21e94..ada4f9a24f 100644 --- a/wpilibcIntegrationTests/src/main/native/cpp/CircularBufferTest.cpp +++ b/wpilibc/src/test/native/cpp/CircularBufferTest.cpp @@ -14,14 +14,14 @@ using namespace frc; static const std::array values = { - 751.848, 766.366, 342.657, 234.252, 716.126, - 132.344, 445.697, 22.727, 421.125, 799.913}; + {751.848, 766.366, 342.657, 234.252, 716.126, 132.344, 445.697, 22.727, + 421.125, 799.913}}; static const std::array pushFrontOut = { - 799.913, 421.125, 22.727, 445.697, 132.344, 716.126, 234.252, 342.657}; + {799.913, 421.125, 22.727, 445.697, 132.344, 716.126, 234.252, 342.657}}; static const std::array pushBackOut = { - 342.657, 234.252, 716.126, 132.344, 445.697, 22.727, 421.125, 799.913}; + {342.657, 234.252, 716.126, 132.344, 445.697, 22.727, 421.125, 799.913}}; TEST(CircularBufferTest, PushFrontTest) { circular_buffer queue(8); diff --git a/wpilibcIntegrationTests/src/main/native/cpp/FilterNoiseTest.cpp b/wpilibc/src/test/native/cpp/FilterNoiseTest.cpp similarity index 80% rename from wpilibcIntegrationTests/src/main/native/cpp/FilterNoiseTest.cpp rename to wpilibc/src/test/native/cpp/FilterNoiseTest.cpp index 58ab6b28a9..ea14f32f8d 100644 --- a/wpilibcIntegrationTests/src/main/native/cpp/FilterNoiseTest.cpp +++ b/wpilibc/src/test/native/cpp/FilterNoiseTest.cpp @@ -13,10 +13,20 @@ #include #include -#include "TestBench.h" #include "frc/Base.h" #include "gtest/gtest.h" +/* Filter constants */ +static constexpr double kFilterStep = 0.005; +static constexpr double kFilterTime = 2.0; +static constexpr double kSinglePoleIIRTimeConstant = 0.015915; +static constexpr double kSinglePoleIIRExpectedOutput = -3.2172003; +static constexpr double kHighPassTimeConstant = 0.006631; +static constexpr double kHighPassExpectedOutput = 10.074717; +static constexpr int32_t kMovAvgTaps = 6; +static constexpr double kMovAvgExpectedOutput = -10.191644; +static constexpr double kPi = 3.14159265358979323846; + using namespace frc; enum FilterNoiseTestType { TEST_SINGLE_POLE_IIR, TEST_MOVAVG }; @@ -53,18 +63,18 @@ class NoiseGenerator : public PIDSource { double PIDGet() override { m_noise = m_distr(m_gen); - m_count += TestBench::kFilterStep; + m_count += kFilterStep; return m_dataFunc(m_count) + m_noise; } - void Reset() { m_count = -TestBench::kFilterStep; } + void Reset() { m_count = -kFilterStep; } private: std::function m_dataFunc; double m_noise = 0.0; // Make sure first call to PIDGet() uses m_count == 0 - double m_count = -TestBench::kFilterStep; + double m_count = -kFilterStep; std::random_device m_rd; std::mt19937 m_gen{m_rd()}; @@ -79,7 +89,7 @@ class FilterNoiseTest : public testing::TestWithParam { std::unique_ptr m_filter; std::shared_ptr m_noise; - static double GetData(double t) { return 100.0 * std::sin(2.0 * M_PI * t); } + static double GetData(double t) { return 100.0 * std::sin(2.0 * kPi * t); } void SetUp() override { m_noise = std::make_shared(GetData, kStdDev); @@ -88,15 +98,13 @@ class FilterNoiseTest : public testing::TestWithParam { case TEST_SINGLE_POLE_IIR: { m_filter = std::make_unique( LinearDigitalFilter::SinglePoleIIR( - m_noise, TestBench::kSinglePoleIIRTimeConstant, - TestBench::kFilterStep)); + m_noise, kSinglePoleIIRTimeConstant, kFilterStep)); break; } case TEST_MOVAVG: { m_filter = std::make_unique( - LinearDigitalFilter::MovingAverage(m_noise, - TestBench::kMovAvgTaps)); + LinearDigitalFilter::MovingAverage(m_noise, kMovAvgTaps)); break; } } @@ -112,7 +120,7 @@ TEST_P(FilterNoiseTest, NoiseReduce) { double filterError = 0.0; m_noise->Reset(); - for (double t = 0; t < TestBench::kFilterTime; t += TestBench::kFilterStep) { + for (double t = 0; t < kFilterTime; t += kFilterStep) { theoryData = GetData(t); filterError += std::abs(m_filter->PIDGet() - theoryData); noiseGenError += std::abs(m_noise->Get() - theoryData); diff --git a/wpilibcIntegrationTests/src/main/native/cpp/FilterOutputTest.cpp b/wpilibc/src/test/native/cpp/FilterOutputTest.cpp similarity index 74% rename from wpilibcIntegrationTests/src/main/native/cpp/FilterOutputTest.cpp rename to wpilibc/src/test/native/cpp/FilterOutputTest.cpp index a8d25e2df5..ec71760998 100644 --- a/wpilibcIntegrationTests/src/main/native/cpp/FilterOutputTest.cpp +++ b/wpilibc/src/test/native/cpp/FilterOutputTest.cpp @@ -13,10 +13,20 @@ #include #include -#include "TestBench.h" #include "frc/Base.h" #include "gtest/gtest.h" +/* Filter constants */ +static constexpr double kFilterStep = 0.005; +static constexpr double kFilterTime = 2.0; +static constexpr double kSinglePoleIIRTimeConstant = 0.015915; +static constexpr double kSinglePoleIIRExpectedOutput = -3.2172003; +static constexpr double kHighPassTimeConstant = 0.006631; +static constexpr double kHighPassExpectedOutput = 10.074717; +static constexpr int32_t kMovAvgTaps = 6; +static constexpr double kMovAvgExpectedOutput = -10.191644; +static constexpr double kPi = 3.14159265358979323846; + using namespace frc; enum FilterOutputTestType { @@ -52,17 +62,17 @@ class DataWrapper : public PIDSource { virtual void SetPIDSourceType(PIDSourceType pidSource) {} virtual double PIDGet() { - m_count += TestBench::kFilterStep; + m_count += kFilterStep; return m_dataFunc(m_count); } - void Reset() { m_count = -TestBench::kFilterStep; } + void Reset() { m_count = -kFilterStep; } private: std::function m_dataFunc; // Make sure first call to PIDGet() uses m_count == 0 - double m_count = -TestBench::kFilterStep; + double m_count = -kFilterStep; }; /** @@ -75,7 +85,7 @@ class FilterOutputTest : public testing::TestWithParam { double m_expectedOutput = 0.0; static double GetData(double t) { - return 100.0 * std::sin(2.0 * M_PI * t) + 20.0 * std::cos(50.0 * M_PI * t); + return 100.0 * std::sin(2.0 * kPi * t) + 20.0 * std::cos(50.0 * kPi * t); } static double GetPulseData(double t) { @@ -92,9 +102,8 @@ class FilterOutputTest : public testing::TestWithParam { m_data = std::make_shared(GetData); m_filter = std::make_unique( LinearDigitalFilter::SinglePoleIIR( - m_data, TestBench::kSinglePoleIIRTimeConstant, - TestBench::kFilterStep)); - m_expectedOutput = TestBench::kSinglePoleIIRExpectedOutput; + m_data, kSinglePoleIIRTimeConstant, kFilterStep)); + m_expectedOutput = kSinglePoleIIRExpectedOutput; break; } @@ -102,24 +111,23 @@ class FilterOutputTest : public testing::TestWithParam { m_data = std::make_shared(GetData); m_filter = std::make_unique(LinearDigitalFilter::HighPass( - m_data, TestBench::kHighPassTimeConstant, - TestBench::kFilterStep)); - m_expectedOutput = TestBench::kHighPassExpectedOutput; + m_data, kHighPassTimeConstant, kFilterStep)); + m_expectedOutput = kHighPassExpectedOutput; break; } case TEST_MOVAVG: { m_data = std::make_shared(GetData); m_filter = std::make_unique( - LinearDigitalFilter::MovingAverage(m_data, TestBench::kMovAvgTaps)); - m_expectedOutput = TestBench::kMovAvgExpectedOutput; + LinearDigitalFilter::MovingAverage(m_data, kMovAvgTaps)); + m_expectedOutput = kMovAvgExpectedOutput; break; } case TEST_PULSE: { m_data = std::make_shared(GetPulseData); m_filter = std::make_unique( - LinearDigitalFilter::MovingAverage(m_data, TestBench::kMovAvgTaps)); + LinearDigitalFilter::MovingAverage(m_data, kMovAvgTaps)); m_expectedOutput = 0.0; break; } @@ -134,8 +142,7 @@ TEST_P(FilterOutputTest, FilterOutput) { m_data->Reset(); double filterOutput = 0.0; - for (double t = 0.0; t < TestBench::kFilterTime; - t += TestBench::kFilterStep) { + for (double t = 0.0; t < kFilterTime; t += kFilterStep) { filterOutput = m_filter->PIDGet(); } diff --git a/wpilibcIntegrationTests/src/main/native/cpp/MockSpeedController.cpp b/wpilibc/src/test/native/cpp/MockSpeedController.cpp similarity index 100% rename from wpilibcIntegrationTests/src/main/native/cpp/MockSpeedController.cpp rename to wpilibc/src/test/native/cpp/MockSpeedController.cpp diff --git a/wpilibcIntegrationTests/src/main/native/cpp/RobotDriveTest.cpp b/wpilibc/src/test/native/cpp/RobotDriveTest.cpp similarity index 99% rename from wpilibcIntegrationTests/src/main/native/cpp/RobotDriveTest.cpp rename to wpilibc/src/test/native/cpp/RobotDriveTest.cpp index 2fd97df3cf..464a7074fd 100644 --- a/wpilibcIntegrationTests/src/main/native/cpp/RobotDriveTest.cpp +++ b/wpilibc/src/test/native/cpp/RobotDriveTest.cpp @@ -6,7 +6,6 @@ /*----------------------------------------------------------------------------*/ #include "MockSpeedController.h" -#include "TestBench.h" #include "frc/RobotDrive.h" #include "frc/drive/DifferentialDrive.h" #include "frc/drive/MecanumDrive.h" diff --git a/wpilibcIntegrationTests/src/main/native/cpp/SpeedControllerGroupTest.cpp b/wpilibc/src/test/native/cpp/SpeedControllerGroupTest.cpp similarity index 99% rename from wpilibcIntegrationTests/src/main/native/cpp/SpeedControllerGroupTest.cpp rename to wpilibc/src/test/native/cpp/SpeedControllerGroupTest.cpp index dee5bf6ea3..a6f50285f9 100644 --- a/wpilibcIntegrationTests/src/main/native/cpp/SpeedControllerGroupTest.cpp +++ b/wpilibc/src/test/native/cpp/SpeedControllerGroupTest.cpp @@ -11,7 +11,6 @@ #include #include "MockSpeedController.h" -#include "TestBench.h" #include "gtest/gtest.h" using namespace frc; diff --git a/wpilibcIntegrationTests/src/main/native/include/MockSpeedController.h b/wpilibc/src/test/native/include/MockSpeedController.h similarity index 100% rename from wpilibcIntegrationTests/src/main/native/include/MockSpeedController.h rename to wpilibc/src/test/native/include/MockSpeedController.h diff --git a/wpilibcIntegrationTests/src/main/native/include/TestBench.h b/wpilibcIntegrationTests/src/main/native/include/TestBench.h index cc04f6b684..f9b5f304de 100644 --- a/wpilibcIntegrationTests/src/main/native/include/TestBench.h +++ b/wpilibcIntegrationTests/src/main/native/include/TestBench.h @@ -56,14 +56,4 @@ class TestBench { /* PCM channels */ static const int32_t kSolenoidChannel1 = 0; static const int32_t kSolenoidChannel2 = 1; - - /* Filter constants */ - static constexpr double kFilterStep = 0.005; - static constexpr double kFilterTime = 2.0; - static constexpr double kSinglePoleIIRTimeConstant = 0.015915; - static constexpr double kSinglePoleIIRExpectedOutput = -3.2172003; - static constexpr double kHighPassTimeConstant = 0.006631; - static constexpr double kHighPassExpectedOutput = 10.074717; - static constexpr int32_t kMovAvgTaps = 6; - static constexpr double kMovAvgExpectedOutput = -10.191644; };