diff --git a/test/similarity/cosine_test.exs b/test/similarity/cosine_test.exs index 5496bbf..cdefe29 100644 --- a/test/similarity/cosine_test.exs +++ b/test/similarity/cosine_test.exs @@ -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