Skip to content

Commit 9e19377

Browse files
committed
Added more tests
1 parent 1774011 commit 9e19377

File tree

5 files changed

+47
-14
lines changed

5 files changed

+47
-14
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ jobs:
2222
make
2323
sudo make install
2424
25-
- run: g++ -std=c++17 -Wall -Wextra -Werror -o test/pqxx test/pqxx_test.cpp -lpqxx -lpq
26-
- run: test/pqxx
25+
- run: g++ -std=c++17 -Wall -Wextra -Werror -o test/main test/main.cpp test/pqxx_test.cpp -lpqxx -lpq
26+
- run: test/main
2727

28-
- run: g++ -std=c++20 -Wall -Wextra -Werror -o test/pqxx test/pqxx_test.cpp -lpqxx -lpq
29-
- run: test/pqxx
28+
- run: g++ -std=c++20 -Wall -Wextra -Werror -o test/main test/main.cpp test/pqxx_test.cpp -lpqxx -lpq
29+
- run: test/main
3030

31-
- run: g++ -std=c++23 -Wall -Wextra -Werror -o test/pqxx test/pqxx_test.cpp -lpqxx -lpq
32-
- run: test/pqxx
31+
- run: g++ -std=c++23 -Wall -Wextra -Werror -o test/main test/main.cpp test/pqxx_test.cpp -lpqxx -lpq
32+
- run: test/main
3333

3434
- run: |
3535
sudo apt-get install valgrind
36-
valgrind --leak-check=yes test/pqxx
36+
valgrind --leak-check=yes test/main
3737
3838
# test install
3939
- run: cmake -S . -B build

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
build
2-
/test/pqxx
2+
/test/main

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ To get started with development:
107107
git clone https://github.com/pgvector/pgvector-cpp.git
108108
cd pgvector-cpp
109109
createdb pgvector_cpp_test
110-
g++ -std=c++17 -Wall -Wextra -Wno-unknown-attributes -Werror -o test/pqxx test/pqxx_test.cpp -lpqxx -lpq
111-
test/pqxx
110+
g++ -std=c++17 -Wall -Wextra -Wno-unknown-attributes -Werror -o test/main test/main.cpp test/pqxx_test.cpp -lpqxx -lpq
111+
test/main
112112
```
113113

114114
To run an example:

test/main.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <cassert>
2+
3+
#include "../include/pgvector/halfvec.hpp"
4+
#include "../include/pgvector/sparsevec.hpp"
5+
#include "../include/pgvector/vector.hpp"
6+
7+
using pgvector::HalfVector;
8+
using pgvector::SparseVector;
9+
using pgvector::Vector;
10+
11+
void test_pqxx();
12+
13+
void test_vector() {
14+
auto vec = Vector({1, 2, 3});
15+
assert(vec.dimensions() == 3);
16+
}
17+
18+
void test_halfvec() {
19+
auto vec = HalfVector({1, 2, 3});
20+
assert(vec.dimensions() == 3);
21+
}
22+
23+
void test_sparsevec() {
24+
auto vec = SparseVector({1, 2, 3});
25+
assert(vec.dimensions() == 3);
26+
}
27+
28+
int main() {
29+
test_pqxx();
30+
test_vector();
31+
test_halfvec();
32+
test_sparsevec();
33+
return 0;
34+
}

test/pqxx_test.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
#include "../include/pgvector/pqxx.hpp"
21
#include <cassert>
32
#include <optional>
43
#include <pqxx/pqxx>
54

5+
#include "../include/pgvector/pqxx.hpp"
6+
67
void setup(pqxx::connection &conn) {
78
pqxx::nontransaction tx(conn);
89
tx.exec("CREATE EXTENSION IF NOT EXISTS vector");
@@ -131,7 +132,7 @@ void test_precision(pqxx::connection &conn) {
131132
assert(res[0][0].as<pgvector::Vector>() == embedding);
132133
}
133134

134-
int main() {
135+
void test_pqxx() {
135136
pqxx::connection conn("dbname=pgvector_cpp_test");
136137
setup(conn);
137138

@@ -143,6 +144,4 @@ int main() {
143144
test_stream(conn);
144145
test_stream_to(conn);
145146
test_precision(conn);
146-
147-
return 0;
148147
}

0 commit comments

Comments
 (0)