| @@ 45-60 (lines=16) @@ | ||
| 42 | * |
|
| 43 | * @dataProvider compareDataProvider |
|
| 44 | */ |
|
| 45 | public function testCompare($a, $b, $expected) |
|
| 46 | { |
|
| 47 | $this |
|
| 48 | ->assert('The comparision is right') |
|
| 49 | /* @var \Cubiche\Core\Comparable\ComparatorInterface $comparator */ |
|
| 50 | ->given($comparator = $this->newDefaultTestedInstance()) |
|
| 51 | ->then($this->comparision($comparator, $a, $b, $expected)); |
|
| 52 | ||
| 53 | $this |
|
| 54 | ->assert('The comparator is a callable') |
|
| 55 | ->given($result1 = $comparator->compare($a, $b)) |
|
| 56 | ->when($result2 = $comparator($a, $b)) |
|
| 57 | ->then() |
|
| 58 | ->variable($result1) |
|
| 59 | ->isEqualTo($result2); |
|
| 60 | } |
|
| 61 | ||
| 62 | /** |
|
| 63 | * Test reverse method. |
|
| @@ 99-117 (lines=19) @@ | ||
| 96 | * |
|
| 97 | * @dataProvider otherwiseDataProvider |
|
| 98 | */ |
|
| 99 | public function testOtherwise(callable $otherwise, $a, $b, $expected) |
|
| 100 | { |
|
| 101 | $this |
|
| 102 | ->assert('The otherwise result is a comparator') |
|
| 103 | /* @var \Cubiche\Core\Comparable\ComparatorInterface $comparator */ |
|
| 104 | ->given($comparator = $this->newDefaultTestedInstance()) |
|
| 105 | ->when($otherwiseComparator = $comparator->otherwise($otherwise)) |
|
| 106 | ->object($otherwiseComparator) |
|
| 107 | ->isInstanceOf(ComparatorInterface::class) |
|
| 108 | ; |
|
| 109 | ||
| 110 | $this |
|
| 111 | ->assert('The otherwise comparator result is right') |
|
| 112 | ->let($expected = $this->sign($expected)) |
|
| 113 | ->then( |
|
| 114 | $this->comparision($otherwiseComparator, $a, $b, $expected == 0 ? $otherwise($a, $b) : $expected) |
|
| 115 | ) |
|
| 116 | ; |
|
| 117 | } |
|
| 118 | ||
| 119 | /** |
|
| 120 | * @return array |
|