public function testFirst() { // from js $this->assertEquals(1, __u::first(array(1, 2, 3)), 'can pull out the first element of an array'); $this->assertEquals(array(), __u::first(array(1, 2, 3), 0), 'can pass an index to first'); $this->assertEquals(array(1, 2), __u::first(array(1, 2, 3), 2), 'can pass an index to first'); $this->assertEquals(1, __u(array(1, 2, 3))->first(), 'can perform OO-style "first()"'); $result = __u::map(array(array(1, 2, 3), array(1, 2, 3)), function ($vals) { return __u::first($vals); }); $this->assertEquals(array(1, 1), $result, 'works well with _.map'); $func = function () { return __u::first(func_get_args()); }; $result = $func(4, 3, 2, 1); $this->assertEquals(4, $result, 'works on an arguments object'); // extra $this->assertEquals(array(1), __u::first(array(1, 2, 3), 1), 'can pass an index of 1 to first'); $this->assertEquals(array(4, 5), __u(array(4, 5, 6, 7))->first(2), 'can perform OO-style "first()" with index passed'); $this->assertEquals(1, __u::head(array(1, 2, 3)), 'aliased as "head"'); $this->assertEquals(array(), __u::head(array(1, 2, 3), 0), 'aliased as "head"'); // docs $this->assertEquals(5, __u::first(array(5, 4, 3, 2, 1))); $this->assertEquals(array(5, 4, 3), __u::first(array(5, 4, 3, 2, 1), 3)); }
public function testUniqueId() { // docs $this->assertEquals(0, __u::uniqueId()); $this->assertEquals('stooge_1', __u::uniqueId('stooge_')); $this->assertEquals(2, __u::uniqueId()); // from js $ids = array(); $i = 0; while ($i++ < 100) { array_push($ids, __u::uniqueId()); } $this->assertEquals(count($ids), count(__u::uniq($ids))); // extra $this->assertEquals('stooges', join('', __u::first(__u::uniqueId('stooges'), 7)), 'prefix assignment works'); $this->assertEquals('stooges', join('', __u(__u('stooges')->uniqueId())->first(7)), 'prefix assignment works in OO-style call'); while ($i++ < 100) { array_push($ids, __u()->uniqueId()); } $this->assertEquals(count($ids), count(__u()->uniq($ids))); }