[commands] Use factories and decorators in Command tests (#7006)

This commit is contained in:
ハイドラント
2024-12-29 10:45:17 -06:00
committed by GitHub
parent e7dd5dca82
commit 78b6d61e88
30 changed files with 374 additions and 412 deletions

View File

@@ -56,85 +56,72 @@ TEST_F(ConditionalCommandTest, ConditionalCommandRequirement) {
}
TEST_F(ConditionalCommandTest, AllTrue) {
CommandPtr command =
cmd::Either(cmd::WaitUntil([] { return false; }).IgnoringDisable(true),
cmd::WaitUntil([] { return false; }).IgnoringDisable(true),
[] { return true; });
auto command =
cmd::Either(cmd::Idle().IgnoringDisable(true),
cmd::Idle().IgnoringDisable(true), [] { return true; });
EXPECT_EQ(true, command.get()->RunsWhenDisabled());
}
TEST_F(ConditionalCommandTest, AllFalse) {
CommandPtr command =
cmd::Either(cmd::WaitUntil([] { return false; }).IgnoringDisable(false),
cmd::WaitUntil([] { return false; }).IgnoringDisable(false),
[] { return true; });
auto command =
cmd::Either(cmd::Idle().IgnoringDisable(false),
cmd::Idle().IgnoringDisable(false), [] { return true; });
EXPECT_EQ(false, command.get()->RunsWhenDisabled());
}
TEST_F(ConditionalCommandTest, OneTrueOneFalse) {
CommandPtr command =
cmd::Either(cmd::WaitUntil([] { return false; }).IgnoringDisable(true),
cmd::WaitUntil([] { return false; }).IgnoringDisable(false),
[] { return true; });
auto command =
cmd::Either(cmd::Idle().IgnoringDisable(true),
cmd::Idle().IgnoringDisable(false), [] { return true; });
EXPECT_EQ(false, command.get()->RunsWhenDisabled());
}
TEST_F(ConditionalCommandTest, TwoFalseOneTrue) {
CommandPtr command =
cmd::Either(cmd::WaitUntil([] { return false; }).IgnoringDisable(false),
cmd::WaitUntil([] { return false; }).IgnoringDisable(true),
[] { return true; });
auto command =
cmd::Either(cmd::Idle().IgnoringDisable(false),
cmd::Idle().IgnoringDisable(true), [] { return true; });
EXPECT_EQ(false, command.get()->RunsWhenDisabled());
}
TEST_F(ConditionalCommandTest, AllCancelSelf) {
CommandPtr command = cmd::Either(
cmd::WaitUntil([] {
return false;
}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelSelf),
cmd::WaitUntil([] {
return false;
}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelSelf),
[] { return true; });
auto command = cmd::Either(cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelSelf),
cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelSelf),
[] { return true; });
EXPECT_EQ(Command::InterruptionBehavior::kCancelSelf,
command.get()->GetInterruptionBehavior());
}
TEST_F(ConditionalCommandTest, AllCancelIncoming) {
CommandPtr command = cmd::Either(
cmd::WaitUntil([] {
return false;
}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelIncoming),
cmd::WaitUntil([] {
return false;
}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelIncoming),
[] { return false; });
auto command =
cmd::Either(cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelIncoming),
cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelIncoming),
[] { return false; });
EXPECT_EQ(Command::InterruptionBehavior::kCancelIncoming,
command.get()->GetInterruptionBehavior());
}
TEST_F(ConditionalCommandTest, OneCancelSelfOneIncoming) {
CommandPtr command = cmd::Either(
cmd::WaitUntil([] {
return false;
}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelSelf),
cmd::WaitUntil([] {
return false;
}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelIncoming),
[] { return false; });
auto command =
cmd::Either(cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelSelf),
cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelIncoming),
[] { return false; });
EXPECT_EQ(Command::InterruptionBehavior::kCancelSelf,
command.get()->GetInterruptionBehavior());
}
TEST_F(ConditionalCommandTest, OneCancelIncomingOneSelf) {
CommandPtr command = cmd::Either(
cmd::WaitUntil([] {
return false;
}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelIncoming),
cmd::WaitUntil([] {
return false;
}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelSelf),
[] { return false; });
auto command =
cmd::Either(cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelIncoming),
cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelSelf),
[] { return false; });
EXPECT_EQ(Command::InterruptionBehavior::kCancelSelf,
command.get()->GetInterruptionBehavior());
}