Skip to content

Commit 1c8ab4a

Browse files
authored
Add unit tests (#6)
1 parent a406637 commit 1c8ab4a

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

BUILD

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,12 @@ cc_binary(
3131
"@com_github_google_benchmark//:benchmark_main"],
3232
copts=COPTS
3333
)
34+
35+
cc_binary(
36+
name = "tests",
37+
srcs = ["tests.cc"],
38+
deps = [
39+
":soa",
40+
"@com_google_googletest//:gtest_main",
41+
],
42+
copts=COPTS)

WORKSPACE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,10 @@ http_archive(
66
name = "com_github_google_benchmark",
77
url = "https://github.com/google/benchmark/archive/refs/tags/v1.6.1.zip",
88
strip_prefix = "benchmark-1.6.1")
9+
10+
http_archive(
11+
name = "com_google_googletest",
12+
urls = ["https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip"],
13+
strip_prefix = "googletest-609281088cfefc76f9d0ce82e1ff6c30cc3591e5",
14+
sha256 = "5cf189eb6847b4f8fc603a3ffff3b0771c08eec7dd4bd961bfd45477dd13eb73"
15+
)

tests.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <gtest/gtest.h>
2+
#include <iostream>
3+
#include "vapid/soa.h"
4+
5+
template <typename T>
6+
bool is_sorted(const std::vector<T>& l) {
7+
for (size_t idx = 1; idx < l.size(); ++idx) {
8+
if (l[idx] < l[idx-1]) {
9+
return false;
10+
}
11+
}
12+
return true;
13+
}
14+
15+
TEST(SortA, Sorting) {
16+
vapid::soa<int, int> soa;
17+
soa.insert(0, 1);
18+
soa.insert(2, 5);
19+
soa.insert(4, 9);
20+
soa.insert(1, 0);
21+
soa.sort_by_field<0>();
22+
EXPECT_TRUE(is_sorted(soa.get_column<0>()));
23+
}

0 commit comments

Comments
 (0)