Exemplo n.º 1
0
 function dataProvider()
 {
     $fizzBuzz = new FizzBuzz(new FizzBuzzElement());
     $arr = $fizzBuzz->run();
     $testCases = array('T0' => array(count($arr), 100), 'T2' => array($arr[1], 1), 'T3' => array($arr[3], 'Fizz'), 'T4' => array($arr[4], 4), 'T5' => array($arr[5], 'Buzz'), 'T6' => array($arr[6], 'Fizz'), 'T20' => array($arr[20], 'Buzz'), 'T13' => array($arr[13], 'Fizz'), 'T15' => array($arr[15], 'FizzBuzz'), 'T53' => array($arr[53], 'FizzBuzz'));
     return $testCases;
 }
Exemplo n.º 2
0
 /**
  * @dataProvider testProvider
  */
 function test_fizz_buzz($actual, $expected)
 {
     $fb = new FizzBuzz();
     $this->assertEquals($fb->write2($actual), $expected);
 }
Exemplo n.º 3
0
 function testIsFizz()
 {
     $fizzbuzz = new FizzBuzz();
     $range = $fizzbuzz->getList();
     $this->assertEquals('fizz', $range[2]);
 }
Exemplo n.º 4
0
        return $result;
    }
    /**
     * Get arguments from file.
     *
     * @param string $filePath
     * @return array
     */
    private static function getArgumentsFromFile($filePath)
    {
        $arguments = [];
        $handle = fopen($filePath, 'r');
        while (($fileLine = fgets($handle)) !== false) {
            $arguments[] = self::getArgumentsFromLine($fileLine);
        }
        fclose($handle);
        return $arguments;
    }
    /**
     * Get fizz buzz arguments from file line.
     *
     * @param string $line
     * @return array
     */
    private static function getArgumentsFromLine($line)
    {
        return explode(' ', $line);
    }
}
echo FizzBuzz::getResult('/Users/jana/Desktop/file/source.txt');
Exemplo n.º 5
0
 /**
  * @dataProvider fizzbuzzDataProvider
  * @param $intTestvalue
  * @param $intExpectedResult
  */
 public function test3($intTestvalue, $intExpectedResult)
 {
     $actual = FizzBuzz::get($intTestvalue);
     static::assertEquals($intExpectedResult, $actual);
 }
Exemplo n.º 6
0
 public function testEnter15ReturnF_B()
 {
     $expected = "FizzBuzz";
     $result = FizzBuzz::recieve(15);
     $this->assertEquals($expected, $result);
 }
Exemplo n.º 7
0
<?php

/**
 * Untuk optimasi - pada seksi pencetakan "FizzBuzz",
 * kita bisa langsung mengganti denominator modulus menggunakan angka 15.
 */
class FizzBuzz
{
    var $angka_maksimum = 100;
    function cetak()
    {
        for ($i = 1; $i <= $this->angka_maksimum; $i++) {
            switch ($i) {
                case $i % 3 == 0 && $i % 5 == 0:
                    echo $i . " FizzBuzz\n";
                    break;
                case $i % 3 == 0:
                    echo $i . " Fizz\n";
                    break;
                case $i % 5 == 0:
                    echo $i . " Buzz\n";
                    break;
                default:
                    echo $i . "\n";
                    break;
            }
        }
    }
}
$FizzBuzz = new FizzBuzz();
$FizzBuzz->cetak();
Exemplo n.º 8
0
 public function testFizzBuzz()
 {
     $expected = array("1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19", "Buzz");
     $fizzbuzz = new FizzBuzz();
     $this->assertEquals($expected, $fizzbuzz->play());
 }
Exemplo n.º 9
0
<?php

class FizzBuzz
{
    private $value;
    public function __construct($v)
    {
        $this->value = $this->fizzbuzz($v, 15, 'FizzBuzz') ?: $this->fizzbuzz($v, 5, 'Fizz') ?: $this->fizzbuzz($v, 3, 'Buzz') ?: $v;
    }
    private function fizzbuzz($val, $num, $str)
    {
        return $val % $num == 0 ? $str : false;
    }
    public function say()
    {
        return $this->value;
    }
}
foreach (range(1, 19) as $i) {
    $fizzbuzz = new FizzBuzz($i);
    echo $fizzbuzz->say() . PHP_EOL;
}
Exemplo n.º 10
0
 function testThirtyShouldBeFizzBuzz()
 {
     $fb = new FizzBuzz();
     $this->assertEquals("FizzBuzz", $fb->tell('30'));
 }
Exemplo n.º 11
0
    private function hasNumber($i, $n)
    {
        $i = (string) $i;
        $n = (string) $n;
        if (strpos($i, $n) === false && $i !== $n) {
            return false;
        } else {
            return true;
        }
    }
}
?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>FizzBuzz!</title>
  <style type="text/css" media="all">
    body {background:#eee;color:#333;text-shadow:0px 1px 0px #fff;font-family:sans-serif;}
    .fb {font-size:1.2em;font-weight:bold;}
  </style>
</head>
<body>
<h1>FizzBuzz!</h1>
<?php 
$c = new FizzBuzz();
$c->execute();
?>
  
</body>
</html>
Exemplo n.º 12
0
 /**
  * @dataProvider FizzBuzz_data_provider
  */
 public function test_FizzBuzz_run($from, $to, $expected)
 {
     $this->FizzBuzz->set_from($from);
     $this->FizzBuzz->set_to($to);
     $this->assertEquals($expected, $this->FizzBuzz->run());
 }
 public function testNumberOutputOnNotMultipleOf3()
 {
     $this->assertSame(7, $this->fizzBuzz->execute(7));
 }
Exemplo n.º 14
0
    {
        $i = !($i % 3) + (!($i % 5) << 1);
        return $i;
    }
    public function frequency($count = 100)
    {
        $freq = array(0, 0, 0, 0);
        for ($i = 1; $i <= $count; $i++) {
            $j = !($i % 3) + !($i % 5) * 2;
            $freq[$j]++;
        }
        return $freq;
    }
}
/**************************************************************************/
/* Using PHP, iterate through the integers between (inclusive) 1 and 100. */
/* For each number, if it is divisible by 3 and not 5, print fizz. If it  */
/* is divisible by 5 and not 3, print buzz. If it is divisible by both 3  */
/* and 5, print fizzbuzz. If the number is divisible by neither 3 nor 5,  */
/* do not print anything out.                                             */
/**************************************************************************/
$test = new FizzBuzz();
// Testing
echo "\nTesting:\n\n";
$test->run(1, 15, 1, true);
// Frequency of occurrances (sanity check)
$fdist = array_combine(array('neither', 'fizz', 'buzz', 'fizzbuzz'), $test->frequency(100000));
echo "\nFrequency:\n\n" . print_r($fdist, true) . "\n";
// Time trials
$times = array('Version 1' => $test->run(10, 100000, 1), 'Version 2' => $test->run(10, 100000, 2), 'Version 3' => $test->run(10, 100000, 3));
echo "Times:\n\n" . print_r($times, true) . "\n";
Exemplo n.º 15
0
<?php

/**
 * Teste DotGroup: Avaliação para Analista Desenvolvedor.
 *
 * PHP version 5.5.12
 *
 * @category  FizzBuzz
 * @package   Index
 * @author    GêBender <*****@*****.**>
 * @license   http://www.opensource.org/licenses/mit-license.php MIT License
 * @version   GIT: <git_id>
 * @link      http://www.gebender.com.br/teste-dot-group/fizz-buzz
 */
namespace FizzBuzz;

require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Core' . DIRECTORY_SEPARATOR . 'FizzBuzz.php';
$FizzBuzz = new FizzBuzz();
echo implode('<br>', $FizzBuzz->show(100));