#include "gtest/gtest.h"
#include <vector>
#include <Eigen/Core>
TEST(IO, CSVRW1d) {
std::vector<double> v = {1, 2, 3, -3.41203498123234};
std::vector<double> vread =
CSV::read(
"test/testdata/v.csv");
EXPECT_EQ(v, vread);
}
TEST(IO, CSVRW2d) {
std::vector<std::vector<double>> M = {{1, 2},
{3, -3.4},
{-4.5, 4.5}};
EXPECT_EQ(M, Mread);
}
TEST(IO, CSVEigen1D) {
Eigen::VectorXd v(10);
v << 1, 3, 4, -2, 3, 5.6, 3.4, -2.3, 4, 5;
EXPECT_TRUE((v - vread).isZero(0));
}
TEST(IO, CSVEigen2D) {
Eigen::MatrixXd M(3, 2); M << 1, 2, 3, 4.3, 7.1, -2.3;
EXPECT_TRUE((M - Mread).isZero(0));
}
TEST(IO, CSVDeath) {
EXPECT_DEATH(
CSV::read2d(
"test/testdata/death1.csv"),
"Failed parsing .* to double");
"Not all rows in CSV file have the same number of elements");
EXPECT_DEATH(
CSV::read2d(
"test/testdata/death3.csv"),
"Error opening CSV file");
}
TEST(IO, CSVUsageExample) {
std::vector<double> v = {1, 2.5, -4.5, 12.34};
std::vector<double> v2 =
CSV::read(
"test/testdata/example.csv");
EXPECT_EQ(v, v2);
}
}