2021-08-21 02:19:59 -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.
|
|
|
|
|
|
|
|
|
|
#include "frc/Ultrasonic.h"
|
|
|
|
|
#include "frc/simulation/UltrasonicSim.h"
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
2023-01-09 02:33:07 +02:00
|
|
|
using namespace frc;
|
2021-08-21 02:19:59 -04:00
|
|
|
|
|
|
|
|
TEST(UltrasonicTest, SimDevices) {
|
|
|
|
|
Ultrasonic ultrasonic{0, 1};
|
|
|
|
|
sim::UltrasonicSim sim{ultrasonic};
|
|
|
|
|
|
2021-10-25 08:58:12 -07:00
|
|
|
EXPECT_EQ(0, ultrasonic.GetRange().value());
|
2021-08-21 02:19:59 -04:00
|
|
|
EXPECT_TRUE(ultrasonic.IsRangeValid());
|
|
|
|
|
|
|
|
|
|
sim.SetRange(units::meter_t{35.04});
|
2021-10-25 08:58:12 -07:00
|
|
|
EXPECT_EQ(35.04, ultrasonic.GetRange().value());
|
2021-08-21 02:19:59 -04:00
|
|
|
|
|
|
|
|
sim.SetRangeValid(false);
|
|
|
|
|
EXPECT_FALSE(ultrasonic.IsRangeValid());
|
2021-10-25 08:58:12 -07:00
|
|
|
EXPECT_EQ(0, ultrasonic.GetRange().value());
|
2021-08-21 02:19:59 -04:00
|
|
|
}
|
|
|
|
|
|
2023-01-09 02:33:07 +02:00
|
|
|
TEST(UltrasonicTest, AutomaticModeToggle) {
|
|
|
|
|
frc::Ultrasonic ultrasonic{0, 1};
|
|
|
|
|
EXPECT_NO_THROW({
|
|
|
|
|
frc::Ultrasonic::SetAutomaticMode(true);
|
|
|
|
|
frc::Ultrasonic::SetAutomaticMode(false);
|
|
|
|
|
frc::Ultrasonic::SetAutomaticMode(true);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(UltrasonicTest, AutomaticModeOnWithZeroInstances) {
|
|
|
|
|
EXPECT_NO_THROW({ frc::Ultrasonic::SetAutomaticMode(true); });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(UltrasonicTest, AutomaticModeOffWithZeroInstances) {
|
|
|
|
|
EXPECT_NO_THROW({ frc::Ultrasonic::SetAutomaticMode(false); });
|
|
|
|
|
}
|