Esempio n. 1
0
 public function testMax()
 {
     // Arrange
     $a = [1, 2, 3];
     // Act
     $x = __::max($a);
     // Assert
     $this->assertEquals(3, $x);
 }
 public function testMax()
 {
     // from js
     $this->assertEquals(3, __::max(array(1, 2, 3)), 'can perform a regular max');
     $this->assertEquals(1, __::max(array(1, 2, 3), function ($num) {
         return -$num;
     }), 'can performa a computation-based max');
     // extra
     $stooges = array(array('name' => 'moe', 'age' => 40), array('name' => 'larry', 'age' => 50), array('name' => 'curly', 'age' => 60));
     $this->assertEquals($stooges[2], __::max($stooges, function ($stooge) {
         return $stooge['age'];
     }));
     $this->assertEquals($stooges[0], __::max($stooges, function ($stooge) {
         return $stooge['name'];
     }));
     $this->assertEquals($stooges[0], __($stooges)->max(function ($stooge) {
         return $stooge['name'];
     }), 'works with OO-style call');
     // docs
     $stooges = array(array('name' => 'moe', 'age' => 40), array('name' => 'larry', 'age' => 50), array('name' => 'curly', 'age' => 60));
     $this->assertEquals(array('name' => 'curly', 'age' => 60), __::max($stooges, function ($stooge) {
         return $stooge['age'];
     }));
 }