/** * This method tests if the TreeMap is sorted * correctly by the passed Comparator. * * return void */ public function testSortedByComparator() { // initialize a new TreeMap $map = new TreeMap(new TestComparator()); // add several values $map->add(0, 3); $map->add(1, 2); $map->add(2, 1); // initialize the values $counter = 1; $keys = 0; // check the sort order foreach ($map as $key => $value) { $this->assertEquals($keys++, $key); $this->assertEquals($counter++, $value); } }