test zero divisions

This commit is contained in:
Bart Slinger
2018-09-12 21:06:17 +02:00
committed by Beat Küng
parent 3f2d3cf58d
commit 7495794386
+22
View File
@@ -5,6 +5,7 @@ using namespace matrix;
int test_4x3(void);
int test_4x4(void);
int test_div_zero(void);
int main()
{
@@ -16,6 +17,9 @@ int main()
ret = test_4x3();
if (ret != 0) return ret;
ret = test_div_zero();
if (ret != 0) return ret;
return 0;
}
@@ -70,4 +74,22 @@ int test_4x4() {
return 0;
}
int test_div_zero() {
float data[4] = {0.0f, 0.0f, 0.0f, 0.0f};
Matrix<float, 2, 2> A(data);
float b_data[2] = {1.0, 1.0};
Vector<float, 2> b(b_data);
// Implement such that x returns zeros if it reaches div by zero
float x_check_data[2] = {0.0f, 0.0f};
Vector<float, 2> x_check(x_check_data);
LeastSquaresSolver<float, 2, 2> qrd = LeastSquaresSolver<float, 2, 2>(A);
Vector<float, 2> x = qrd.solve(b);
TEST(isEqual(x, x_check));
return 0;
}
/* vim: set et fenc=utf-8 ff=unix sts=0 sw=4 ts=4 : */