phpstream\tests\unit\operations\SortedOperationTest::testSortedWithCallback PHP Method

testSortedWithCallback() public method

    public function testSortedWithCallback()
    {
        // Test by sorting modulo 7.
        $instance = new SortedOperation([6, 21, 17, 44, 40], function ($a, $b) {
            if ($a % 7 < $b % 7) {
                return -1;
            }
            return $a % 7 > $b % 7;
        });
        $result = iterator_to_array($instance);
        $expected = [1 => 21, 3 => 44, 2 => 17, 4 => 40, 0 => 6];
        $this->assertEquals($expected, $result);
    }