|
1 | | -#include <cassert> |
2 | | -#include <unordered_map> |
3 | | - |
4 | | -#include "../include/pgvector/halfvec.hpp" |
5 | | -#include "../include/pgvector/sparsevec.hpp" |
6 | | -#include "../include/pgvector/vector.hpp" |
7 | | - |
8 | | -#if __cplusplus >= 202002L |
9 | | -#include <span> |
10 | | -#endif |
11 | | - |
12 | | -using pgvector::HalfVector; |
13 | | -using pgvector::SparseVector; |
14 | | -using pgvector::Vector; |
15 | | - |
| 1 | +void test_vector(); |
| 2 | +void test_halfvec(); |
| 3 | +void test_sparsevec(); |
16 | 4 | void test_pqxx(); |
17 | 5 |
|
18 | | -void test_vector() { |
19 | | - auto vec = Vector({1, 2, 3}); |
20 | | - assert(vec.dimensions() == 3); |
21 | | -} |
22 | | - |
23 | | -#if __cplusplus >= 202002L |
24 | | -void test_vector_span() { |
25 | | - auto vec = Vector(std::span<const float>({1, 2, 3})); |
26 | | - assert(vec.dimensions() == 3); |
27 | | -} |
28 | | -#endif |
29 | | - |
30 | | -void test_halfvec() { |
31 | | - auto vec = HalfVector({1, 2, 3}); |
32 | | - assert(vec.dimensions() == 3); |
33 | | -} |
34 | | - |
35 | | -#if __cplusplus >= 202002L |
36 | | -void test_halfvec_span() { |
37 | | - auto vec = HalfVector(std::span<const float>({1, 2, 3})); |
38 | | - assert(vec.dimensions() == 3); |
39 | | -} |
40 | | -#endif |
41 | | - |
42 | | -void test_sparsevec() { |
43 | | - auto vec = SparseVector({1, 0, 2, 0, 3, 0}); |
44 | | - assert(vec.dimensions() == 6); |
45 | | - assert(vec.indices() == (std::vector<int>{0, 2, 4})); |
46 | | - assert(vec.values() == (std::vector<float>{1, 2, 3})); |
47 | | -} |
48 | | - |
49 | | -#if __cplusplus >= 202002L |
50 | | -void test_sparsevec_span() { |
51 | | - auto vec = SparseVector(std::span<const float>({1, 0, 2, 0, 3, 0})); |
52 | | - assert(vec.dimensions() == 6); |
53 | | -} |
54 | | -#endif |
55 | | - |
56 | | -void test_sparsevec_map() { |
57 | | - std::unordered_map<int, float> map = {{2, 2}, {4, 3}, {3, 0}, {0, 1}}; |
58 | | - auto vec = SparseVector(map, 6); |
59 | | - assert(vec.dimensions() == 6); |
60 | | - assert(vec.indices() == (std::vector<int>{0, 2, 4})); |
61 | | - assert(vec.values() == (std::vector<float>{1, 2, 3})); |
62 | | -} |
63 | | - |
64 | 6 | int main() { |
65 | | - test_pqxx(); |
66 | 7 | test_vector(); |
67 | | -#if __cplusplus >= 202002L |
68 | | - test_vector_span(); |
69 | | -#endif |
70 | 8 | test_halfvec(); |
71 | | -#if __cplusplus >= 202002L |
72 | | - test_halfvec_span(); |
73 | | -#endif |
74 | 9 | test_sparsevec(); |
75 | | -#if __cplusplus >= 202002L |
76 | | - test_sparsevec_span(); |
77 | | -#endif |
| 10 | + test_pqxx(); |
78 | 11 | return 0; |
79 | 12 | } |
0 commit comments