PL
games/satisfying-bounce / tests / LiveSpeedTest.php · commit 8bdd6e4
<?phpnamespace Tests;use App\Scene\MarbleScene;use App\Scene\SpiralScene;use JumPHP\Shorts\Quality;use JumPHP\Shorts\Recorder;use JumPHP\Shorts\Sprites;use JumPHP\Shorts\Voice;use JumPHP\Testing\GameTestCase;/** What keeps the game smooth on a phone: no sound made at a bounce, no texture made every frame. */final class LiveSpeedTest extends GameTestCase{    public function testTheVoicesOfTheSceneAreMadeInTheBackgroundAtItsStart(): void    {        $this->game->start(MarbleScene::class, ['seed' => 3]);        $recorder = $this->recorder();        self::assertGreaterThan(0, $recorder->waiting() + $recorder->made(), 'the notes of the scene are queued at its start');        $this->game->run(120);        self::assertSame(0, $recorder->waiting());        $made = $recorder->made();        $this->game->run(600);        self::assertSame($made, $recorder->made(), 'a steady scene makes no new voice at a bounce');    }    public function testTheCatsHelloMeowsAreMadeBeforeTheCatsShowUp(): void    {        $this->game->start(\App\Scene\CatBounceScene::class, ['seed' => 3]);        $this->game->run(60 * 3);        $made = $this->recorder()->made();        $this->game->run(60 * 8);        self::assertLessThanOrEqual($made + 3, $this->recorder()->made(), 'no burst of new voices once the cats are all there');    }    public function testASteadyFrameMakesNoTexture(): void    {        $this->game->start(SpiralScene::class, ['seed' => 3]);        $this->game->run(60 * 6);                       // one loop of the spiral: its colours are all made        $before = Sprites::$created;        $this->game->run(60 * 4);        self::assertLessThan(10, Sprites::$created - $before);    }    public function testALiveGameUsesTheFastShapes(): void    {        $this->game->start(SpiralScene::class, ['seed' => 3]);        self::assertTrue(Quality::$live);        self::assertFalse($this->recorder()->isRecording());    }    public function testALiveVoiceIsAHalfRateWavAndTheFilmKeepsFullRate(): void    {        $live = Voice::wav('pluck', 440.0, 0.4, 0.3);        $film = Voice::header(10);        self::assertSame(Voice::LIVE_RATE, unpack('V', substr($live, 24, 4))[1]);        self::assertSame(Voice::RATE, unpack('V', substr($film, 24, 4))[1]);        self::assertCount((int)round(0.4 * Voice::RATE), Voice::render('pluck', 440.0, 0.4, 0.3));    }    private function recorder(): Recorder    {        return $this->game->peek('recorder');    }}