From de62a752357fa72931f4843755ea69dc91d98114 Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Sun, 9 Jun 2024 15:39:17 -0400 Subject: [PATCH] Make tests consistent and make assertions non-fatal --- wpilibc/src/test/native/cpp/InterruptTest.cpp | 14 ++++----- .../edu/wpi/first/wpilibj/InterruptTest.java | 31 ++++++++++++------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/wpilibc/src/test/native/cpp/InterruptTest.cpp b/wpilibc/src/test/native/cpp/InterruptTest.cpp index 85fb2fe9fda..b21484c2c67 100644 --- a/wpilibc/src/test/native/cpp/InterruptTest.cpp +++ b/wpilibc/src/test/native/cpp/InterruptTest.cpp @@ -30,7 +30,7 @@ TEST(InterruptTest, AsynchronousInterrupt) { frc::Wait(0.5_s); DIOSim digitalSim{di}; digitalSim.SetValue(false); - frc::Wait(20_ms); + frc::Wait(10_ms); digitalSim.SetValue(true); frc::Wait(10_ms); @@ -59,7 +59,7 @@ TEST(InterruptTest, RisingEdge) { digitalSim.SetValue(false); frc::Wait(0.5_s); interrupt.Enable(); - frc::Wait(20_ms); + frc::Wait(10_ms); digitalSim.SetValue(true); frc::Wait(10_ms); @@ -69,8 +69,8 @@ TEST(InterruptTest, RisingEdge) { count++; ASSERT_TRUE(count < 1000); } - ASSERT_FALSE(hasFiredFallingEdge); - ASSERT_TRUE(hasFiredRisingEdge); + EXPECT_FALSE(hasFiredFallingEdge); + EXPECT_TRUE(hasFiredRisingEdge); } TEST(InterruptTest, FallingEdge) { @@ -89,7 +89,7 @@ TEST(InterruptTest, FallingEdge) { digitalSim.SetValue(true); frc::Wait(0.5_s); interrupt.Enable(); - frc::Wait(20_ms); + frc::Wait(10_ms); digitalSim.SetValue(false); frc::Wait(10_ms); @@ -99,7 +99,7 @@ TEST(InterruptTest, FallingEdge) { count++; ASSERT_TRUE(count < 1000); } - ASSERT_TRUE(hasFiredFallingEdge); - ASSERT_FALSE(hasFiredRisingEdge); + EXPECT_TRUE(hasFiredFallingEdge); + EXPECT_FALSE(hasFiredRisingEdge); } } // namespace frc diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/InterruptTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/InterruptTest.java index 320beadadd2..795f6291235 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/InterruptTest.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/InterruptTest.java @@ -4,6 +4,7 @@ package edu.wpi.first.wpilibj; +import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -23,7 +24,7 @@ void testAsynchronousInterrupt() { AsynchronousInterrupt interrupt = new AsynchronousInterrupt( di, - (a, b) -> { + (rising, falling) -> { counter.incrementAndGet(); hasFired.set(true); })) { @@ -54,9 +55,9 @@ void testRisingEdge() { AsynchronousInterrupt interrupt = new AsynchronousInterrupt( di, - (a, b) -> { - hasFiredFallingEdge.set(b); - hasFiredRisingEdge.set(a); + (rising, falling) -> { + hasFiredFallingEdge.set(falling); + hasFiredRisingEdge.set(rising); })) { interrupt.setInterruptEdges(true, true); DIOSim digitalSim = new DIOSim(di); @@ -73,8 +74,12 @@ void testRisingEdge() { count++; assertTrue(count < 1000); } - assertFalse(hasFiredFallingEdge.get(), "The interrupt triggered on the falling edge"); - assertTrue(hasFiredRisingEdge.get(), "The interrupt did not trigger on the rising edge"); + assertAll( + () -> + assertFalse(hasFiredFallingEdge.get(), "The interrupt triggered on the falling edge"), + () -> + assertTrue( + hasFiredRisingEdge.get(), "The interrupt did not trigger on the rising edge")); } } @@ -87,9 +92,9 @@ void testFallingEdge() { AsynchronousInterrupt interrupt = new AsynchronousInterrupt( di, - (a, b) -> { - hasFiredFallingEdge.set(b); - hasFiredRisingEdge.set(a); + (rising, falling) -> { + hasFiredFallingEdge.set(falling); + hasFiredRisingEdge.set(rising); })) { interrupt.setInterruptEdges(true, true); DIOSim digitalSim = new DIOSim(di); @@ -106,8 +111,12 @@ void testFallingEdge() { count++; assertTrue(count < 1000); } - assertTrue(hasFiredFallingEdge.get(), "The interrupt did not trigger on the rising edge"); - assertFalse(hasFiredRisingEdge.get(), "The interrupt triggered on the rising edge"); + assertAll( + () -> + assertTrue( + hasFiredFallingEdge.get(), "The interrupt did not trigger on the rising edge"), + () -> + assertFalse(hasFiredRisingEdge.get(), "The interrupt triggered on the rising edge")); } } }