1 #define BOOST_TEST_MODULE TestSkylineLU
2 #include <boost/test/unit_test.hpp>
3
4 #include <amgcl/io/mm.hpp>
5 #include <amgcl/adapter/crs_tuple.hpp>
6 #include <amgcl/profiler.hpp>
7 #include "sample_problem.hpp"
8
9 namespace amgcl {
10 profiler<> prof;
11 }
12
13 BOOST_AUTO_TEST_SUITE( test_io )
14
BOOST_AUTO_TEST_CASE(io_mm)15 BOOST_AUTO_TEST_CASE(io_mm)
16 {
17 std::vector<ptrdiff_t> ptr, ptr2;
18 std::vector<ptrdiff_t> col, col2;
19 std::vector<double> val, val2;
20 std::vector<double> rhs, rhs2;
21
22 size_t n = sample_problem(16, val, col, ptr, rhs);
23
24 auto A = std::tie(n, ptr, col, val);
25
26 amgcl::io::mm_write("test_io_crs.mm", A);
27 amgcl::io::mm_write("test_io_vec.mm", rhs.data(), n, 1);
28
29 size_t rows, cols;
30 std::tie(rows, cols) = amgcl::io::mm_reader("test_io_crs.mm")(ptr2, col2, val2);
31
32 BOOST_REQUIRE_EQUAL(n, rows);
33 BOOST_REQUIRE_EQUAL(n, cols);
34 BOOST_REQUIRE_EQUAL(ptr.back(), ptr2.back());
35 for(size_t i = 0; i < n; ++i) {
36 BOOST_REQUIRE_EQUAL(ptr[i], ptr2[i]);
37 for(ptrdiff_t j = ptr[i], e = ptr[i+1]; j < e; ++j) {
38 BOOST_CHECK_EQUAL(col[j], col2[j]);
39 BOOST_CHECK_SMALL(val[j] - val2[j], 1e-12);
40 }
41 }
42
43 std::tie(rows, cols) = amgcl::io::mm_reader("test_io_vec.mm")(rhs2);
44 BOOST_REQUIRE_EQUAL(n, rows);
45 BOOST_REQUIRE_EQUAL(1, cols);
46 for(size_t i = 0; i < n; ++i) {
47 BOOST_CHECK_SMALL(rhs[i] - rhs2[i], 1e-12);
48 }
49 }
50
51 BOOST_AUTO_TEST_SUITE_END()
52
53