From f58345e1a25f3b3572aab14b0110168bd70fd984 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Mon, 8 Jul 2024 20:01:00 -0700 Subject: [PATCH] Added tests for encode and decode --- test/pgvector_test.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 test/pgvector_test.rb diff --git a/test/pgvector_test.rb b/test/pgvector_test.rb new file mode 100644 index 0000000..d45f6a6 --- /dev/null +++ b/test/pgvector_test.rb @@ -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