From 9f2ec39a99aef8aafc463f26774bb141f5b7d65b Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Fri, 12 Dec 2014 23:49:23 +0100 Subject: [PATCH] Add a simple test of matrix transposes --- unittest/UnitTest.cpp | 25 +++++++++++++++++++++++++ unittest/UnitTest.h | 1 + 2 files changed, 26 insertions(+) diff --git a/unittest/UnitTest.cpp b/unittest/UnitTest.cpp index 02cf4209e..fd898d8b1 100644 --- a/unittest/UnitTest.cpp +++ b/unittest/UnitTest.cpp @@ -287,12 +287,36 @@ bool TestVFPUSinCos() { return true; } +bool TestMatrixTranspose() { + MatrixSize sz = M_4x4; + int matrix = 0; // M000 + u8 cols[4]; + u8 rows[4]; + + GetMatrixColumns(matrix, sz, cols); + GetMatrixRows(matrix, sz, rows); + + int transposed = Xpose(matrix); + u8 x_cols[4]; + u8 x_rows[4]; + + GetMatrixColumns(transposed, sz, x_cols); + GetMatrixRows(transposed, sz, x_rows); + + for (int i = 0; i < GetMatrixSide(sz); i++) { + EXPECT_EQ_INT(cols[i], x_rows[i]); + EXPECT_EQ_INT(x_cols[i], rows[i]); + } + return true; +} + void TestGetMatrix(int matrix, MatrixSize sz) { ILOG("Testing matrix %s", GetMatrixNotation(matrix, sz)); u8 fullMatrix[16]; u8 cols[4]; u8 rows[4]; + GetMatrixColumns(matrix, sz, cols); GetMatrixRows(matrix, sz, rows); @@ -358,6 +382,7 @@ TestItem availableTests[] = { TEST_ITEM(MathUtil), TEST_ITEM(Parsers), TEST_ITEM(Jit), + TEST_ITEM(MatrixTranspose) }; int main(int argc, const char *argv[]) { diff --git a/unittest/UnitTest.h b/unittest/UnitTest.h index 8b7c47cf7..2cb26cadd 100644 --- a/unittest/UnitTest.h +++ b/unittest/UnitTest.h @@ -2,6 +2,7 @@ #define EXPECT_TRUE(a) if (!(a)) { printf("%s:%i: Test Fail\n", __FUNCTION__, __LINE__); return false; } #define EXPECT_FALSE(a) if ((a)) { printf("%s:%i: Test Fail\n", __FUNCTION__, __LINE__); return false; } +#define EXPECT_EQ_INT(a, b) if ((a) != (b)) { printf("%s:%i: Test Fail\n%d\nvs\n%d\n", __FUNCTION__, __LINE__, a, b); return false; } #define EXPECT_EQ_FLOAT(a, b) if ((a) != (b)) { printf("%s:%i: Test Fail\n%f\nvs\n%f\n", __FUNCTION__, __LINE__, a, b); return false; } #define EXPECT_APPROX_EQ_FLOAT(a, b) if (fabsf((a)-(b))>0.00001f) { printf("%s:%i: Test Fail\n%f\nvs\n%f\n", __FUNCTION__, __LINE__, a, b); /*return false;*/ } #define EXPECT_EQ_STR(a, b) if (a != b) { printf("%s: Test Fail\n%s\nvs\n%s\n", __FUNCTION__, a.c_str(), b.c_str()); return false; }