public function testUniqueId() { // docs $this->assertEquals(0, __::uniqueId()); $this->assertEquals('stooge_1', __::uniqueId('stooge_')); $this->assertEquals(2, __::uniqueId()); // from js $ids = array(); $i = 0; while ($i++ < 100) { array_push($ids, __::uniqueId()); } $this->assertEquals(count($ids), count(__::uniq($ids))); // extra $this->assertEquals('stooges', join('', __::first(__::uniqueId('stooges'), 7)), 'prefix assignment works'); }
public function testUniq() { // from js $list = array(1, 2, 1, 3, 1, 9); $this->assertEquals(array(1, 2, 3, 9), __::uniq($list), 'can find the unique values of an unsorted array'); $list = array(1, 1, 1, 2, 2, 3); $this->assertEquals(array(1, 2, 3), __::uniq($list), 'can find the unique values of a sorted array faster'); $func = function () { return __::uniq(func_get_args()); }; $result = $func(1, 2, 1, 3, 1, 4); $this->assertEquals(array(1, 2, 3, 4), $result, 'works on an arguments object'); $list = array((object) array('name' => 'moe'), (object) array('name' => 'curly'), (object) array('name' => 'larry'), (object) array('name' => 'curly')); $iterator = function ($value) { return $value->name; }; $this->assertEquals(array('moe', 'curly', 'larry'), __::map(__::uniq($list, false, $iterator), $iterator), 'can find the unique values of an array using a custom iterator'); $iterator = function ($value) { return $value + 1; }; $list = array(1, 2, 2, 3, 4, 4); $this->assertEquals(array(1, 2, 3, 4), __::uniq($list, true, $iterator), 'iterator works with sorted array'); // extra $this->assertEquals(array(4, 5, 6), __(array(4, 5, 4, 4, 5, 5, 6))->uniq(), 'works with OO call'); $this->assertEquals(array(4, 5, 6), __(array(4, 5, 4, 4, 5, 5, 6))->unique(), 'aliased as "unique"'); // docs $this->assertEquals(array(2, 4, 1), __::uniq(array(2, 2, 4, 4, 4, 1, 1, 1))); }
public function testUniq() { $object = array(1, 2, 2, 2, 5); $return = array(1, 2, 5); $result = __::uniq($object); $this->assertEquals($return, $result); }