forked from widmogrod/php-functional
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ApplicatorLiftTest.php
39 lines (32 loc) · 963 Bytes
/
ApplicatorLiftTest.php
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
<?php
namespace example;
use Widmogrod\Functional as f;
use Widmogrod\Primitive\Listt;
function sum($a, $b)
{
return $a + $b;
}
class ApplicatorLiftTest extends \PHPUnit_Framework_TestCase
{
public function test_it_should_sum_all_from_one_list_with_elements_from_second()
{
$listA = Listt::of([1, 2]);
$listB = Listt::of([4, 5]);
// sum <*> [1, 2] <*> [4, 5]
$result = f\liftA2('example\sum', $listA, $listB);
$this->assertInstanceOf(Listt::class, $result);
$this->assertEquals([5, 6, 6, 7], f\valueOf($result));
}
public function test_it_should_sum_all_from_one_list_with_single_element()
{
// sum <$> [1, 2] <*> [4, 5]
$sum = f\curryN(2, 'example\sum');
$a = Listt::of([1, 2]);
$b = Listt::of([4, 5]);
$result = f\map($sum, $a)->ap($b);
$this->assertEquals(
Listt::of([5, 6, 6, 7]),
$result
);
}
}