Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 1 | // Copyright (c) FIRST and other WPILib contributors. |
| 2 | // Open Source Software; you can modify and/or share it under the terms of |
| 3 | // the WPILib BSD license file in the root directory of this project. |
| 4 | |
| 5 | #include "frc/Ultrasonic.h" |
| 6 | #include "frc/simulation/UltrasonicSim.h" |
| 7 | #include "gtest/gtest.h" |
| 8 | |
| 9 | namespace frc { |
| 10 | |
| 11 | TEST(UltrasonicTest, SimDevices) { |
| 12 | Ultrasonic ultrasonic{0, 1}; |
| 13 | sim::UltrasonicSim sim{ultrasonic}; |
| 14 | |
| 15 | EXPECT_EQ(0, ultrasonic.GetRange().value()); |
| 16 | EXPECT_TRUE(ultrasonic.IsRangeValid()); |
| 17 | |
| 18 | sim.SetRange(units::meter_t{35.04}); |
| 19 | EXPECT_EQ(35.04, ultrasonic.GetRange().value()); |
| 20 | |
| 21 | sim.SetRangeValid(false); |
| 22 | EXPECT_FALSE(ultrasonic.IsRangeValid()); |
| 23 | EXPECT_EQ(0, ultrasonic.GetRange().value()); |
| 24 | } |
| 25 | |
| 26 | } // namespace frc |