-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathApplicatorLiftTest.php
More file actions
42 lines (34 loc) · 1.01 KB
/
ApplicatorLiftTest.php
File metadata and controls
42 lines (34 loc) · 1.01 KB
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
40
41
42
<?php
declare(strict_types=1);
namespace example;
use PHPUnit\Framework\TestCase;
use Widmogrod\Functional as f;
use Widmogrod\Primitive\Listt;
function sum_($a, $b)
{
return $a + $b;
}
class ApplicatorLiftTest extends TestCase
{
public function test_it_should_sum_all_from_one_list_with_elements_from_second()
{
$listA = f\fromIterable([1, 2]);
$listB = f\fromIterable([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 = f\fromIterable([1, 2]);
$b = f\fromIterable([4, 5]);
$result = f\map($sum, $a)->ap($b);
$this->assertEquals(
f\fromIterable([5, 6, 6, 7]),
$result
);
}
}