PHP Classes

File: tests/WordTest.php

Recommend this page to a friend!
  Classes of Rodolfo Berrios Arce   Wordle CLI   tests/WordTest.php   Download  
File: tests/WordTest.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Wordle CLI
Run the Wordle game on the command line console
Author: By
Last change:
Date: 8 days ago
Size: 1,458 bytes
 

Contents

Class file image Download
<?php

/*
 * This file is part of Chevere.
 *
 * (c) Rodolfo Berrios <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace
Rodber\Wordle\Tests;

use
PHPUnit\Framework\TestCase;
use
Rodber\Wordle\Word;

final class
WordTest extends TestCase
{
    public function
testWord(): void
   
{
       
$word = 'word';
       
$solver = new Word($word);
       
$this->assertSame($word, $solver->__toString());
       
$this->assertSame(strlen($word), $solver->length());
       
$this->assertSame(
            [
'w', 'o', 'r', 'd'],
           
$solver->split()
        );
    }

    public function
testWordUtf8(): void
   
{
       
$foo = 'piņa';
       
$word = new Word($foo);
       
$this->assertSame($foo, $word->__toString());
       
$this->assertSame(mb_strlen($foo), $word->length());
       
$this->assertSame(
            [
'p', 'i', 'ņ', 'a'],
           
$word->split()
        );
    }

    public function
testCharMatch(): void
   
{
       
$word = '01';
       
$solver = new Word($word);
       
$expected = [
           
'0' => Word::CHAR_MATCH_EXACT,
           
'1' => Word::CHAR_MATCH_PARTIAL,
           
'2' => Word::CHAR_MATCH_NONE,
        ];
        foreach (
$expected as $letter => $expected) {
           
$this->assertSame($expected, $solver->getPosMatch(0, strval($letter)));
        }
    }
}