def test_same_amount_of_neighbours(self): features = load_file_features("skinnyDipData_0.csv") tree = create_tree(features) for edge in tree.edges: self.assertEqual(200, len(tree.neighbours[edge.src]), "All vertices should have same amount of neighbours") self.assertEqual(200, len(tree.neighbours[edge.dest]), "All vertices should have same amount of neighbours")
def test_sorted_by_eucledian_cost(self): features = load_file_features("skinnyDipData_0.csv") tree = create_tree(features) tree.sort() last = 0 for edge in tree.edges: self.assertTrue(last <= edge.cost, "Tree is supposed to be sorted by wasser cost") last = edge.cost
def test_create_tree(self): features = load_file_features("skinnyDipData_0.csv") tree = create_tree(features) tree.wasser_cost_calc() self.assertEqual(3000, tree.number_vertices, "Tree is supposed to have all data points") self.assertEqual(17949, len(tree.edges), "Tree is supposed to contain all edges") self.assertEqual(0, tree.min_wasser, "Min wasser is supposed to be updated") self.assertEqual(0.43006119008417043, tree.max_wasser, "Max wasser is supposed to be updated")
def test_cluster_with_margin(self): features = load_file_features("skinnyDipData_0.csv") labels = load_file_labels("skinnyDipData_0.csv") increment = wasser(features, 0.018500000000000003, labels, 5) clusters = increment.clusters cluster = clusters[1941] noise_cluster = clusters[-1] self.assertEqual(382, cluster.sz, "Cluster size should be of correct size") self.assertEqual(2618, noise_cluster.sz, "Noise cluster should be of correct size") total_sz = 0 for key in clusters.keys(): total_sz += clusters[key].sz self.assertEqual(3000, total_sz, "The total amount of vertices should remain 3000")
def test_cluster_range_with_labels(self): features = load_file_features("skinnyDipData_0.csv") labels = load_file_labels("skinnyDipData_0.csv") increments = wasser_range(features, 0.0185, 0.02, 0.0003, labels, 5) self.assertEqual(6, len(increments), "Wasser_range should produce expected amounts of increments") clusters = increments[-1].clusters cluster = clusters[1941] noise_cluster = clusters[-1] self.assertEqual(414, cluster.sz, "Cluster size should be of correct size") self.assertEqual(2586, noise_cluster.sz, "Noise cluster should be of correct size") total_sz = 0 for key in clusters.keys(): total_sz += clusters[key].sz self.assertEqual(3000, total_sz, "The total amount of vertices should remain 3000")