Skip to content

Commit bfa1b09

Browse files
committed
Added more tests
1 parent 6afb877 commit bfa1b09

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

test/halfvec_test.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <span>
2+
#include <sstream>
23
#include <vector>
34

45
#include <pgvector/halfvec.hpp>
@@ -27,9 +28,17 @@ static void test_values() {
2728
assert_equal(vec.values() == std::vector<pgvector::Half>{1, 2, 3}, true);
2829
}
2930

31+
static void test_string() {
32+
HalfVector vec{{1, 2, 3}};
33+
std::ostringstream oss;
34+
oss << vec;
35+
assert_equal(oss.str(), "[1,2,3]");
36+
}
37+
3038
void test_halfvec() {
3139
test_constructor_vector();
3240
test_constructor_span();
3341
test_constructor_empty();
3442
test_values();
43+
test_string();
3544
}

test/sparsevec_test.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <span>
2+
#include <sstream>
23
#include <stdexcept>
34
#include <unordered_map>
45
#include <vector>
@@ -49,9 +50,17 @@ static void test_constructor_empty() {
4950
assert_equal(vec2.dimensions(), 0);
5051
}
5152

53+
static void test_string() {
54+
SparseVector vec{std::vector<float>{1, 0, 2, 0, 3, 0}};
55+
std::ostringstream oss;
56+
oss << vec;
57+
assert_equal(oss.str(), "{1:1,3:2,5:3}/6");
58+
}
59+
5260
void test_sparsevec() {
5361
test_constructor_vector();
5462
test_constructor_span();
5563
test_constructor_empty();
5664
test_constructor_map();
65+
test_string();
5766
}

test/vector_test.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <span>
2+
#include <sstream>
23
#include <vector>
34

45
#include <pgvector/vector.hpp>
@@ -27,9 +28,17 @@ static void test_values() {
2728
assert_equal(vec.values() == std::vector<float>{1, 2, 3}, true);
2829
}
2930

31+
static void test_string() {
32+
Vector vec{{1, 2, 3}};
33+
std::ostringstream oss;
34+
oss << vec;
35+
assert_equal(oss.str(), "[1,2,3]");
36+
}
37+
3038
void test_vector() {
3139
test_constructor_vector();
3240
test_constructor_span();
3341
test_constructor_empty();
3442
test_values();
43+
test_string();
3544
}

0 commit comments

Comments
 (0)