24#include <boost/test/unit_test.hpp>
29using namespace boost::unit_test_framework;
34BOOST_AUTO_TEST_SUITE(fillIncompleteMatrixTest)
37 BOOST_TEST_MESSAGE(
"Testing filling matrices with blank lines");
42 Matrix empty_row, empty_col;
43 empty_row = Matrix(5, 5, Real(22.5));
44 empty_col = Matrix(5, 5, Real(22.5));
46 for (
int i = 0; i < 5; i++) {
47 empty_row[2][i] = non_val;
48 empty_col[i][2] = non_val;
52 Matrix tmp_mat_r = empty_row;
53 Matrix tmp_mat_c = empty_col;
57 tmp_mat_r = empty_row;
58 tmp_mat_c = empty_col;
64 for (
int i = 0; i < 5; i++) {
65 BOOST_CHECK_CLOSE(tmp_mat_r[2][i], Real(22.5), tol);
66 BOOST_CHECK_CLOSE(tmp_mat_c[i][2], Real(22.5), tol);
71 BOOST_TEST_MESSAGE(
"Testing interpolation only");
85 incomplete_m = Matrix(5, 5, non_val);
86 for (
int i = 0; i < 5; i++) {
87 for (
int j = 0; j < 5; j++) {
88 if (i == 0 || j == 0 || i == 4 || j == 4) {
89 incomplete_m[i][j] = j + i + 1;
95 Matrix to_fill_row = incomplete_m;
96 Matrix to_fill_col = incomplete_m;
102 for (
int i = 0; i < 5; i++) {
103 for (
int j = 0; j < 5; j++) {
104 BOOST_CHECK_CLOSE(to_fill_row[i][j], j + i + 1, tol);
105 BOOST_CHECK_CLOSE(to_fill_col[i][j], j + i + 1, tol);
111 BOOST_TEST_MESSAGE(
"Testing extrapolation of edges in filling the matrix");
114 Matrix missing_rows, missing_cols;
115 vector<vector<Real> > test_cases;
116 for (
int i = 0; i < 4; i++) {
118 for (
int j = 0; j <= i; j++) {
121 test_cases.push_back(tmp);
136 vector<vector<Real> >::iterator cs;
137 for (cs = test_cases.begin(); cs != test_cases.end(); cs++) {
140 missing_rows = Matrix(5, 5, non_val);
141 missing_cols = Matrix(5, 5, non_val);
142 for (
int i = 0; i < 5; i++) {
143 for (
int j = 0; j < 5; j++) {
146 bool set_row = find(cs->begin(), cs->end(), i) == cs->end();
147 bool set_col = find(cs->begin(), cs->end(), j) == cs->end();
149 missing_rows[i][j] = j + i + 1;
152 missing_cols[i][j] = j + i + 1;
158 Matrix to_fill_rows = missing_rows;
159 Matrix to_fill_cols = missing_cols;
164 for (
int i = 0; i < 5; i++) {
165 for (
int j = 0; j < 5; j++) {
166 int last_val = cs->size();
167 Real expectedVal_row;
168 Real expectedVal_col;
170 expectedVal_col = missing_cols[i][last_val];
172 expectedVal_col = missing_cols[i][j];
175 expectedVal_row = missing_rows[last_val][j];
177 expectedVal_row = missing_rows[i][j];
179 bool check_row = to_fill_rows[i][j] == expectedVal_row;
180 bool check_col = to_fill_cols[i][j] == expectedVal_col;
182 if (!check_row || !check_col) {
183 BOOST_FAIL(
"FillIncomplete matrix failed on extrapolation only tests.");
191 BOOST_TEST_MESSAGE(
"Testing interpolation and extrapolation");
204 incomplete_m = Matrix(5, 5, non_val);
205 for (
int i = 0; i < 5; i++) {
206 incomplete_m[i][i] = i;
210 Matrix to_fill_rows = incomplete_m;
211 Matrix to_fill_cols = incomplete_m;
216 for (
int i = 0; i < 5; i++) {
217 for (
int j = 0; j < 5; j++) {
218 BOOST_CHECK_EQUAL(to_fill_rows[i][j], incomplete_m[i][i]);
219 BOOST_CHECK_EQUAL(to_fill_cols[i][j], incomplete_m[j][j]);
226 Matrix inc = Matrix(1, 1, 22.5);
227 Matrix tmp1 = inc, tmp2 = inc, tmp3 = inc, tmp4 = inc;
230 BOOST_TEST_MESSAGE(
"Testing single non-blank entry");
233 BOOST_CHECK_EQUAL(tmp1[0][0], inc[0][0]);
234 BOOST_CHECK_EQUAL(tmp2[0][0], inc[0][0]);
237 BOOST_TEST_MESSAGE(
"Testing single blank entry");
243 BOOST_TEST_MESSAGE(
"testing empty matrices");
251 BOOST_TEST_MESSAGE(
"tesing full matrices");
254 Matrix full_single = Matrix(1, 1, 22.5);
255 Matrix full = Matrix(5, 5, 22.5);
256 Matrix tmp_single_r = full_single;
257 Matrix tmp_single_c = full_single;
268 BOOST_CHECK_EQUAL(tmp_single_r[0][0], full_single[0][0]);
269 BOOST_CHECK_EQUAL(tmp_single_c[0][0], full_single[0][0]);
270 for (
int i = 0; i < 5; i++) {
271 for (
int j = 0; j < 5; j++) {
272 BOOST_CHECK_EQUAL(tmp_r[i][j], full[i][j]);
273 BOOST_CHECK_EQUAL(tmp_c[i][j], full[i][j]);
279 Matrix single_row = Matrix(1, 5, 22.5);
280 Matrix single_col = Matrix(5, 1, 22.5);
281 single_row[0][3] = -1;
282 single_col[3][0] = -1;
283 Matrix tmp_row = single_row;
284 Matrix tmp_col = single_col;
293BOOST_AUTO_TEST_SUITE_END()
295BOOST_AUTO_TEST_SUITE_END()
functions to fill a "not-completely-populated" matrix.
void fillIncompleteMatrix(Matrix &mat, bool interpRows=true, Real blank=QL_NULL_REAL)
function that fills a matrix
BOOST_AUTO_TEST_CASE(testBlankLineFill)
Fixture that can be used at top level.