Skip to content

Commit

Permalink
Add some tests for computing Jaccard similarity.
Browse files Browse the repository at this point in the history
  • Loading branch information
kernelmethod committed Jan 16, 2020
1 parent 5cce8b2 commit 3ff9c2f
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions test/test_similarities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Tests
end
end

@testset "ℓ^p distance and norm" begin
@testset "ℓ^p distance and norm tests" begin
Random.seed!(RANDOM_SEED)

@testset "Compute ℓ^1 distance and norm" begin
Expand Down Expand Up @@ -111,7 +111,7 @@ end
end
end

@testset "Function space L^p distance and norm" begin
@testset "Function space L^p distance and norm tests" begin
Random.seed!(RANDOM_SEED)

@testset "Compute L^1 distance and norm" begin
Expand Down Expand Up @@ -175,7 +175,7 @@ end
end
end

@testset "Test cosine similarity" begin
@testset "Cosine similarity tests" begin
@testset "Compute cosine similarity between Vectors" begin
x = [1, 0, 1, 0]
y = [0, 1, 0, 1]
Expand Down Expand Up @@ -223,3 +223,38 @@ end
@test cossim(f, g, LSH.@interval(0 x 10)) cossim(f_steps, g_steps)
end
end

@testset "Jaccard similarity tests" begin

@testset "Compute Jaccard similarity with Int64 sets" begin
A = Set([1, 2, 3])
B = Set([2, 3, 4])

@test jaccard(A, A) == jaccard(B, B) == 1
@test jaccard(A, B) == jaccard(B, A) == 2 / 4

@test jaccard(A, Set()) == jaccard(B, Set()) == 0

@test jaccard(A, Set([2])) == jaccard(B, Set([2])) == 1 / 3
@test jaccard(A, Set([5])) == jaccard(B, Set([5])) == 0

# Convention used in this module
@test jaccard(Set(), Set()) == 0
end

@testset "Compute Jaccard similarity with String sets" begin
A = Set(["a", "b", "c"])
B = Set(["b", "c", "d"])

@test jaccard(A, A) == jaccard(B, B) == 1
@test jaccard(A, B) == jaccard(B, A) == 2 / 4

@test jaccard(A, Set()) == jaccard(B, Set()) == 0

@test jaccard(A, Set(["b"])) == jaccard(B, Set(["b"])) == 1 / 3
@test jaccard(A, Set(["e"])) == jaccard(B, Set(["e"])) == 0

# Convention used in this module
@test jaccard(Set(), Set()) == 0
end
end

0 comments on commit 3ff9c2f

Please sign in to comment.