Skip to content

Commit

Permalink
Use parameterized test
Browse files Browse the repository at this point in the history
  • Loading branch information
rzblue committed Oct 10, 2023
1 parent e534721 commit 207bcc9
Showing 1 changed file with 38 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,48 @@

using namespace frc2;

class DeferredCommandTest : public CommandTestBase {
public:
void DeferredFunctionsTest(bool testInterrupted) {
int initializeCount = 0;
int executeCount = 0;
int isFinishedCount = 0;
int endCount = 0;
bool finished = false;
class DeferredFunctionsTest : public CommandTestBaseWithParam<bool> {};

DeferredCommand deferred{[&] {
return FunctionalCommand{
[&] { initializeCount++; },
[&] { executeCount++; },
[&](bool interrupted) {
EXPECT_EQ(interrupted, testInterrupted);
endCount++;
},
[&] {
isFinishedCount++;
return finished;
}}
.ToPtr();
},
{}};
TEST_P(DeferredFunctionsTest, DeferredFunctions) {
int initializeCount = 0;
int executeCount = 0;
int isFinishedCount = 0;
int endCount = 0;
bool finished = false;

deferred.Initialize();
EXPECT_EQ(1, initializeCount);
deferred.Execute();
EXPECT_EQ(1, executeCount);
EXPECT_FALSE(deferred.IsFinished());
EXPECT_EQ(1, isFinishedCount);
finished = true;
EXPECT_TRUE(deferred.IsFinished());
EXPECT_EQ(2, isFinishedCount);
deferred.End(testInterrupted);
EXPECT_EQ(1, endCount);
}
};
DeferredCommand deferred{[&] {
return FunctionalCommand{
[&] { initializeCount++; },
[&] { executeCount++; },
[&](bool interrupted) {
EXPECT_EQ(interrupted, GetParam());
endCount++;
},
[&] {
isFinishedCount++;
return finished;
}}
.ToPtr();
},
{}};

TEST_F(DeferredCommandTest, DeferredFunctions) {
DeferredFunctionsTest(false);
DeferredFunctionsTest(true);
deferred.Initialize();
EXPECT_EQ(1, initializeCount);
deferred.Execute();
EXPECT_EQ(1, executeCount);
EXPECT_FALSE(deferred.IsFinished());
EXPECT_EQ(1, isFinishedCount);
finished = true;
EXPECT_TRUE(deferred.IsFinished());
EXPECT_EQ(2, isFinishedCount);
deferred.End(GetParam());
EXPECT_EQ(1, endCount);
}

TEST_F(DeferredCommandTest, DeferredSupplierOnlyCalledDuringInit) {
INSTANTIATE_TEST_SUITE_P(DeferredCommandTest, DeferredFunctionsTest,
testing::Values(true, false));

TEST(DeferredCommandTest, DeferredSupplierOnlyCalledDuringInit) {
int count = 0;
DeferredCommand command{[&count] {
count++;
Expand All @@ -70,7 +67,7 @@ TEST_F(DeferredCommandTest, DeferredSupplierOnlyCalledDuringInit) {
EXPECT_EQ(1, count);
}

TEST_F(DeferredCommandTest, DeferredRequirements) {
TEST(DeferredCommandTest, DeferredRequirements) {
TestSubsystem subsystem;
DeferredCommand command{cmd::None, {&subsystem}};

Expand Down

0 comments on commit 207bcc9

Please sign in to comment.