Sha256: 386be4668fa591558af7e71ee3f079c227f2f47d0413ae1537a69ac4ab65f59a

Contents?: true

Size: 1.72 KB

Versions: 67

Compression:

Stored size: 1.72 KB

Contents

<?php

require_once "robot-name.php";

class RobotTest extends PHPUnit_Framework_TestCase
{
    /** @var Robot $robot */
    protected $robot = null;

    public function setUp()
    {
        $this->robot = new Robot();
    }

    public function testHasName()
    {
        $this->assertRegExp('/^[a-z]{2}\d{3}$/i', $this->robot->getName());
    }

    public function testNameSticks()
    {
        $this->markTestSkipped();
        $old = $this->robot->getName();

        $this->assertSame($this->robot->getName(), $old);
    }

    public function testDifferentRobotsHaveDifferentNames()
    {
        $this->markTestSkipped();
        $other_bot = new Robot();

        $this->assertNotSame($other_bot->getName(), $this->robot->getName());

        unset($other_bot);
    }

    public function testresetName()
    {
        $this->markTestSkipped();
        $name1 = $this->robot->getName();

        $this->robot->reset();

        $name2 = $this->robot->getName();

        $this->assertNotSame($name1, $name2);

        $this->assertRegExp('/\w{2}\d{3}/', $name2);
    }
  
    public function testNameArentRecycled()
    {
        $names = [];

        for ($i = 0; $i < 10000; $i++) {
            $name = $this->robot->getName();
            $this->assertArrayNotHasKey($name, $names, sprintf('Name %s reissued after Reset.', $name));
            $names[$name] = true;
            $this->robot->reset();
        }
    }

    public function testNameUniquenessManyRobots()
    {
        $names = [];

        for ($i = 0; $i < 10000; $i++) {
            $name = (new Robot())->getName();
            $this->assertArrayNotHasKey($name, $names, sprintf('Name %s reissued after %d robots', $name, $i));
            $names[$name] = true;
        }
    }
}

Version data entries

67 entries across 67 versions & 1 rubygems

Version Path
trackler-2.0.6.40 tracks/php/exercises/robot-name/robot-name_test.php
trackler-2.0.6.39 tracks/php/exercises/robot-name/robot-name_test.php
trackler-2.0.6.38 tracks/php/exercises/robot-name/robot-name_test.php
trackler-2.0.6.37 tracks/php/exercises/robot-name/robot-name_test.php
trackler-2.0.6.36 tracks/php/exercises/robot-name/robot-name_test.php
trackler-2.0.6.35 tracks/php/exercises/robot-name/robot-name_test.php
trackler-2.0.6.34 tracks/php/exercises/robot-name/robot-name_test.php
trackler-2.0.6.33 tracks/php/exercises/robot-name/robot-name_test.php
trackler-2.0.6.32 tracks/php/exercises/robot-name/robot-name_test.php
trackler-2.0.6.31 tracks/php/exercises/robot-name/robot-name_test.php
trackler-2.0.6.30 tracks/php/exercises/robot-name/robot-name_test.php
trackler-2.0.6.29 tracks/php/exercises/robot-name/robot-name_test.php
trackler-2.0.6.28 tracks/php/exercises/robot-name/robot-name_test.php
trackler-2.0.6.27 tracks/php/exercises/robot-name/robot-name_test.php
trackler-2.0.6.26 tracks/php/exercises/robot-name/robot-name_test.php
trackler-2.0.6.25 tracks/php/exercises/robot-name/robot-name_test.php
trackler-2.0.6.24 tracks/php/exercises/robot-name/robot-name_test.php
trackler-2.0.6.23 tracks/php/exercises/robot-name/robot-name_test.php
trackler-2.0.6.22 tracks/php/exercises/robot-name/robot-name_test.php
trackler-2.0.6.21 tracks/php/exercises/robot-name/robot-name_test.php