public void KModesConstructorTest()
{
Accord.Math.Random.Generator.Seed = 0;
// Declare some observations
int[][] observations =
{
new int[] { 0, 0 }, // a
new int[] { 0, 1 }, // a
new int[] { 0, 1 }, // a
new int[] { 1, 1 }, // a
new int[] { 5, 3 }, // b
new int[] { 6, 8 }, // b
new int[] { 6, 8 }, // b
new int[] { 6, 7 }, // b
new int[] { 5, 8 }, // b
new int[] { 12, 14 }, // c
new int[] { 12, 14 }, // c
new int[] { 13, 14 }, // c
};
int[][] orig = observations.MemberwiseClone();
// Create a new K-Modes algorithm with 3 clusters
KModes kmodes = new KModes(3);
// Compute the algorithm, retrieving an integer array
// containing the labels for each of the observations
int[] labels = kmodes.Compute(observations);
// As a result, the first three observations should belong to the
// same cluster (thus having the same label). The same should
// happen to the next four observations and to the last two.
Assert.AreEqual(labels[0], labels[1]);
Assert.AreEqual(labels[0], labels[2]);
Assert.AreEqual(labels[0], labels[3]);
Assert.AreEqual(labels[4], labels[5]);
Assert.AreEqual(labels[4], labels[6]);
Assert.AreEqual(labels[4], labels[7]);
Assert.AreEqual(labels[4], labels[8]);
Assert.AreEqual(labels[9], labels[10]);
Assert.AreEqual(labels[9], labels[11]);
Assert.AreNotEqual(labels[0], labels[4]);
Assert.AreNotEqual(labels[0], labels[9]);
Assert.AreNotEqual(labels[4], labels[9]);
int[] labels2 = kmodes.Clusters.Nearest(observations);
Assert.IsTrue(labels.IsEqual(labels2));
// the data must not have changed!
Assert.IsTrue(orig.IsEqual(observations));
}