Sha256: 166e2e9b774c0e2c2a7ac84eb761cb6990568d34f5e8f8263ae006bccf811c0c

Contents?: true

Size: 1.73 KB

Versions: 30

Compression:

Stored size: 1.73 KB

Contents

<?php

include_once 'grains.php';

class GrainsTest extends PHPUnit_Framework_TestCase
{
    /**
     * PHP integers greater than 2^31 (32-bit systems)
     * or 2^63 (64-bit) are casted to floats.
     * In some cases it may lead to problems
     * http://php.net/manual/ru/language.types.float.php#warn.float-precision
     *
     * Consider King hates floats and demands solution with
     * precise integer-only calculations. Don't involve any floats.
     * Don't use gmp or any other similar libraries.
     * Try to make the solution for virtually any board size.
     */

    public function testInput1()
    {
        $this->assertSame('1', square(1));
    }

    public function testInput2()
    {
        $this->assertSame('2', square(2));
    }

    public function testInput3()
    {
        $this->assertSame('4', square(3));
    }

    public function testInput4()
    {
        $this->assertSame('8', square(4));
    }

    public function testInput16()
    {
        $this->assertSame('32768', square(16));
    }

    public function testInput32()
    {
        $this->assertSame('2147483648', square(32));
    }

    public function testInput64()
    {
        $this->assertSame('9223372036854775808', square(64));
    }

    /**
     * @expectedException InvalidArgumentException
     */
    public function testRejectsZero()
    {
        square(0);
    }

    /**
     * @expectedException InvalidArgumentException
     */
    public function testRejectsNegative()
    {
        square(-1);
    }

    /**
     * @expectedException InvalidArgumentException
     */
    public function testRejectsGreaterThan64()
    {
        square(65);
    }

    public function testTotal()
    {
        $this->assertSame('18446744073709551615', total());
    }
}

Version data entries

30 entries across 30 versions & 1 rubygems

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