Skip to content

Commit 57afcf9

Browse files
committed
Improved assertions
1 parent 0a0bc40 commit 57afcf9

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

test/pqxx_test.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include "helper.hpp"
1010

11+
using namespace std::string_literals;
12+
1113
void setup(pqxx::connection &conn) {
1214
pqxx::nontransaction tx(conn);
1315
tx.exec("CREATE EXTENSION IF NOT EXISTS vector");
@@ -124,8 +126,8 @@ void test_stream_to(pqxx::connection &conn) {
124126
stream.write_values(pgvector::Vector({4, 5, 6}));
125127
stream.complete();
126128
pqxx::result res = tx.exec("SELECT embedding FROM items ORDER BY id");
127-
assert_true(res[0][0].as<std::string>() == "[1,2,3]");
128-
assert_true(res[1][0].as<std::string>() == "[4,5,6]");
129+
assert_equal(res[0][0].as<std::string>(), "[1,2,3]"s);
130+
assert_equal(res[1][0].as<std::string>(), "[4,5,6]"s);
129131
}
130132

131133
void test_precision(pqxx::connection &conn) {
@@ -140,8 +142,8 @@ void test_precision(pqxx::connection &conn) {
140142
}
141143

142144
void test_vector_to_string() {
143-
assert_true(pqxx::to_string(pgvector::Vector({1, 2, 3})) == "[1,2,3]");
144-
assert_true(pqxx::to_string(pgvector::Vector({-1.234567890123})) == "[-1.2345679]");
145+
assert_equal(pqxx::to_string(pgvector::Vector({1, 2, 3})), "[1,2,3]"s);
146+
assert_equal(pqxx::to_string(pgvector::Vector({-1.234567890123})), "[-1.2345679]"s);
145147

146148
assert_exception<pqxx::conversion_overrun>([] {
147149
auto unused = pqxx::to_string(pgvector::Vector(std::vector<float>(16001)));
@@ -178,8 +180,8 @@ void test_vector_from_string() {
178180
}
179181

180182
void test_halfvec_to_string() {
181-
assert_true(pqxx::to_string(pgvector::HalfVector({1, 2, 3})) == "[1,2,3]");
182-
assert_true(pqxx::to_string(pgvector::HalfVector({-1.234567890123})) == "[-1.2345679]");
183+
assert_equal(pqxx::to_string(pgvector::HalfVector({1, 2, 3})), "[1,2,3]"s);
184+
assert_equal(pqxx::to_string(pgvector::HalfVector({-1.234567890123})), "[-1.2345679]"s);
183185

184186
assert_exception<pqxx::conversion_overrun>([] {
185187
auto unused = pqxx::to_string(pgvector::HalfVector(std::vector<float>(16001)));
@@ -216,9 +218,9 @@ void test_halfvec_from_string() {
216218
}
217219

218220
void test_sparsevec_to_string() {
219-
assert_true(pqxx::to_string(pgvector::SparseVector({1, 0, 2, 0, 3, 0})) == "{1:1,3:2,5:3}/6");
221+
assert_equal(pqxx::to_string(pgvector::SparseVector({1, 0, 2, 0, 3, 0})), "{1:1,3:2,5:3}/6"s);
220222
std::unordered_map<int, float> map = {{999999999, -1.234567890123}};
221-
assert_true(pqxx::to_string(pgvector::SparseVector(map, 1000000000)) == "{1000000000:-1.2345679}/1000000000");
223+
assert_equal(pqxx::to_string(pgvector::SparseVector(map, 1000000000)), "{1000000000:-1.2345679}/1000000000"s);
222224
}
223225

224226
void test_sparsevec_from_string() {

0 commit comments

Comments
 (0)