Skip to content

Commit

Permalink
Add c++ tests and java tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel1464 committed Nov 18, 2024
1 parent d3e91c5 commit 9580f02
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,58 @@ void deadlineForOrderTest() {
assertAll(() -> assertTrue(dictatorHasRun.get()), () -> assertTrue(dictatorWasPolled.get()));
}
}

@Test
void withDeadlineTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
AtomicBoolean finish = new AtomicBoolean(false);
Command endsBeforeGroup = Commands.none().withDeadline(
Commands.waitUntil(finish::get)
);
Command endsAfterGroup = Commands.idle().withDeadline(
Commands.waitUntil(finish::get)
);
scheduler.schedule(endsBeforeGroup);
scheduler.run();
assertTrue(scheduler.isScheduled(endsBeforeGroup));
finish.set(true);
scheduler.run();
assertFalse(scheduler.isScheduled(endsBeforeGroup));
finish.set(false);
scheduler.schedule(endsAfterGroup);
scheduler.run();
assertTrue(scheduler.isScheduled(endsAfterGroup));
finish.set(true);
scheduler.run();
assertFalse(scheduler.isScheduled(endsAfterGroup));
}
}
@Test
void withDeadlineOrderTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
AtomicBoolean dictatorHasRun = new AtomicBoolean(false);
AtomicBoolean dictatorWasPolled = new AtomicBoolean(false);
Command dictator =
new FunctionalCommand(
() -> {},
() -> dictatorHasRun.set(true),
interrupted -> {},
() -> {
dictatorWasPolled.set(true);
return true;
});
Command other =
Commands.run(
() ->
assertAll(
() -> assertTrue(dictatorHasRun.get()),
() -> assertTrue(dictatorWasPolled.get())));
Command group = other.withDeadline(dictator);
scheduler.schedule(group);
scheduler.run();
assertAll(() -> assertTrue(dictatorHasRun.get()), () -> assertTrue(dictatorWasPolled.get()));
}
}

@Test
void alongWithTest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,27 @@ TEST_F(CommandDecoratorTest, DeadlineFor) {
EXPECT_FALSE(scheduler.IsScheduled(group));
}

TEST_F(CommandDecoratorTest, WithDeadline) {
CommandScheduler scheduler = GetScheduler();

bool finish = false;

auto dictator = WaitUntilCommand([&finish] { return finish; });
auto endsAfter = WaitUntilCommand([] { return false; });

auto group = std::move(endsAfter).WithDeadline(std::move(dictator).ToPtr());

scheduler.Schedule(group);
scheduler.Run();

EXPECT_TRUE(scheduler.IsScheduled(group));

finish = true;
scheduler.Run();

EXPECT_FALSE(scheduler.IsScheduled(group));
}

TEST_F(CommandDecoratorTest, AlongWith) {
CommandScheduler scheduler = GetScheduler();

Expand Down Expand Up @@ -283,6 +304,33 @@ TEST_F(CommandDecoratorTest, DeadlineForOrder) {
EXPECT_TRUE(dictatorWasPolled);
}

TEST_F(CommandDecoratorTest, WithDeadlineOrder) {
CommandScheduler scheduler = GetScheduler();

bool dictatorHasRun = false;
bool dictatorWasPolled = false;

auto dictator =
FunctionalCommand([] {}, [&dictatorHasRun] { dictatorHasRun = true; },
[](bool interrupted) {},
[&dictatorWasPolled] {
dictatorWasPolled = true;
return true;
});
auto other = RunCommand([&dictatorHasRun, &dictatorWasPolled] {
EXPECT_TRUE(dictatorHasRun);
EXPECT_TRUE(dictatorWasPolled);
});

auto group = std::move(other).WithDeadline(std::move(dictator).ToPtr());

scheduler.Schedule(group);
scheduler.Run();

EXPECT_TRUE(dictatorHasRun);
EXPECT_TRUE(dictatorWasPolled);
}

TEST_F(CommandDecoratorTest, AlongWithOrder) {
CommandScheduler scheduler = GetScheduler();

Expand Down

0 comments on commit 9580f02

Please sign in to comment.