44"""
55#import pickle
66from nose .tools import assert_less
7+ from nose .tools import assert_greater_equal
78import numpy as np
89from scipy .spatial import distance
910from scipy import sparse
@@ -217,7 +218,6 @@ def test_hdbscan_best_balltree_metric():
217218 n_clusters_2 = len (set (labels )) - int (- 1 in labels )
218219 assert_equal (n_clusters_2 , n_clusters )
219220
220-
221221def test_hdbscan_no_clusters ():
222222 labels , p , persist , ctree , ltree , mtree = hdbscan (X , min_cluster_size = len (X )+ 1 )
223223 n_clusters_1 = len (set (labels )) - int (- 1 in labels )
@@ -226,7 +226,19 @@ def test_hdbscan_no_clusters():
226226 labels = HDBSCAN (min_cluster_size = len (X )+ 1 ).fit (X ).labels_
227227 n_clusters_2 = len (set (labels )) - int (- 1 in labels )
228228 assert_equal (n_clusters_2 , 0 )
229-
229+
230+ def test_hdbscan_min_cluster_size ():
231+ for min_cluster_size in range (2 , len (X )+ 1 , 1 ):
232+ labels , p , persist , ctree , ltree , mtree = hdbscan (X , min_cluster_size = min_cluster_size )
233+ true_labels = [label for label in labels if label != - 1 ]
234+ if len (true_labels ) != 0 :
235+ assert_greater_equal (np .min (np .bincount (true_labels )), min_cluster_size )
236+
237+ labels = HDBSCAN (min_cluster_size = min_cluster_size ).fit (X ).labels_
238+ true_labels = [label for label in labels if label != - 1 ]
239+ if len (true_labels ) != 0 :
240+ assert_greater_equal (np .min (np .bincount (true_labels )), min_cluster_size )
241+
230242def test_hdbscan_callable_metric ():
231243 # metric is the function reference, not the string key.
232244 metric = distance .euclidean
0 commit comments