Completed
Pull Request — master (#13)
by Siwapun
04:10
created

IfElseTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testIfElseOnFalseCondition() 0 15 1
A testIfElseOnTrueCondition() 0 15 1
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