Exemplo n.º 1
0
 public function testLast()
 {
     // Arrange
     $a = [1, 2, 3, 4, 5];
     // Act
     $x = __::last($a, 2);
     // Assert
     $this->assertEquals([4, 5], $x);
 }
Exemplo n.º 2
0
 public function testLast()
 {
     // from js
     $this->assertEquals(3, __::last(array(1, 2, 3)), 'can pull out the last element of an array');
     $this->assertEquals('', join(', ', __::last(array(1, 2, 3), 0)), 'can pass n to last');
     $this->assertEquals('2, 3', join(', ', __::last(array(1, 2, 3), 2)), 'can pass n to last');
     $this->assertEquals('1, 2, 3', join(', ', __::last(array(1, 2, 3), 5)), 'can pass n to last');
     $result = __::map(array(array(1, 2, 3), array(1, 2, 3)), function ($item) {
         return __::last($item);
     });
     $this->assertEquals('3,3', join(',', $result), 'works well with map');
     // docs
     $this->assertEquals(1, __::last(array(5, 4, 3, 2, 1)));
 }
Exemplo n.º 3
0
 public function testClon()
 {
     // from js
     $moe = array('name' => 'moe', 'lucky' => array(13, 27, 34));
     $clone = __::clon($moe);
     $this->assertEquals('moe', $clone['name'], 'the clone as the attributes of the original');
     $moe_obj = (object) $moe;
     $clone_obj = __::clon($moe_obj);
     $this->assertEquals('moe', $clone_obj->name, 'the clone as the attributes of the original');
     $clone['name'] = 'curly';
     $this->assertTrue($clone['name'] === 'curly' && $moe['name'] === 'moe', 'clones can change shallow attributes without affecting the original');
     $clone_obj->name = 'curly';
     $this->assertTrue($clone_obj->name === 'curly' && $moe_obj->name === 'moe', 'clones can change shallow attributes without affecting the original');
     $clone['lucky'][] = 101;
     $this->assertEquals(101, __::last($moe['lucky']), 'changes to deep attributes are shared with the original');
     $clone_obj->lucky[] = 101;
     $this->assertEquals(101, __::last($moe_obj->lucky), 'changes to deep attributes are shared with the original');
     $val = 1;
     $this->assertEquals(1, __::clon($val), 'non objects should not be changed by clone');
     $val = null;
     $this->assertEquals(null, __::clon($val), 'non objects should not be changed by clone');
     // extra
     $foo = array('name' => 'Foo');
     $bar = __($foo)->clon();
     $this->assertEquals('Foo', $bar['name'], 'works with OO-style call');
     // docs
     $stooge = (object) array('name' => 'moe');
     $this->assertEquals((object) array('name' => 'moe'), __::clon($stooge));
 }
Exemplo n.º 4
0
 public function testLast()
 {
     $object = array(5, 10, 15, 20);
     $return = array(5);
     $result = __::last($object, 2, function ($row) {
         if ($row < 10) {
             return true;
         } else {
             return false;
         }
     });
     $this->assertEquals($return, $result);
 }