Повысить устойчивость восьмого уровня к задержкам
This commit is contained in:
@@ -43,19 +43,39 @@ public final class LevelEightPlaythroughTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void intendedRouteSurvivesStressedDecisionScheduling() {
|
||||
try (ActivityScenario<MainActivity> activity = ActivityScenario.launch(MainActivity.class)) {
|
||||
LevelEightScenario.Result result = new LevelEightScenario()
|
||||
.completeIntendedRoute(driver(activity, 96L), 20_000L);
|
||||
|
||||
assertTrue("Stressed scheduling: " + result.diagnostic(), result.completed());
|
||||
assertEquals("The stressed intended route is deathless", 0, result.deaths());
|
||||
}
|
||||
}
|
||||
|
||||
private static AndroidDriver driver(ActivityScenario<MainActivity> activity) {
|
||||
return driver(activity, 0L);
|
||||
}
|
||||
|
||||
private static AndroidDriver driver(ActivityScenario<MainActivity> activity,
|
||||
long extraDecisionDelayMillis) {
|
||||
final GameView[] view = new GameView[1];
|
||||
activity.onActivity(mainActivity -> view[0] = mainActivity.gameViewForAutomation());
|
||||
return new AndroidDriver(InstrumentationRegistry.getInstrumentation(), view[0]);
|
||||
return new AndroidDriver(InstrumentationRegistry.getInstrumentation(), view[0],
|
||||
extraDecisionDelayMillis);
|
||||
}
|
||||
|
||||
private static final class AndroidDriver implements LevelPlaytestBot.Driver {
|
||||
private final Instrumentation instrumentation;
|
||||
private final GameView gameView;
|
||||
private final long extraDecisionDelayMillis;
|
||||
|
||||
AndroidDriver(Instrumentation instrumentation, GameView gameView) {
|
||||
AndroidDriver(Instrumentation instrumentation, GameView gameView,
|
||||
long extraDecisionDelayMillis) {
|
||||
this.instrumentation = instrumentation;
|
||||
this.gameView = gameView;
|
||||
this.extraDecisionDelayMillis = extraDecisionDelayMillis;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -80,7 +100,7 @@ public final class LevelEightPlaythroughTest {
|
||||
@Override
|
||||
public void waitForNextDecision(long millis) {
|
||||
try {
|
||||
Thread.sleep(millis);
|
||||
Thread.sleep(millis + extraDecisionDelayMillis);
|
||||
} catch (InterruptedException interrupted) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new AssertionError("Level-8 bot interrupted", interrupted);
|
||||
|
||||
@@ -109,10 +109,10 @@ public final class LevelCatalog {
|
||||
8, "Borrowed Time", "Jump for the far blue relay if the timed gate closes.",
|
||||
2450, 130, 760, goal(2220, 600), 0, 38,
|
||||
platforms(
|
||||
floor(0, 900), floor(1510, 940), ledge(1980, 710, 470),
|
||||
floor(0, 970), floor(1510, 940), ledge(1980, 710, 470),
|
||||
moving(990, 770, 240, 34, 380, 0, 4.0f, "clock")
|
||||
),
|
||||
hazards(hazard(PIT, 900, 880, 610, 200)),
|
||||
hazards(hazard(PIT, 970, 880, 540, 200)),
|
||||
switches(
|
||||
sw(TIMED, 560, 810, 90, 70, "clock", 6.0f, 1),
|
||||
sw(TIMED, 1600, 650, 90, 70, "clock", 3.5f, 1)
|
||||
|
||||
Reference in New Issue
Block a user