-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFizzBuzzTest.php
More file actions
59 lines (53 loc) · 2.06 KB
/
FizzBuzzTest.php
File metadata and controls
59 lines (53 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
require 'FizzBuzz.php';
class FizzBuzzTest extends PHPUnit_Framework_TestCase
{
protected $fizzBuzz;
public function setUp()
{
$this->fizzBuzz = new FizzBuzz();
}
public function testFizzBuzzForEach()
{
foreach ($this->fizzBuzz as $key => $value) {
if ($key % 3 === 0 && $key % 5 === 0) {
$this->assertEquals('FizzBuzz', $value);
} elseif ($key % 3 === 0) {
$this->assertEquals('Fizz', $value);
} elseif ($key % 5 === 0) {
$this->assertEquals('Buzz', $value);
} else {
$this->assertEquals($key, $value);
}
}
}
public function testFizzBuzzForLoop()
{
for ($this->fizzBuzz->rewind(); $this->fizzBuzz->valid(); $this->fizzBuzz->next()) {
if ($this->fizzBuzz->key() % 3 === 0 && $this->fizzBuzz->key() % 5 === 0) {
$this->assertEquals('FizzBuzz', $this->fizzBuzz->current());
} elseif ($this->fizzBuzz->key() % 3 === 0) {
$this->assertEquals('Fizz', $this->fizzBuzz->current());
} elseif ($this->fizzBuzz->key() % 5 === 0) {
$this->assertEquals('Buzz', $this->fizzBuzz->current());
} else {
$this->assertEquals($this->fizzBuzz->key(), $this->fizzBuzz->current());
}
}
}
public function testFizzBuzzWhileLoop()
{
while ($this->fizzBuzz->valid()) {
if ($this->fizzBuzz->key() % 3 === 0 && $this->fizzBuzz->key() % 5 === 0) {
$this->assertEquals('FizzBuzz', $this->fizzBuzz->current());
} elseif ($this->fizzBuzz->key() % 3 === 0) {
$this->assertEquals('Fizz', $this->fizzBuzz->current());
} elseif ($this->fizzBuzz->key() % 5 === 0) {
$this->assertEquals('Buzz', $this->fizzBuzz->current());
} else {
$this->assertEquals($this->fizzBuzz->key(), $this->fizzBuzz->current());
}
$this->fizzBuzz->next();
}
}
}