|
1 | 1 | <?php
|
2 | 2 |
|
| 3 | +declare(strict_types = 1); |
| 4 | + |
3 | 5 | namespace CodelyTV\FinderKataTest\Algorithm;
|
4 | 6 |
|
5 | 7 | use CodelyTV\FinderKata\Algorithm\Finder;
|
| 8 | +use CodelyTV\FinderKata\Algorithm\FT; |
| 9 | +use CodelyTV\FinderKata\Algorithm\Thing; |
6 | 10 | use PHPUnit\Framework\TestCase;
|
7 | 11 |
|
8 | 12 | final class FinderTest extends TestCase
|
9 | 13 | {
|
| 14 | + /** @var Thing */ |
| 15 | + private $sue; |
| 16 | + |
| 17 | + /** @var Thing */ |
| 18 | + private $greg; |
| 19 | + |
| 20 | + /** @var Thing */ |
| 21 | + private $sarah; |
| 22 | + |
| 23 | + /** @var Thing */ |
| 24 | + private $mike; |
| 25 | + |
| 26 | + protected function setUp() |
| 27 | + { |
| 28 | + $this->sue = new Thing(); |
| 29 | + $this->sue->name = "Sue"; |
| 30 | + $this->sue->birthDate = new \DateTime("1950-01-01"); |
| 31 | + |
| 32 | + $this->greg = new Thing(); |
| 33 | + $this->greg->name = "Greg"; |
| 34 | + $this->greg->birthDate = new \DateTime("1952-05-01"); |
| 35 | + |
| 36 | + $this->sarah = new Thing(); |
| 37 | + $this->sarah->name = "Sarah"; |
| 38 | + $this->sarah->birthDate = new \DateTime("1982-01-01"); |
| 39 | + |
| 40 | + $this->mike = new Thing(); |
| 41 | + $this->mike->name = "Mike"; |
| 42 | + $this->mike->birthDate = new \DateTime("1979-01-01"); |
| 43 | + } |
| 44 | + |
10 | 45 | /** @test */
|
11 |
| - public function should_be_able_to_instantiate() |
| 46 | + public function should_return_empty_when_given_empty_list() |
12 | 47 | {
|
13 |
| - $finder = new Finder(); |
| 48 | + $list = []; |
| 49 | + $finder = new Finder($list); |
| 50 | + |
| 51 | + $result = $finder->find(FT::ONE); |
| 52 | + |
| 53 | + $this->assertEquals(null, $result->p1); |
| 54 | + $this->assertEquals(null, $result->p2); |
| 55 | + } |
| 56 | + |
| 57 | + /** @test */ |
| 58 | + public function should_return_empty_when_given_one_person() |
| 59 | + { |
| 60 | + $list = []; |
| 61 | + $list[] = $this->sue; |
| 62 | + $finder = new Finder($list); |
| 63 | + |
| 64 | + $result = $finder->find(FT::ONE); |
| 65 | + |
| 66 | + $this->assertEquals(null, $result->p1); |
| 67 | + $this->assertEquals(null, $result->p2); |
| 68 | + } |
| 69 | + |
| 70 | + /** @test */ |
| 71 | + public function should_return_closest_two_for_two_people() |
| 72 | + { |
| 73 | + $list = []; |
| 74 | + $list[] = $this->sue; |
| 75 | + $list[] = $this->greg; |
| 76 | + $finder = new Finder($list); |
| 77 | + |
| 78 | + $result = $finder->find(FT::ONE); |
| 79 | + |
| 80 | + $this->assertEquals($this->sue, $result->p1); |
| 81 | + $this->assertEquals($this->greg, $result->p2); |
| 82 | + } |
| 83 | + |
| 84 | + /** @test */ |
| 85 | + public function should_return_furthest_two_for_two_people() |
| 86 | + { |
| 87 | + $list = []; |
| 88 | + $list[] = $this->mike; |
| 89 | + $list[] = $this->greg; |
| 90 | + $finder = new Finder($list); |
| 91 | + |
| 92 | + $result = $finder->find(FT::TWO); |
| 93 | + |
| 94 | + $this->assertEquals($this->greg, $result->p1); |
| 95 | + $this->assertEquals($this->mike, $result->p2); |
| 96 | + } |
| 97 | + |
| 98 | + /** @test */ |
| 99 | + public function should_return_furthest_two_for_four_people() |
| 100 | + { |
| 101 | + $list = []; |
| 102 | + $list[] = $this->sue; |
| 103 | + $list[] = $this->sarah; |
| 104 | + $list[] = $this->mike; |
| 105 | + $list[] = $this->greg; |
| 106 | + $finder = new Finder($list); |
| 107 | + |
| 108 | + $result = $finder->find(FT::TWO); |
| 109 | + |
| 110 | + $this->assertEquals($this->sue, $result->p1); |
| 111 | + $this->assertEquals($this->sarah, $result->p2); |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * @test |
| 116 | + */ |
| 117 | + public function should_return_closest_two_for_four_people() |
| 118 | + { |
| 119 | + $list = []; |
| 120 | + $list[] = $this->sue; |
| 121 | + $list[] = $this->sarah; |
| 122 | + $list[] = $this->mike; |
| 123 | + $list[] = $this->greg; |
| 124 | + $finder = new Finder($list); |
| 125 | + |
| 126 | + $result = $finder->find(FT::ONE); |
14 | 127 |
|
15 |
| - $this->assertInstanceOf(Finder::class, $finder); |
| 128 | + $this->assertEquals($this->sue, $result->p1); |
| 129 | + $this->assertEquals($this->greg, $result->p2); |
16 | 130 | }
|
17 | 131 | }
|
0 commit comments