2021-08-05 22:04:51 -04:00
|
|
|
// 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.
|
|
|
|
|
|
2025-11-07 19:56:21 -05:00
|
|
|
#include "wpi/simulation/DutyCycleEncoderSim.hpp" // NOLINT(build/include_order)
|
2021-08-05 22:04:51 -04:00
|
|
|
|
2023-08-28 15:13:34 -07:00
|
|
|
#include <gtest/gtest.h>
|
2021-08-05 22:04:51 -04:00
|
|
|
|
2025-11-07 19:56:21 -05:00
|
|
|
#include "callback_helpers/TestCallbackHelpers.hpp"
|
2025-11-07 19:57:55 -05:00
|
|
|
#include "wpi/hal/HAL.h"
|
2025-11-07 19:56:21 -05:00
|
|
|
#include "wpi/hardware/rotation/DutyCycleEncoder.hpp"
|
2021-08-05 22:04:51 -04:00
|
|
|
|
|
|
|
|
namespace frc::sim {
|
|
|
|
|
|
|
|
|
|
TEST(DutyCycleEncoderSimTest, Set) {
|
|
|
|
|
HAL_Initialize(500, 0);
|
|
|
|
|
|
2024-05-24 11:53:56 -07:00
|
|
|
DutyCycleEncoder enc{0, 10, 0};
|
2021-08-05 22:04:51 -04:00
|
|
|
DutyCycleEncoderSim sim(enc);
|
|
|
|
|
|
2024-05-24 11:53:56 -07:00
|
|
|
constexpr double kTestValue{5.67};
|
2021-08-05 22:04:51 -04:00
|
|
|
sim.Set(kTestValue);
|
|
|
|
|
EXPECT_EQ(kTestValue, enc.Get());
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-19 20:24:09 -04:00
|
|
|
TEST(DutyCycleEncoderSimTest, SetIsConnected) {
|
|
|
|
|
HAL_Initialize(500, 0);
|
|
|
|
|
|
|
|
|
|
DutyCycleEncoder enc{0};
|
|
|
|
|
DutyCycleEncoderSim sim(enc);
|
|
|
|
|
sim.SetConnected(true);
|
|
|
|
|
EXPECT_TRUE(enc.IsConnected());
|
|
|
|
|
sim.SetConnected(false);
|
|
|
|
|
EXPECT_FALSE(enc.IsConnected());
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-05 22:04:51 -04:00
|
|
|
} // namespace frc::sim
|