Skip to content

Commit

Permalink
Make tests consistent and make assertions non-fatal
Browse files Browse the repository at this point in the history
  • Loading branch information
Gold856 committed Jul 8, 2024
1 parent 087c967 commit 8340720
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
14 changes: 7 additions & 7 deletions wpilibc/src/test/native/cpp/InterruptTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -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) {
Expand All @@ -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);

Expand All @@ -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
31 changes: 20 additions & 11 deletions wpilibj/src/test/java/edu/wpi/first/wpilibj/InterruptTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,7 +24,7 @@ void testAsynchronousInterrupt() {
AsynchronousInterrupt interrupt =
new AsynchronousInterrupt(
di,
(a, b) -> {
(rising, falling) -> {
counter.incrementAndGet();
hasFired.set(true);
})) {
Expand Down Expand Up @@ -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);
Expand All @@ -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"));
}
}

Expand All @@ -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);
Expand All @@ -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"));
}
}
}

0 comments on commit 8340720

Please sign in to comment.