Skip to content

Commit 847c4ba

Browse files
committed
Improved tests
1 parent 7bda624 commit 847c4ba

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

test/pqxx_test.cpp

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ void test_vector(pqxx::connection &conn) {
3434
assert(res[0][0].as<pgvector::Vector>() == embedding2);
3535
assert(res[1][0].as<pgvector::Vector>() == embedding);
3636
assert(!res[2][0].as<std::optional<pgvector::Vector>>().has_value());
37-
38-
assert(pqxx::to_string(embedding) == "[1,2,3]");
39-
assert(pqxx::from_string<pgvector::Vector>("[1,2,3]") == embedding);
4037
}
4138

4239
void test_halfvec(pqxx::connection &conn) {
@@ -54,9 +51,6 @@ void test_halfvec(pqxx::connection &conn) {
5451
assert(res[0][0].as<pgvector::HalfVector>() == embedding2);
5552
assert(res[1][0].as<pgvector::HalfVector>() == embedding);
5653
assert(!res[2][0].as<std::optional<pgvector::HalfVector>>().has_value());
57-
58-
assert(pqxx::to_string(embedding) == "[1,2,3]");
59-
assert(pqxx::from_string<pgvector::HalfVector>("[1,2,3]") == embedding);
6054
}
6155

6256
void test_bit(pqxx::connection &conn) {
@@ -87,10 +81,6 @@ void test_sparsevec(pqxx::connection &conn) {
8781
assert(res[0][0].as<std::string>() == "{1:4,2:5,3:6}/3");
8882
assert(res[1][0].as<std::string>() == "{1:1,2:2,3:3}/3");
8983
assert(!res[2][0].as<std::optional<std::string>>().has_value());
90-
91-
assert(pqxx::to_string(embedding) == "{1:1,2:2,3:3}/3");
92-
// TODO add
93-
// assert(pqxx::from_string<pgvector::SparseVector>("{1:1,2:2,3:3}/3") == embedding);
9484
}
9585

9686
void test_sparsevec_nnz(pqxx::connection &conn) {
@@ -145,6 +135,30 @@ void test_precision(pqxx::connection &conn) {
145135
assert(res[0][0].as<pgvector::Vector>() == embedding);
146136
}
147137

138+
void test_vector_to_string() {
139+
assert(pqxx::to_string(pgvector::Vector({1, 2, 3})) == "[1,2,3]");
140+
}
141+
142+
void test_vector_from_string() {
143+
assert(pqxx::from_string<pgvector::Vector>("[1,2,3]") == pgvector::Vector({1, 2, 3}));
144+
}
145+
146+
void test_halfvec_to_string() {
147+
assert(pqxx::to_string(pgvector::HalfVector({1, 2, 3})) == "[1,2,3]");
148+
}
149+
150+
void test_halfvec_from_string() {
151+
assert(pqxx::from_string<pgvector::HalfVector>("[1,2,3]") == pgvector::HalfVector({1, 2, 3}));
152+
}
153+
154+
void test_sparsevec_to_string() {
155+
assert(pqxx::to_string(pgvector::SparseVector({1, 0, 2, 0, 3, 0})) == "{1:1,3:2,5:3}/6");
156+
}
157+
158+
void test_sparsevec_from_string() {
159+
// TODO add
160+
}
161+
148162
void test_pqxx() {
149163
pqxx::connection conn("dbname=pgvector_cpp_test");
150164
setup(conn);
@@ -157,4 +171,11 @@ void test_pqxx() {
157171
test_stream(conn);
158172
test_stream_to(conn);
159173
test_precision(conn);
174+
175+
test_vector_to_string();
176+
test_vector_from_string();
177+
test_halfvec_to_string();
178+
test_halfvec_from_string();
179+
test_sparsevec_to_string();
180+
test_sparsevec_from_string();
160181
}

0 commit comments

Comments
 (0)