Skip to content

Commit 61910ee

Browse files
committed
Added tests for vectors with zero dimensions [skip ci]
1 parent 7c946e1 commit 61910ee

4 files changed

Lines changed: 22 additions & 0 deletions

File tree

test/halfvec_test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ static void test_constructor_span() {
1616
assert_equal(vec.dimensions(), 3u);
1717
}
1818

19+
static void test_constructor_empty() {
20+
HalfVector vec{std::vector<pgvector::Half>{}};
21+
assert_equal(vec.dimensions(), 0u);
22+
}
23+
1924
static void test_values() {
2025
HalfVector vec{{1, 2, 3}};
2126
assert_equal(vec.values() == std::vector<pgvector::Half>{1, 2, 3}, true);
@@ -24,5 +29,6 @@ static void test_values() {
2429
void test_halfvec() {
2530
test_constructor_vector();
2631
test_constructor_span();
32+
test_constructor_empty();
2733
test_values();
2834
}

test/pqxx_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ void test_sparsevec_to_string() {
231231
void test_sparsevec_from_string() {
232232
assert_equal(pqxx::from_string<pgvector::SparseVector>("{1:1,3:2,5:3}/6"), pgvector::SparseVector{{1, 0, 2, 0, 3, 0}});
233233
assert_equal(pqxx::from_string<pgvector::SparseVector>("{}/6"), pgvector::SparseVector{{0, 0, 0, 0, 0, 0}});
234+
assert_equal(pqxx::from_string<pgvector::SparseVector>("{}/0"), pgvector::SparseVector{std::vector<float>{}});
234235

235236
assert_exception<pqxx::conversion_error>([] {
236237
auto _ = pqxx::from_string<pgvector::SparseVector>("");

test/sparsevec_test.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,17 @@ static void test_constructor_map() {
3535
}, "sparsevec index out of bounds");
3636
}
3737

38+
static void test_constructor_empty() {
39+
SparseVector vec{std::vector<float>{}};
40+
assert_equal(vec.dimensions(), 0);
41+
42+
SparseVector vec2{{}, 0};
43+
assert_equal(vec2.dimensions(), 0);
44+
}
45+
3846
void test_sparsevec() {
3947
test_constructor_vector();
4048
test_constructor_span();
49+
test_constructor_empty();
4150
test_constructor_map();
4251
}

test/vector_test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ static void test_constructor_span() {
1616
assert_equal(vec.dimensions(), 3u);
1717
}
1818

19+
static void test_constructor_empty() {
20+
Vector vec{std::vector<float>{}};
21+
assert_equal(vec.dimensions(), 0u);
22+
}
23+
1924
static void test_values() {
2025
Vector vec{{1, 2, 3}};
2126
assert_equal(vec.values() == std::vector<float>{1, 2, 3}, true);
@@ -24,5 +29,6 @@ static void test_values() {
2429
void test_vector() {
2530
test_constructor_vector();
2631
test_constructor_span();
32+
test_constructor_empty();
2733
test_values();
2834
}

0 commit comments

Comments
 (0)