Skip to content

Commit 820646c

Browse files
committed
Improved tests
1 parent 98be8d4 commit 820646c

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

test/halfvec_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ using pgvector::HalfVector;
88

99
static void test_constructor_vector() {
1010
auto vec = HalfVector({1, 2, 3});
11-
assert_equal(vec.dimensions(), static_cast<size_t>(3));
11+
assert_equal(vec.dimensions(), 3u);
1212
}
1313

1414
static void test_constructor_span() {
1515
auto vec = HalfVector(std::span<const float>({1, 2, 3}));
16-
assert_equal(vec.dimensions(), static_cast<size_t>(3));
16+
assert_equal(vec.dimensions(), 3u);
1717
}
1818

1919
void test_halfvec() {

test/helper.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#include <sstream>
77
#include <string_view>
88

9-
template<typename T>
10-
void assert_equal(const T& left, const T& right, const std::source_location& loc = std::source_location::current()) {
9+
template<typename T, typename U>
10+
void assert_equal(const T& left, const U& right, const std::source_location& loc = std::source_location::current()) {
1111
if (left != right) {
1212
std::ostringstream message;
1313
message << left << " != " << right;

test/pqxx_test.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ void test_stream_to(pqxx::connection &conn) {
124124
stream.write_values(pgvector::Vector({4, 5, 6}));
125125
stream.complete();
126126
pqxx::result res = tx.exec("SELECT embedding FROM items ORDER BY id");
127-
assert_equal(res[0][0].as<std::string>(), std::string("[1,2,3]"));
128-
assert_equal(res[1][0].as<std::string>(), std::string("[4,5,6]"));
127+
assert_equal(res[0][0].as<std::string>(), "[1,2,3]");
128+
assert_equal(res[1][0].as<std::string>(), "[4,5,6]");
129129
}
130130

131131
void test_precision(pqxx::connection &conn) {
@@ -140,8 +140,8 @@ void test_precision(pqxx::connection &conn) {
140140
}
141141

142142
void test_vector_to_string() {
143-
assert_equal(pqxx::to_string(pgvector::Vector({1, 2, 3})), std::string("[1,2,3]"));
144-
assert_equal(pqxx::to_string(pgvector::Vector({-1.234567890123})), std::string("[-1.2345679]"));
143+
assert_equal(pqxx::to_string(pgvector::Vector({1, 2, 3})), "[1,2,3]");
144+
assert_equal(pqxx::to_string(pgvector::Vector({-1.234567890123})), "[-1.2345679]");
145145

146146
assert_exception<pqxx::conversion_overrun>([] {
147147
auto unused = pqxx::to_string(pgvector::Vector(std::vector<float>(16001)));
@@ -178,8 +178,8 @@ void test_vector_from_string() {
178178
}
179179

180180
void test_halfvec_to_string() {
181-
assert_equal(pqxx::to_string(pgvector::HalfVector({1, 2, 3})), std::string("[1,2,3]"));
182-
assert_equal(pqxx::to_string(pgvector::HalfVector({-1.234567890123})), std::string("[-1.2345679]"));
181+
assert_equal(pqxx::to_string(pgvector::HalfVector({1, 2, 3})), "[1,2,3]");
182+
assert_equal(pqxx::to_string(pgvector::HalfVector({-1.234567890123})), "[-1.2345679]");
183183

184184
assert_exception<pqxx::conversion_overrun>([] {
185185
auto unused = pqxx::to_string(pgvector::HalfVector(std::vector<float>(16001)));
@@ -216,9 +216,9 @@ void test_halfvec_from_string() {
216216
}
217217

218218
void test_sparsevec_to_string() {
219-
assert_equal(pqxx::to_string(pgvector::SparseVector({1, 0, 2, 0, 3, 0})), std::string("{1:1,3:2,5:3}/6"));
219+
assert_equal(pqxx::to_string(pgvector::SparseVector({1, 0, 2, 0, 3, 0})), "{1:1,3:2,5:3}/6");
220220
std::unordered_map<int, float> map = {{999999999, -1.234567890123}};
221-
assert_equal(pqxx::to_string(pgvector::SparseVector(map, 1000000000)), std::string("{1000000000:-1.2345679}/1000000000"));
221+
assert_equal(pqxx::to_string(pgvector::SparseVector(map, 1000000000)), "{1000000000:-1.2345679}/1000000000");
222222
}
223223

224224
void test_sparsevec_from_string() {

test/vector_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ using pgvector::Vector;
88

99
static void test_constructor_vector() {
1010
auto vec = Vector({1, 2, 3});
11-
assert_equal(vec.dimensions(), static_cast<size_t>(3));
11+
assert_equal(vec.dimensions(), 3u);
1212
}
1313

1414
static void test_constructor_span() {
1515
auto vec = Vector(std::span<const float>({1, 2, 3}));
16-
assert_equal(vec.dimensions(), static_cast<size_t>(3));
16+
assert_equal(vec.dimensions(), 3u);
1717
}
1818

1919
void test_vector() {

0 commit comments

Comments
 (0)