Completed
Push — master ( 8871bc...78797b )
by Siwapun
03:45
created

testSliceOnStringWithToIndexIsLargerThanArraySize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Aerophant\RamdaTest;
4
5
use function Aerophant\Ramda\slice;
6
use PHPUnit\Framework\TestCase;
7
8
class SliceTest extends TestCase
9
{
10
  public function testSliceOnArray()
11
  {
12
    $fromIndex = 1;
13
    $toIndex = 3;
14
    $list = ['a', 'b', 'c', 'd', 'e'];
15
    $expect = ['b', 'c'];
16
    $actual = slice($fromIndex)($toIndex)($list);
17
    $this->assertEquals($expect, $actual);
18
  }
19
20
  public function testSliceOnArrayWithToIndexIsLargerThanArraySize()
21
  {
22
    $fromIndex = 1;
23
    $toIndex = 300;
24
    $list = ['a', 'b', 'c', 'd'];
25
    $expect = ['b', 'c', 'd'];
26
    $actual = slice($fromIndex)($toIndex)($list);
27
    $this->assertEquals($expect, $actual);
28
  }
29
  public function testSliceOnArrayWithNegativeToIndex()
30
  {
31
    $fromIndex = 0;
32
    $toIndex = -1;
33
    $list = ['a', 'b', 'c', 'd'];
34
    $expect = ['a', 'b', 'c'];
35
    $actual = slice($fromIndex)($toIndex)($list);
36
    $this->assertEquals($expect, $actual);
37
  }
38
  public function testSliceOnArrayWithNegativeIndex()
39
  {
40
    $fromIndex = -3;
41
    $toIndex = -1;
42
    $list = ['a', 'b', 'c', 'd'];
43
    $expect = ['b', 'c'];
44
    $actual = slice($fromIndex)($toIndex)($list);
45
    $this->assertEquals($expect, $actual);
46
  }
47
48
  public function testSliceOnString()
49
  {
50
    $fromIndex = 1;
51
    $toIndex = 3;
52
    $list = 'abcde';
53
    $expect = 'bc';
54
    $actual = slice($fromIndex)($toIndex)($list);
55
    $this->assertEquals($expect, $actual);
56
  }
57
58
  public function testSliceOnStringWithToIndexIsLargerThanArraySize()
59
  {
60
    $fromIndex = 1;
61
    $toIndex = 300;
62
    $list = 'abcd';
63
    $expect = 'bcd';
64
    $actual = slice($fromIndex)($toIndex)($list);
65
    $this->assertEquals($expect, $actual);
66
  }
67
  public function testSliceOnStringWithNegativeToIndex()
68
  {
69
    $fromIndex = 0;
70
    $toIndex = -1;
71
    $list = 'abcd';
72
    $expect = 'abc';
73
    $actual = slice($fromIndex)($toIndex)($list);
74
    $this->assertEquals($expect, $actual);
75
  }
76
  public function testSliceOnStringWithNegativeIndex()
77
  {
78
    $fromIndex = -3;
79
    $toIndex = -1;
80
    $list = 'abcd';
81
    $expect = 'bc';
82
    $actual = slice($fromIndex)($toIndex)($list);
83
    $this->assertEquals($expect, $actual);
84
  }
85
}
86