public function testInKeyOrderCustomCompareReverse()
 {
     $map = new ArrayOrderedMap();
     $map->insert("Gamma-10", 10);
     $map->insert("Gamma-1", 1);
     $map->insert("Gamma-100", 100);
     $map = new ImmutableOrderedMap($map);
     $prefix_length = strlen('Gamma-');
     $compare = function ($a, $b) use($prefix_length) {
         $a_num = intval(substr($a, $prefix_length));
         $b_num = intval(substr($b, $prefix_length));
         return $a_num - $b_num;
     };
     $expectedOrder = [['key' => 'Gamma-100', 'val' => 100], ['key' => 'Gamma-10', 'val' => 10], ['key' => 'Gamma-1', 'val' => 1]];
     $j = 0;
     foreach ($map->inKeyOrder(true, $compare) as $key => $value) {
         $expected = $expectedOrder[$j];
         $this->assertEquals($expected['key'], $key);
         $this->assertEquals($expected['val'], $value);
         ++$j;
     }
 }
Ejemplo n.º 2
0
 public function testRemove()
 {
     $map = new ArrayOrderedMap();
     $map->insert('Alpha', 42);
     $value_to_remove = new \stdClass();
     $map->insert('Beta', $value_to_remove);
     $map->insert('Gamma', 200);
     list($value, $pos) = $map->remove('Beta');
     $this->assertSame($value_to_remove, $value);
     $this->assertEquals(1, $pos);
     $this->setExpectedException(KeyNotFoundException::class);
     $map->remove('DoesntExist');
 }