File tree Expand file tree Collapse file tree 3 files changed +32
-16
lines changed
Expand file tree Collapse file tree 3 files changed +32
-16
lines changed Original file line number Diff line number Diff line change 1+ #pragma once
2+
3+ #include < cassert>
4+ #include < functional>
5+ #include < optional>
6+ #include < string_view>
7+
8+ template <typename T>
9+ void assert_exception (std::function<void (void )> code, std::optional<std::string_view> message = std::nullopt) {
10+ bool exception = false ;
11+ try {
12+ code ();
13+ } catch (const T& e) {
14+ exception = true ;
15+ if (message) {
16+ assert (std::string_view (e.what ()) == *message);
17+ }
18+ }
19+ assert (exception);
20+ }
Original file line number Diff line number Diff line change 11#include < cassert>
2- #include < functional>
32#include < optional>
43#include < string>
54#include < string_view>
65#include < vector>
76
87#include < pqxx/pqxx>
9-
108#include < pgvector/pqxx.hpp>
119
10+ #include " helper.hpp"
11+
1212void setup (pqxx::connection &conn) {
1313 pqxx::nontransaction tx (conn);
1414 tx.exec (" CREATE EXTENSION IF NOT EXISTS vector" );
@@ -21,20 +21,6 @@ void before_each(pqxx::connection &conn) {
2121 tx.exec (" TRUNCATE items" );
2222}
2323
24- template <typename T>
25- void assert_exception (std::function<void (void )> code, std::optional<std::string_view> message = std::nullopt) {
26- bool exception = false ;
27- try {
28- code ();
29- } catch (const T& e) {
30- exception = true ;
31- if (message) {
32- assert (std::string_view (e.what ()) == *message);
33- }
34- }
35- assert (exception);
36- }
37-
3824std::optional<std::string_view> float_error ([[maybe_unused]] std::string_view message) {
3925#ifdef __linux__
4026 return message;
Original file line number Diff line number Diff line change 44
55#include < pgvector/sparsevec.hpp>
66
7+ #include " helper.hpp"
8+
79using pgvector::SparseVector;
810
911static void test_constructor_vector () {
@@ -24,6 +26,14 @@ static void test_constructor_map() {
2426 assert (vec.dimensions () == 6 );
2527 assert (vec.indices () == (std::vector<int >{0 , 2 , 4 }));
2628 assert (vec.values () == (std::vector<float >{1 , 2 , 3 }));
29+
30+ assert_exception<std::invalid_argument>([&]{
31+ auto unused = SparseVector (map, 0 );
32+ }, " sparsevec must have at least 1 dimension" );
33+
34+ assert_exception<std::invalid_argument>([&]{
35+ auto unused = SparseVector (map, 4 );
36+ }, " sparsevec index out of bounds" );
2737}
2838
2939void test_sparsevec () {
You can’t perform that action at this time.
0 commit comments