Skip to content

Commit

Permalink
Added tests for encode and decode
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Jul 9, 2024
1 parent b454296 commit f58345e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/pgvector_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require_relative "test_helper"

class PgvectorTest < Minitest::Test
def test_encode_array
assert_equal "[1.0,2.0,3.0]", Pgvector.encode([1, 2, 3])
end

def test_encode_vector
assert_equal "[1.0,2.0,3.0]", Pgvector.encode(Pgvector::Vector.new([1, 2, 3]))
end

def test_encode_half_vector
assert_equal "[1.0,2.0,3.0]", Pgvector.encode(Pgvector::HalfVector.new([1, 2, 3]))
end

def test_encode_sparse_vector
assert_equal "{1:1.0,2:2.0,3:3.0}/3", Pgvector.encode(Pgvector::SparseVector.new([1, 2, 3]))
end

def test_decode_vector
assert_equal [1, 2, 3], Pgvector.decode("[1,2,3]")
end

def test_decode_sparse_vector
assert_equal [1, 2, 3], Pgvector.decode("{1:1.0,2:2.0,3:3.0}/3").to_a
end
end

0 comments on commit f58345e

Please # to comment.