public function testAddWithMultipleObjects()
{
$set = new Set([1, 2, 3]);
$vector1 = new Vector([1, 2, 3]);
$vector2 = new Vector([1, 2, 3]);
$vector3 = new Vector([4, 5, 6]);
$matrix = new Matrix([[1, 2, 3], [2, 3, 4]]);
$std1 = new \StdClass();
$std2 = new \StdClass();
$std3 = $std2;
// Same object so this wont get added
$set->add($vector1);
$set->add($vector2);
$set->add($vector3);
$set->add($matrix);
$set->add($std1);
$set->add($std2);
$set->add($std3);
$this->assertEquals(9, count($set));
$this->assertEquals(9, count($set->asArray()));
$objects = 0;
foreach ($set as $key => $value) {
if ($value instanceof \MathPHP\LinearAlgebra\Vector) {
$objects++;
$this->assertInstanceOf('MathPHP\\LinearAlgebra\\Vector', $value);
}
if ($value instanceof \MathPHP\LinearAlgebra\Matrix) {
$objects++;
$this->assertInstanceOf('MathPHP\\LinearAlgebra\\Matrix', $value);
}
if ($value instanceof \StdClass) {
$objects++;
$this->assertInstanceOf('StdClass', $value);
}
}
// There should have been four objects (3 vectors and 1 matrix)
$this->assertEquals(6, $objects);
}