function testToArray() { $copy = []; $emptyArray = $this->object->toArray($copy, null); $this->assertTrue(is_array($emptyArray)); $this->assertCount(0, $emptyArray); $this->object->append(1); $this->object->append(5); $this->object->append(3); $notEmptyArray = $this->object->toArray($copy, null); $this->assertTrue(is_array($notEmptyArray)); $this->assertCount(3, $notEmptyArray); }
/** * Compares two vectors. * * @param Vector $v * @return bool True if vectors are equal, false otherwise. */ public function equals(Vector $v) { if ($this->dimension != $v->getDimensions()) { throw new Exception("Both vectors must have the same size"); } $otherComponents = $v->toArray(); $ret = true; for ($i = 0; $ret && $i < $this->dimension; ++$i) { $ret = $this->components[$i] == $otherComponents[$i]; } return $ret; }
function __construct(Vector $vector) { parent::__construct(new \ArrayIterator($vector->toArray())); $this->rewind(); }