Mercurial > hg > aimc
diff carfac/test_util.h @ 661:7a0031c321da
Better SAI unit tests.
Includes a test to compare the output of the Matlab and C++ version which is currently disabled since the outputs are not identical.
author | ronw@google.com |
---|---|
date | Mon, 01 Jul 2013 19:02:37 +0000 |
parents | 499ffd3a50ba |
children |
line wrap: on
line diff
--- a/carfac/test_util.h Mon Jul 01 19:02:32 2013 +0000 +++ b/carfac/test_util.h Mon Jul 01 19:02:37 2013 +0000 @@ -28,6 +28,8 @@ #include <Eigen/Core> +#include "gtest/gtest.h" + #include "common.h" // Location of the text files produced by 'CARFAC_GenerateTestData.m' for @@ -62,9 +64,27 @@ return output; } -bool ArraysNear(const ArrayX& expected, const ArrayX& actual, - double precision) { - return (expected - actual).cwiseAbs().maxCoeff() <= precision; +void WriteMatrix(const std::string& filename, const ArrayXX& matrix) { + std::string fullfile = kTestDataDir + filename; + std::ofstream ofile(fullfile.c_str()); + const int kPrecision = 9; + ofile.precision(kPrecision); + if (ofile.is_open()) { + Eigen::IOFormat ioformat(kPrecision, Eigen::DontAlignCols); + ofile << matrix.format(ioformat) << std::endl; + } + ofile.close(); +} + +void AssertArrayNear(const ArrayX& expected, const ArrayX& actual, + double precision) { + ArrayX abs_difference = (expected - actual).cwiseAbs(); + ASSERT_TRUE(abs_difference.maxCoeff() <= precision) + << "expected differs from actual by more than " << precision + << "\n max(abs(expected - actual)) = " << abs_difference.maxCoeff() + << "\n max(abs(expected)) = " << expected.cwiseAbs().maxCoeff() + << "\n max(abs(actual)) = " << actual.cwiseAbs().maxCoeff() + << "\n" << abs_difference; } #endif // CARFAC_TEST_UTIL_H