Example #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;
 }
 /**
  * @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());
 }
Example #3
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";