示例#1
0
 function testMap()
 {
     $vector = new Vector(0, 1, 2, 3);
     $mapped = $vector->map(function ($value, $key) {
         return $value + $key;
     });
     $this->assertInstanceOf('Collections\\Vector', $mapped);
     $this->assertCount(count($vector), $mapped);
     foreach ($mapped as $key => $value) {
         $this->assertEquals($key * 2, $value);
     }
 }
示例#2
0
 public function testVectorMapWithMethod()
 {
     $vector_of_objects = new Vector(new TestNode("testa"), new TestNode("testb"), new TestNode("testc"));
     $this->assertEquals($vector_of_objects->map('upper')->data, array("TESTA", "TESTB", "TESTC"));
 }