public void FromDataTest2()
{
Accord.Math.Random.Generator.Seed = 0;
double[][] points =
{
new double[] { 2, 3 },
new double[] { 5, 4 },
new double[] { 9, 6 },
new double[] { 4, 7 },
new double[] { 8, 1 },
new double[] { 7, 2 },
};
var tree = SPTree.FromData(points);
var nodes = tree.ToList();
Assert.IsTrue(tree.Root.IsCorrect());
foreach (var p in points)
{
Assert.IsTrue(nodes.Where(x => x.IsLeaf && !x.IsEmpty)
.Select(x => x.Position)
.Contains(p, new ArrayComparer<double>()));
}
Assert.IsTrue(tree.Root.IsCorrect());
Assert.IsFalse(tree.Root.IsLeaf);
Assert.IsNull(tree.Root.Position);
Assert.AreEqual(5.8333333333333339, tree.Root.CenterOfMass[0]);
Assert.AreEqual(3.8333333333333339, tree.Root.CenterOfMass[1]);
Assert.AreEqual(4, tree.Root.Children.Length);
Assert.AreEqual(9, tree.Root.Children[0].Position[0]);
Assert.AreEqual(6, tree.Root.Children[0].Position[1]);
Assert.IsNull(tree.Root.Children[1].Position);
Assert.AreEqual(4.5, tree.Root.Children[1].CenterOfMass[0]);
Assert.AreEqual(5.5, tree.Root.Children[1].CenterOfMass[1]);
}