Passed
Push — master ( 59ebee...0b7415 )
by Siwapun
02:59
created

IfElseTest::testIfElseOnTrueCondition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace Aerophant\RamdaTest;
3
4
use function Aerophant\Ramda\ifElse;
5
use PHPUnit\Framework\TestCase;
6
7
class IfElseTest extends TestCase
8
{
9
  public function testIfElseOnTrueCondition()
10
  {
11
    $value = 10;
12
    $isEven = function ($it) {
13
      return $it % 2 === 0;
14
    };
15
    $powerTwo = function ($it) {
16
      return $it * $it;
17
    };
18
    $powerThree = function ($it) {
19
      return $it * $it * $it;
20
    };
21
    $expect = 100;
22
    $actual = ifElse($isEven)($powerTwo)($powerThree)($value);
23
    $this->assertEquals($expect, $actual);
24
  }
25
26
  public function testIfElseOnFalseCondition()
27
  {
28
    $value = 10;
29
    $isOdd = function ($it) {
30
      return $it % 2 !== 0;
31
    };
32
    $powerTwo = function ($it) {
33
      return $it * $it;
34
    };
35
    $powerThree = function ($it) {
36
      return $it * $it * $it;
37
    };
38
    $expect = 1000;
39
    $actual = ifElse($isOdd)($powerTwo)($powerThree)($value);
40
    $this->assertEquals($expect, $actual);
41
  }
42
}
43