22
33namespace Ahc \Underscore \Tests ;
44
5- use Ahc \Underscore \UnderscoreArray as _ ;
5+ use Ahc \Underscore \Underscore as _ ;
66
77class UnderscoreArrayTest extends \PHPUnit_Framework_TestCase
88{
99 public function test_first_last ()
1010 {
1111 $ array = range (rand (5 , 10 ), rand (15 , 20 ));
1212
13- $ this ->assertSame ($ array [0 ], _:: _ ($ array )->first (), 'first ' );
14- $ this ->assertSame (array_reverse ($ array )[0 ], _:: _ ($ array )->last (), 'last ' );
13+ $ this ->assertSame ($ array [0 ], underscore ($ array )->first (), 'first ' );
14+ $ this ->assertSame (array_reverse ($ array )[0 ], underscore ($ array )->last (), 'last ' );
1515
1616 $ array = ['x ' => ['first ' ], 'z ' => 'last ' ];
1717
18- $ this ->assertSame ($ array ['x ' ], _:: _ ($ array )->head (), 'first ' );
19- $ this ->assertSame ($ array ['z ' ], _:: _ ($ array )->tail (), 'last ' );
18+ $ this ->assertSame ($ array ['x ' ], underscore ($ array )->head (), 'first ' );
19+ $ this ->assertSame ($ array ['z ' ], underscore ($ array )->tail (), 'last ' );
2020
2121 $ array = range (1 , 5 );
2222
23- $ this ->assertSame ([1 , 2 , 3 ], _:: _ ($ array )->take (3 ), 'first 3 ' );
24- $ this ->assertSame ([1 , 2 , 3 , 4 , 5 ], _:: _ ($ array )->first (6 ), 'first 6 (n + 1) ' );
25- $ this ->assertSame ([2 => 3 , 3 => 4 , 4 => 5 ], _:: _ ($ array )->drop (3 ), 'last 3 ' );
26- $ this ->assertSame ([1 , 2 , 3 , 4 , 5 ], _:: _ ($ array )->last (6 ), 'last 6 (n + 1) ' );
23+ $ this ->assertSame ([1 , 2 , 3 ], underscore ($ array )->take (3 ), 'first 3 ' );
24+ $ this ->assertSame ([1 , 2 , 3 , 4 , 5 ], underscore ($ array )->first (6 ), 'first 6 (n + 1) ' );
25+ $ this ->assertSame ([2 => 3 , 3 => 4 , 4 => 5 ], underscore ($ array )->drop (3 ), 'last 3 ' );
26+ $ this ->assertSame ([1 , 2 , 3 , 4 , 5 ], underscore ($ array )->last (6 ), 'last 6 (n + 1) ' );
2727 }
2828
2929 public function test_compact ()
3030 {
3131 $ array = [0 , 'a ' , '' , [], 2 , [1 ]];
3232
33- $ this ->assertSame ([1 => 'a ' , 4 => 2 , 5 => [1 ]], _:: _ ($ array )->compact ()->get (), 'first ' );
33+ $ this ->assertSame ([1 => 'a ' , 4 => 2 , 5 => [1 ]], underscore ($ array )->compact ()->get (), 'first ' );
3434 }
3535
3636 public function test_flatten ()
@@ -39,7 +39,7 @@ public function test_flatten()
3939
4040 $ this ->assertSame (
4141 [0 , 'a ' , '' , 1 , 2 , 'b ' , 3 , 4 , 'c ' , 5 , 'd ' ],
42- _:: _ ($ array )->flatten ()->get (),
42+ underscore ($ array )->flatten ()->get (),
4343 'flatten '
4444 );
4545 }
@@ -50,15 +50,15 @@ public function test_unique_uniq()
5050
5151 $ this ->assertSame (
5252 [0 , 'a ' , '' , 1 , 6 => 2 , 8 => 3 ],
53- _:: _ ($ array )->unique ()->get (),
53+ underscore ($ array )->unique ()->get (),
5454 'unique '
5555 );
5656
5757 $ array = ['a ' , '' , 'a ' , 1 , '' , 0 , 1 , 'b ' , 3 , 2 ];
5858
5959 $ this ->assertSame (
6060 ['a ' , '' , 3 => 1 , 5 => 0 , 7 => 'b ' , 8 => 3 , 9 => 2 ],
61- _:: _ ($ array )->uniq (function ($ i ) {
61+ underscore ($ array )->uniq (function ($ i ) {
6262 return $ i ;
6363 })->get (),
6464 'uniq '
@@ -71,13 +71,13 @@ public function test_difference_without()
7171
7272 $ this ->assertSame (
7373 [1 => 2 , 'a ' => 3 ],
74- _:: _ ($ array )->difference ([1 , [4 ]])->get (),
74+ underscore ($ array )->difference ([1 , [4 ]])->get (),
7575 'difference '
7676 );
7777
7878 $ this ->assertSame (
7979 ['a ' => 3 , 'b ' => [4 ]],
80- _:: _ ($ array )->without ([1 , 2 ])->get (),
80+ underscore ($ array )->without ([1 , 2 ])->get (),
8181 'without '
8282 );
8383 }
@@ -88,7 +88,7 @@ public function test_union()
8888
8989 $ this ->assertSame (
9090 [1 , 2 , 'a ' => 4 , 3 , 'b ' => [5 ]],
91- _:: _ ($ array )->union ([3 , 'a ' => 4 , 'b ' => [5 ]])->get (),
91+ underscore ($ array )->union ([3 , 'a ' => 4 , 'b ' => [5 ]])->get (),
9292 'union '
9393 );
9494 }
@@ -99,7 +99,7 @@ public function test_intersection()
9999
100100 $ this ->assertSame (
101101 [1 => 2 , 'a ' => 3 ],
102- _:: _ ($ array )->intersection ([2 , 'a ' => 3 , 3 ])->get (),
102+ underscore ($ array )->intersection ([2 , 'a ' => 3 , 3 ])->get (),
103103 'intersection '
104104 );
105105 }
@@ -110,7 +110,7 @@ public function test_zip()
110110
111111 $ this ->assertSame (
112112 [[1 , 2 ], [2 , 4 ], 'a ' => [3 , 5 ], 'b ' => ['B ' , null ]],
113- _:: _ ($ array )->zip ([2 , 4 , 'a ' => 5 ])->get (),
113+ underscore ($ array )->zip ([2 , 4 , 'a ' => 5 ])->get (),
114114 'zip '
115115 );
116116 }
@@ -119,7 +119,7 @@ public function test_object()
119119 {
120120 $ array = [[1 , 2 ], 'a ' => 3 , 'b ' => 'B ' ];
121121
122- foreach (_:: _ ($ array )->object () as $ index => $ value ) {
122+ foreach (underscore ($ array )->object () as $ index => $ value ) {
123123 $ this ->assertTrue (is_object ($ value ));
124124 $ this ->assertSame ($ index , $ value ->index );
125125 $ this ->assertSame ($ array [$ index ], $ value ->value );
@@ -128,7 +128,7 @@ public function test_object()
128128
129129 public function test_findIndex_findLastIndex ()
130130 {
131- $ array = _:: _ ([[1 , 2 ], 'a ' => 3 , 'x ' => 4 , 'y ' => 2 , 'b ' => 'B ' ]);
131+ $ array = underscore ([[1 , 2 ], 'a ' => 3 , 'x ' => 4 , 'y ' => 2 , 'b ' => 'B ' ]);
132132
133133 $ this ->assertSame (0 , $ array ->findIndex ());
134134 $ this ->assertSame ('b ' , $ array ->findLastIndex ());
@@ -143,25 +143,25 @@ public function test_findIndex_findLastIndex()
143143
144144 public function test_indexOf_lastIndexOf ()
145145 {
146- $ array = _:: _ ([[1 , 2 ], 'a ' => 2 , 'x ' => 4 , 'y ' => 2 , 'b ' => 'B ' ]);
146+ $ array = underscore ([[1 , 2 ], 'a ' => 2 , 'x ' => 4 , 'y ' => 2 , 'b ' => 'B ' ]);
147147
148148 $ this ->assertSame ('a ' , $ array ->indexOf (2 ));
149149 $ this ->assertSame ('y ' , $ array ->lastIndexOf (2 ));
150150 }
151151
152152 public function test_range ()
153153 {
154- $ this ->assertSame ([4 , 5 , 6 , 7 , 8 , 9 ], _:: _ ()->range (4 , 9 )->get ());
155- $ this ->assertSame ([10 , 12 , 14 , 16 , 18 ], _:: _ ()->range (10 , 18 , 2 )->get ());
156- $ this ->assertSame ([20 , 19 , 18 , 17 , 16 ], _:: _ ()->range (20 , 16 , -1 )->get ());
154+ $ this ->assertSame ([4 , 5 , 6 , 7 , 8 , 9 ], underscore ()->range (4 , 9 )->get ());
155+ $ this ->assertSame ([10 , 12 , 14 , 16 , 18 ], underscore ()->range (10 , 18 , 2 )->get ());
156+ $ this ->assertSame ([20 , 19 , 18 , 17 , 16 ], underscore ()->range (20 , 16 , -1 )->get ());
157157 }
158158
159159 public function test_sortedIndex ()
160160 {
161161 $ nums = [1 , 3 , 5 , 8 , 11 ];
162162 $ new = 9 ;
163163
164- $ newIdx = _:: _ ($ nums )->sortedIndex ($ new , null );
164+ $ newIdx = underscore ($ nums )->sortedIndex ($ new , null );
165165
166166 $ this ->assertSame (4 , $ newIdx );
167167
@@ -174,7 +174,7 @@ public function test_sortedIndex()
174174 ];
175175
176176 $ new = ['x ' => 3 , 'y ' => 2 ];
177- $ newIdx = _:: _ ($ data )->sortedIndex ($ new , function ($ row ) {
177+ $ newIdx = underscore ($ data )->sortedIndex ($ new , function ($ row ) {
178178 return $ row ['x ' ] + $ row ['y ' ];
179179 });
180180
0 commit comments