diff --git a/src/dbscan.jl b/src/dbscan.jl index b34e580e..bfa04bc3 100644 --- a/src/dbscan.jl +++ b/src/dbscan.jl @@ -101,7 +101,6 @@ function dbscan(points::AbstractMatrix, radius::Real; if metric !== nothing # points are point coordinates dim, num_points = size(points) - num_points <= dim && throw(ArgumentError("points has $dim rows and $num_points columns. Must be a D x N matric with D < N")) kdtree = KDTree(points, metric; nntree_kwargs...) data = (kdtree, points) else diff --git a/test/affprop.jl b/test/affprop.jl index d51c3382..f218f50c 100644 --- a/test/affprop.jl +++ b/test/affprop.jl @@ -6,7 +6,6 @@ using Clustering using LinearAlgebra using Random, StableRNGs using Statistics -include("test_helpers.jl") @testset "affinityprop() (affinity propagation)" begin diff --git a/test/dbscan.jl b/test/dbscan.jl index e35195a4..07a89ce9 100644 --- a/test/dbscan.jl +++ b/test/dbscan.jl @@ -1,7 +1,6 @@ using Test using Clustering using Distances -include("test_helpers.jl") @testset "dbscan() (DBSCAN clustering)" begin @@ -14,6 +13,51 @@ include("test_helpers.jl") @test @inferred(dbscan(randn(2, 2), 0.5, metric=nothing, min_neighbors=1)) isa DbscanResult end +@testset "Simple 2D tests" begin + X = [10.0 0.0 10.5 + 0.0 10.0 0.1] + + @testset "n=3 samples" begin + X3 = X + + R = dbscan(X3, 20) + @test nclusters(R) == 1 + + R = dbscan(X3, 1.0) + @test nclusters(R) == 2 + + R = dbscan(X3, 0.1) + @test nclusters(R) == 3 + end + + @testset "n=2 samples" begin + X2 = X[:, 1:2] + + R = dbscan(X2, 20) + @test nclusters(R) == 1 + + R = dbscan(X2, 1.0) + @test nclusters(R) == 2 + end + + @testset "n=1 samples" begin + X1 = X[:, 1:1] + + R = dbscan(X1, 20) + @test nclusters(R) == 1 + + R = dbscan(X1, 1.0) + @test nclusters(R) == 1 + end + + @testset "n=0 samples" begin + X0 = X[:, 1:0] + + R = dbscan(X0, 20) + @test nclusters(R) == 0 + end +end + @testset "clustering synthetic data with 3 clusters" begin Random.seed!(34568) diff --git a/test/kmedoids.jl b/test/kmedoids.jl index a9f50d5f..4a649fc9 100644 --- a/test/kmedoids.jl +++ b/test/kmedoids.jl @@ -1,7 +1,6 @@ using Test using Distances using Clustering -include("test_helpers.jl") @testset "kmedoids() (k-medoids)" begin diff --git a/test/runtests.jl b/test/runtests.jl index 42301653..2e6a7894 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,6 +6,8 @@ using SparseArrays using StableRNGs using Statistics +include("test_helpers.jl") + tests = ["seeding", "kmeans", "kmedoids",