mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-28 02:11:43 +00:00
[wpimath] Add Debouncer type and time setters (#7839)
Signed-off-by: swurl <swurl@swurl.xyz> Co-authored-by: Tyler Veness <calcmogul@gmail.com>
This commit is contained in:
@@ -4,7 +4,9 @@
|
||||
|
||||
package edu.wpi.first.math.filter;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import edu.wpi.first.util.WPIUtilJNI;
|
||||
@@ -67,4 +69,20 @@ class DebouncerTest {
|
||||
|
||||
assertFalse(debouncer.calculate(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
void debounceParamsTest() {
|
||||
var debouncer = new Debouncer(0.02, Debouncer.DebounceType.kBoth);
|
||||
|
||||
assertEquals(debouncer.getDebounceTime(), 0.02);
|
||||
assertSame(debouncer.getDebounceType(), Debouncer.DebounceType.kBoth);
|
||||
|
||||
debouncer.setDebounceTime(0.1);
|
||||
|
||||
assertEquals(debouncer.getDebounceTime(), 0.1);
|
||||
|
||||
debouncer.setDebounceType(Debouncer.DebounceType.kFalling);
|
||||
|
||||
assertSame(debouncer.getDebounceType(), Debouncer.DebounceType.kFalling);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,3 +56,20 @@ TEST_F(DebouncerTest, DebounceBoth) {
|
||||
|
||||
EXPECT_FALSE(debouncer.Calculate(false));
|
||||
}
|
||||
|
||||
TEST_F(DebouncerTest, DebounceParams) {
|
||||
frc::Debouncer debouncer{20_ms, frc::Debouncer::DebounceType::kBoth};
|
||||
|
||||
EXPECT_TRUE(debouncer.GetDebounceTime() == 20_ms);
|
||||
EXPECT_TRUE(debouncer.GetDebounceType() ==
|
||||
frc::Debouncer::DebounceType::kBoth);
|
||||
|
||||
debouncer.SetDebounceTime(100_ms);
|
||||
|
||||
EXPECT_TRUE(debouncer.GetDebounceTime() == 100_ms);
|
||||
|
||||
debouncer.SetDebounceType(frc::Debouncer::DebounceType::kFalling);
|
||||
|
||||
EXPECT_TRUE(debouncer.GetDebounceType() ==
|
||||
frc::Debouncer::DebounceType::kFalling);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user