IT
apps/winzik / tests / KaraokeTest.php · commit 6576d6f
<?phpnamespace Tests;use App\Model\Karaoke;use PHPUnit\Framework\TestCase;final class KaraokeTest extends TestCase{    public function testALineIsCutIntoItsSyllablesAndPutBackTogetherAsItWas(): void    {        self::assertSame(['Mis', 'tral ', 'ga', 'gnant'], Karaoke::syllables('Mistral gagnant'));        self::assertSame(['Le ', 're', 'tour ', 'de ', 'la ', 'pé', 'pette'], Karaoke::syllables('Le retour de la pépette'));        foreach (['Une journée pour célébrer la tristesse', "Parle-moi des bonbons d'antan, ça va ?", '  Oh !'] as $line) {            self::assertSame($line, implode('', Karaoke::syllables($line)), 'nothing lost');        }    }    public function testTheSyllablesShareTheTimeOfTheLineByTheirLength(): void    {        [$syllables, $times, $end] = Karaoke::timing('Mistral gagnant', 10.0, 14.0);        self::assertCount(4, $times);        self::assertSame(10.0, $times[0], 'the first one at the line');        self::assertEqualsWithDelta(10.0 + 4 * 0.3 + 0.25, $end, 0.001, 'about 0.3 s a syllable');        [, , $end] = Karaoke::timing('Mistral gagnant', 10.0, 11.0);        self::assertEqualsWithDelta(10.92, $end, 0.001, 'never past 92 % of the time to the next line');        for ($i = 1; $i < count($times); $i++) {            self::assertGreaterThan($times[$i - 1], $times[$i]);        }    }    public function testAnEnhancedLrcLineGivesTheMomentOfEachWord(): void    {        $line = '<00:10.00>Mistral <00:11.20>gagnant';        self::assertSame('Mistral gagnant', Karaoke::plain($line));        [$syllables, $times] = Karaoke::timing($line, 10.0, 14.0);        self::assertSame(['Mis', 'tral ', 'ga', 'gnant'], $syllables);        self::assertSame(10.0, $times[0]);        self::assertSame(11.2, $times[2], 'the word "gagnant" at its own moment');    }    public function testAMenuNearTheRightEdgeOpensToTheLeftAndItsSubmenusToo(): void    {        $sub = [['label' => 'a'], ['label' => 'b']];        $items = [['label' => 'Zoom', 'sub' => $sub], ['label' => 'Quitter']];        $screen = [0.0, 0.0, 1000.0, 700.0];        $left = new \App\Gui\PopupMenu($items, 950, 100, 1000, 700, $screen);        self::assertTrue($left->leftwards);        self::assertEqualsWithDelta(950 - \App\Gui\PopupMenu::WIDTH, $left->x, 0.01, 'to the left of the pointer');        $left->hoverAt($left->x + 20, $left->y + 8, 1000, 700);        self::assertNotNull($left->child);        self::assertLessThan($left->x, $left->child->x, 'its submenu to the left too');        $right = new \App\Gui\PopupMenu($items, 30, 100, 1000, 700, $screen);        self::assertFalse($right->leftwards);        self::assertEqualsWithDelta(30, $right->x, 0.01, 'near the left edge: to the right');        $low = new \App\Gui\PopupMenu($items, 30, 690, 1000, 700, $screen);        self::assertLessThanOrEqual(690, $low->y + $low->height(), 'near the bottom: upwards');    }}