Skip to content

Commit 451ffc8

Browse files
committed
Allow tests to be called from multiple directories; search for test
files.
1 parent 5442192 commit 451ffc8

File tree

3 files changed

+39
-18
lines changed

3 files changed

+39
-18
lines changed

test/gtest/coo_test.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
#include <gtest/gtest.h>
2-
3-
#include <fmt/core.h>
4-
1+
#include "util.hpp"
52
#include <binsparse/binsparse.hpp>
6-
7-
inline std::vector file_paths({"1138_bus/1138_bus.mtx",
8-
"chesapeake/chesapeake.mtx",
9-
"mouse_gene/mouse_gene.mtx"});
3+
#include <filesystem>
4+
#include <fmt/core.h>
5+
#include <gtest/gtest.h>
106

117
TEST(BinsparseReadWrite, COOFormat) {
128
using T = float;
139
using I = std::size_t;
1410

1511
std::string binsparse_file = "out.bsp.hdf5";
1612

17-
for (auto&& file_path : file_paths) {
13+
auto base_path = find_prefix(files.front());
14+
15+
for (auto&& file : files) {
16+
auto file_path = base_path + file;
1817
auto x = binsparse::__detail::mmread<
1918
T, I, binsparse::__detail::coo_matrix_owning<T, I>>(file_path);
2019

@@ -46,4 +45,6 @@ TEST(BinsparseReadWrite, COOFormat) {
4645
delete matrix_.rowind;
4746
delete matrix_.colind;
4847
}
48+
49+
std::filesystem::remove(binsparse_file);
4950
}

test/gtest/csr_test.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
#include <gtest/gtest.h>
2-
3-
#include <fmt/core.h>
4-
1+
#include "util.hpp"
52
#include <binsparse/binsparse.hpp>
6-
7-
inline std::vector file_paths({"1138_bus/1138_bus.mtx",
8-
"chesapeake/chesapeake.mtx",
9-
"mouse_gene/mouse_gene.mtx"});
3+
#include <filesystem>
4+
#include <fmt/core.h>
5+
#include <gtest/gtest.h>
106

117
TEST(BinsparseReadWrite, CSRFormat) {
128
using T = float;
139
using I = std::size_t;
1410

1511
std::string binsparse_file = "out.bsp.hdf5";
1612

17-
for (auto&& file_path : file_paths) {
13+
auto base_path = find_prefix(files.front());
14+
15+
for (auto&& file : files) {
16+
auto file_path = base_path + file;
1817
auto x = binsparse::__detail::mmread<
1918
T, I, binsparse::__detail::csr_matrix_owning<T, I>>(file_path);
2019

@@ -46,4 +45,6 @@ TEST(BinsparseReadWrite, CSRFormat) {
4645
delete matrix_.row_ptr;
4746
delete matrix_.colind;
4847
}
48+
49+
std::filesystem::remove(binsparse_file);
4950
}

test/gtest/util.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#pragma once
2+
3+
#include <filesystem>
4+
#include <string>
5+
#include <vector>
6+
7+
inline std::vector<std::string> files({"data/1138_bus/1138_bus.mtx",
8+
"data/chesapeake/chesapeake.mtx",
9+
"data/mouse_gene/mouse_gene.mtx"});
10+
11+
inline std::string find_prefix(std::string file_name) {
12+
if (std::filesystem::exists("../../" + file_name)) {
13+
return "../../";
14+
} else if (std::filesystem::exists("build/" + file_name)) {
15+
return "build/";
16+
} else {
17+
return "";
18+
}
19+
}

0 commit comments

Comments
 (0)