Skip to content

Commit

Permalink
Improved SparseVector tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Jun 20, 2024
1 parent 76a0a70 commit 34a4d71
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions test/sparse_vector_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ defmodule SparseVectorTest do
use ExUnit.Case

test "sparse vector" do
vector = Pgvector.SparseVector.new([1, 2, 3])
vector = Pgvector.SparseVector.new([1, 0, 2, 0, 3, 0])
assert vector == vector |> Pgvector.SparseVector.new()
end

test "list" do
list = [1.0, 2.0, 3.0]
list = [1.0, 0.0, 2.0, 0.0, 3.0, 0.0]
assert list == list |> Pgvector.SparseVector.new() |> Pgvector.to_list()
end

test "tensor" do
tensor = Nx.tensor([1.0, 2.0, 3.0], type: :f32)
tensor = Nx.tensor([1.0, 0.0, 2.0, 0.0, 3.0, 0.0], type: :f32)
assert tensor == tensor |> Pgvector.SparseVector.new() |> Pgvector.to_tensor()
end

Expand All @@ -22,23 +22,23 @@ defmodule SparseVectorTest do
end

test "dimensions" do
vector = Pgvector.SparseVector.new([1, 2, 3])
assert 3 == vector |> Pgvector.SparseVector.dimensions()
vector = Pgvector.SparseVector.new([1, 0, 2, 0, 3, 0])
assert 6 == vector |> Pgvector.SparseVector.dimensions()
end

test "indices" do
vector = Pgvector.SparseVector.new([1, 2, 3])
assert [0, 1, 2] == vector |> Pgvector.SparseVector.indices()
vector = Pgvector.SparseVector.new([1, 0, 2, 0, 3, 0])
assert [0, 2, 4] == vector |> Pgvector.SparseVector.indices()
end

test "values" do
vector = Pgvector.SparseVector.new([1, 2, 3])
vector = Pgvector.SparseVector.new([1, 0, 2, 0, 3, 0])
assert [1, 2, 3] == vector |> Pgvector.SparseVector.values()
end

test "inspect" do
vector = Pgvector.SparseVector.new([1, 2, 3])
assert "Pgvector.SparseVector.new(%{0 => 1.0, 1 => 2.0, 2 => 3.0}, 3)" == inspect(vector)
vector = Pgvector.SparseVector.new([1, 0, 2, 0, 3, 0])
assert "Pgvector.SparseVector.new(%{0 => 1.0, 2 => 2.0, 4 => 3.0}, 6)" == inspect(vector)
end

test "equals" do
Expand Down

0 comments on commit 34a4d71

Please sign in to comment.