Ejemplo n.º 1
0
 function testIterator()
 {
     $map = new SortedMap();
     $map[0] = 1;
     $map[2] = 3;
     $map[3] = 4;
     $map[1] = 2;
     $iterator = $map->getIterator();
     $this->assertInstanceOf('Collections\\SortedMapIterator', $iterator);
     $this->assertCount(count($map), $iterator);
     $iterator->rewind();
     for ($i = 0; $i < count($map); $i++) {
         $this->assertTrue($iterator->valid());
         $this->assertEquals($i, $iterator->key());
         $expectedValue = $map[$i];
         $this->assertEquals($expectedValue, $iterator->current());
         $iterator->next();
     }
     $this->assertFalse($iterator->valid());
     $this->assertCount(count($map), $iterator);
 }
Ejemplo n.º 2
0
 /**
  * @depends testOffsetSet
  * @depends testOffsetExists
  */
 function test__construct()
 {
     $map = new SortedMap(function ($a, $b) {
         return compare(abs($a), abs($b));
     });
     $this->assertFalse($map->offsetExists(0));
     $map[5] = 5;
     $map[8] = 8;
     $map[2] = 2;
     $this->assertFalse($map->offsetExists(0));
     $this->assertFalse($map->offsetExists(10));
     $this->assertFalse($map->offsetExists(-10));
     $this->assertTrue($map->offsetExists(5));
     $this->assertTrue($map->offsetExists(8));
     $this->assertTrue($map->offsetExists(2));
     $this->assertTrue($map->offsetExists(-5));
     $this->assertTrue($map->offsetExists(-8));
     $this->assertTrue($map->offsetExists(-2));
 }