-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsparsevec_test.cpp
More file actions
33 lines (27 loc) · 938 Bytes
/
sparsevec_test.cpp
File metadata and controls
33 lines (27 loc) · 938 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <cassert>
#include <span>
#include <unordered_map>
#include <pgvector/sparsevec.hpp>
using pgvector::SparseVector;
static void test_constructor_vector() {
auto vec = SparseVector({1, 0, 2, 0, 3, 0});
assert(vec.dimensions() == 6);
assert(vec.indices() == (std::vector<int>{0, 2, 4}));
assert(vec.values() == (std::vector<float>{1, 2, 3}));
}
static void test_constructor_span() {
auto vec = SparseVector(std::span<const float>({1, 0, 2, 0, 3, 0}));
assert(vec.dimensions() == 6);
}
static void test_constructor_map() {
std::unordered_map<int, float> map = {{2, 2}, {4, 3}, {3, 0}, {0, 1}};
auto vec = SparseVector(map, 6);
assert(vec.dimensions() == 6);
assert(vec.indices() == (std::vector<int>{0, 2, 4}));
assert(vec.values() == (std::vector<float>{1, 2, 3}));
}
void test_sparsevec() {
test_constructor_vector();
test_constructor_span();
test_constructor_map();
}