1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Aerophant\RamdaTest; |
4
|
|
|
|
5
|
|
|
use function Aerophant\Ramda\insert; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
|
8
|
|
|
class InsertTest extends TestCase |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
public function testInsertFirst() |
12
|
|
|
{ |
13
|
|
|
$array = [1, 2, 3, 4, 5]; |
14
|
|
|
$expected = ['newItem', 1, 2, 3, 4, 5]; |
15
|
|
|
$actual = insert(0)('newItem')($array); |
16
|
|
|
$this->assertEquals($expected, $actual); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function testInsertLast() |
20
|
|
|
{ |
21
|
|
|
$array = [1, 2, 3, 4, 5]; |
22
|
|
|
$expected = [1, 2, 3, 4, 5, 'newItem']; |
23
|
|
|
$actual = insert(5)('newItem')($array); |
24
|
|
|
$this->assertEquals($expected, $actual); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testInsertNth() |
28
|
|
|
{ |
29
|
|
|
$array = [1, 2, 3, 4, 5]; |
30
|
|
|
$expected = [1, 2, 'newItem', 3, 4, 5]; |
31
|
|
|
$actual = insert(2)('newItem')($array); |
32
|
|
|
$this->assertEquals($expected, $actual); |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|