Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
preciz committed Jul 20, 2024
1 parent 8fddd2e commit 23f927c
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/similarity/cosine_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,32 @@ defmodule Similarity.CosineTest do

assert Cosine.between(s, "barna", "somebody") |> Float.round(3) == 0.585
end

test "new" do
assert %Cosine{attributes_counter: 0, attributes_map: %{}, map: %{}} = Cosine.new()
end

test "add with empty attributes" do
s = Cosine.new()
s = Cosine.add(s, "empty", [])
assert %Cosine{attributes_counter: 0, attributes_map: %{}, map: %{"empty" => []}} = s
end

test "between with identical entries" do
s = Cosine.new()
s = Cosine.add(s, "a", [{"attr", 1}])
s = Cosine.add(s, "b", [{"attr", 1}])
assert Cosine.between(s, "a", "b") == 1.0
end

test "stream" do
s = Cosine.new()
s = Cosine.add(s, "a", [{"attr", 1}])
s = Cosine.add(s, "b", [{"attr", 2}])
s = Cosine.add(s, "c", [{"attr", 3}])

result = Cosine.stream(s) |> Enum.to_list()
assert length(result) == 3
assert Enum.all?(result, fn {_, _, similarity} -> is_float(similarity) end)
end
end

0 comments on commit 23f927c

Please sign in to comment.