@@ -34,9 +34,6 @@ void test_vector(pqxx::connection &conn) {
34
34
assert (res[0 ][0 ].as <pgvector::Vector>() == embedding2);
35
35
assert (res[1 ][0 ].as <pgvector::Vector>() == embedding);
36
36
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);
40
37
}
41
38
42
39
void test_halfvec (pqxx::connection &conn) {
@@ -54,9 +51,6 @@ void test_halfvec(pqxx::connection &conn) {
54
51
assert (res[0 ][0 ].as <pgvector::HalfVector>() == embedding2);
55
52
assert (res[1 ][0 ].as <pgvector::HalfVector>() == embedding);
56
53
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);
60
54
}
61
55
62
56
void test_bit (pqxx::connection &conn) {
@@ -87,10 +81,6 @@ void test_sparsevec(pqxx::connection &conn) {
87
81
assert (res[0 ][0 ].as <std::string>() == " {1:4,2:5,3:6}/3" );
88
82
assert (res[1 ][0 ].as <std::string>() == " {1:1,2:2,3:3}/3" );
89
83
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);
94
84
}
95
85
96
86
void test_sparsevec_nnz (pqxx::connection &conn) {
@@ -145,6 +135,30 @@ void test_precision(pqxx::connection &conn) {
145
135
assert (res[0 ][0 ].as <pgvector::Vector>() == embedding);
146
136
}
147
137
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
+
148
162
void test_pqxx () {
149
163
pqxx::connection conn (" dbname=pgvector_cpp_test" );
150
164
setup (conn);
@@ -157,4 +171,11 @@ void test_pqxx() {
157
171
test_stream (conn);
158
172
test_stream_to (conn);
159
173
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 ();
160
181
}
0 commit comments