public void LinkageTreeTestAdd() { MersenneTwister rand = new MersenneTwister(); LinkageTree tree = new LinkageTree(Length, rand); tree.Add(solutions[0]); tree.Add(solutions[1]); PrivateObject hidden = new PrivateObject(tree); int[][][] result = (int[][][])hidden.GetField("occurances"); Assert.AreEqual(1, result[1][0][0]); // Positions 0 and 1 had value 00 exactly once Assert.AreEqual(2, result[Length - 1][Length - 2][0]); // Positions 0 and 1 had value 00 exactly once Assert.AreEqual(0, result[Length - 1][Length - 2][1]); // Positions 7 and 8 never had value 10 Assert.AreEqual(1, result[1][0][3]); // Positions 0 and 1 had value 11 exactly once }
public void LinkageTreeTestRebuild() { // The seed matters as equal sized clusters can appear in any order MersenneTwister rand = new MersenneTwister(123); LinkageTree tree = new LinkageTree(Length, rand); foreach (var solution in solutions) { tree.Add(solution); } // Check if the clusters created contain the expected variables. var found = tree.Clusters.ToArray(); Assert.AreEqual(correctClusters.Length, found.Length); for (int i = 0; i < found.Length; i++) { found[i].Sort(); Assert.IsTrue(found[i].SequenceEqual(correctClusters[i]), string.Format("Failed On Cluster {0}", i)); } }
public void LinkageTreeTestEntropyDistance() { MersenneTwister rand = new MersenneTwister(); LinkageTree tree = new LinkageTree(Length, rand); PrivateObject hidden = new PrivateObject(tree); // No information should result in a distance of 0 Assert.AreEqual((double)0, hidden.Invoke("EntropyDistance", new object[] { 0, 1 })); foreach (var solution in solutions) { tree.Add(solution); } // Check that 0 and 1 are closer than 0 and 2 var linked = (double)hidden.Invoke("EntropyDistance", new object[] { 0, 1 }); var unlinked = (double)hidden.Invoke("EntropyDistance", new object[] { 0, 2 }); Assert.IsTrue(linked < unlinked); // Reversing the arguments should not change the result var forward = hidden.Invoke("EntropyDistance", new object[] { Length - 1, Length - 2 }); var backward = hidden.Invoke("EntropyDistance", new object[] { Length - 2, Length - 1 }); Assert.AreEqual(forward, backward); }