public function testAddWithObjects()
{
$set = new Set([1, 2, 3]);
$vector = new Vector([1, 2, 3]);
$matrix = new Matrix([[1, 2, 3], [2, 3, 4]]);
$set->add($vector);
$set->add($matrix);
$this->assertEquals(5, count($set));
$this->assertEquals(5, count($set->asArray()));
$objects = 0;
foreach ($set as $key => $value) {
if ($value instanceof \MathPHP\LinearAlgebra\Vector) {
$objects++;
$vector_key = get_class($value) . '(' . spl_object_hash($vector) . ')';
$this->assertEquals($vector_key, $key);
$this->assertEquals($vector, $value);
}
if ($value instanceof \MathPHP\LinearAlgebra\Matrix) {
$objects++;
$matrix_key = get_class($value) . '(' . spl_object_hash($matrix) . ')';
$this->assertEquals($matrix_key, $key);
$this->assertEquals($matrix, $value);
}
}
// There should have been two objects (vector and matrix)
$this->assertEquals(2, $objects);
}