Skip to content

Commit 539e223

Browse files
Leon Wabekealyst
authored andcommitted
dbscan(): drop number of points <= num dims test
add unit tests for n=3,2,1,0 points
1 parent 7a675b9 commit 539e223

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/dbscan.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ function dbscan(points::AbstractMatrix, radius::Real;
101101
if metric !== nothing
102102
# points are point coordinates
103103
dim, num_points = size(points)
104-
num_points <= dim && throw(ArgumentError("points has $dim rows and $num_points columns. Must be a D x N matric with D < N"))
105104
kdtree = KDTree(points, metric; nntree_kwargs...)
106105
data = (kdtree, points)
107106
else

test/dbscan.jl

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,51 @@ include("test_helpers.jl")
1414
@test @inferred(dbscan(randn(2, 2), 0.5, metric=nothing, min_neighbors=1)) isa DbscanResult
1515
end
1616

17+
@testset "Simple 2D tests" begin
18+
X = [10.0 0.0 10.5
19+
0.0 10.0 0.1]
20+
21+
@testset "n=3 samples" begin
22+
X3 = X
23+
24+
R = dbscan(X3, 20)
25+
@test nclusters(R) == 1
26+
27+
R = dbscan(X3, 1.0)
28+
@test nclusters(R) == 2
29+
30+
R = dbscan(X3, 0.1)
31+
@test nclusters(R) == 3
32+
end
33+
34+
@testset "n=2 samples" begin
35+
X2 = X[:, 1:2]
36+
37+
R = dbscan(X2, 20)
38+
@test nclusters(R) == 1
39+
40+
R = dbscan(X2, 1.0)
41+
@test nclusters(R) == 2
42+
end
43+
44+
@testset "n=1 samples" begin
45+
X1 = X[:, 1:1]
46+
47+
R = dbscan(X1, 20)
48+
@test nclusters(R) == 1
49+
50+
R = dbscan(X1, 1.0)
51+
@test nclusters(R) == 1
52+
end
53+
54+
@testset "n=0 samples" begin
55+
X0 = X[:, 1:0]
56+
57+
R = dbscan(X0, 20)
58+
@test nclusters(R) == 0
59+
end
60+
end
61+
1762
@testset "clustering synthetic data with 3 clusters" begin
1863
Random.seed!(34568)
1964

0 commit comments

Comments
 (0)