Beispiel #1
0
 public function testStableSort2()
 {
     $stableSort = _Array::stableSort(_Comparator::alphaNumeric()->map(function ($elem) {
         return $elem['b'];
     }), function ($a, $b) {
         return $a['a'] - $b['a'];
     });
     $this->assertInstanceOf(ArrayStableSort::class, $stableSort);
     $data = ['p' => ['a' => 34, 'b' => 'p1'], 's' => ['a' => 32, 'b' => 's1'], 'l' => ['a' => 32, 'b' => 'l1'], 'm' => ['a' => 31, 'b' => 'm1'], 'n' => ['a' => 23, 'b' => 'm1']];
     $this->assertEquals(json_encode($stableSort($data)), json_encode(['l' => ['a' => 32, 'b' => 'l1'], 'n' => ['a' => 23, 'b' => 'm1'], 'm' => ['a' => 31, 'b' => 'm1'], 'p' => ['a' => 34, 'b' => 'p1'], 's' => ['a' => 32, 'b' => 's1']]));
 }