OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
CSVReader_unit_test.cpp
1//
2// Created by jstark on 28.12.21.
3//
4#define BOOST_TEST_DYN_LINK
5#include <boost/test/unit_test.hpp>
6#include "CSVReader/CSVReader.hpp"
7
8BOOST_AUTO_TEST_SUITE(CSVReaderTestSuite)
9BOOST_AUTO_TEST_CASE(csv_reader_int_test)
10 {
11#ifdef OPENFPM_PDATA
12 std::string csv_file = std::string("openfpm_io/test_data/integer.csv");
13#else
14 std::string csv_file = std::string("test_data/integer.csv");
15#endif
16 // Read csv file into vector while linearizing
17 openfpm::vector<int> v_lin; // Vector to which csv file will be read to
18 size_t m, n; // Number of rows m and columns n
19
20 read_csv_to_vector(csv_file, v_lin, m, n);
21
22 BOOST_CHECK(m == 4);
23 BOOST_CHECK(n == 3);
24 BOOST_CHECK(m * n == v_lin.size());
25
26 for(int i = 0; i < v_lin.size() / n; ++i)
27 {
28 BOOST_CHECK( v_lin.get(i * n) == i + 1);
29 BOOST_CHECK( v_lin.get(i * n + 1) == (i + 1) * 2);
30 BOOST_CHECK( v_lin.get(i * n + 2) == v_lin.get(i * n) * v_lin.get(i * n + 1));
31 }
32 }
33
34
35BOOST_AUTO_TEST_CASE(csv_reader_char_test)
36 {
37#ifdef OPENFPM_PDATA
38 std::string csv_file = std::string("openfpm_io/test_data/char.csv");
39#else
40 std::string csv_file = std::string("test_data/char.csv");
41#endif
42 // Read csv file into vector while linearizing
43 openfpm::vector<std::string> v_lin; // Vector to which csv file will be read to
44 size_t m, n; // Number of rows m and columns n
45
46 read_csv_to_vector(csv_file, v_lin, m, n);
47
48 BOOST_CHECK(m == 5);
49 BOOST_CHECK(n == 2);
50 BOOST_CHECK(m * n == v_lin.size());
51
52 openfpm::vector<std::string> col1 = {"a", "b", "c", "d", "e"};
53 openfpm::vector<std::string> col2 = {"antilope", "ballena", "camel", "dackel", "elefant"};
54
55 for(int i = 0; i < v_lin.size() / n; ++i)
56 {
57 BOOST_CHECK(col1.get(i) == v_lin.get(i * n));
58 BOOST_CHECK(col2.get(i) == v_lin.get(i * n + 1));
59 }
60
61 }
62BOOST_AUTO_TEST_SUITE_END()
Implementation of 1-D std::vector like structure.
size_t size()
Stub size.