Browse Source

Adding some tests for the matrix_helpers.hpp file.

Sam Jaffe 7 years ago
parent
commit
ae5441a420
3 changed files with 42 additions and 0 deletions
  1. 4 0
      matrix.xcodeproj/project.pbxproj
  2. 5 0
      matrix_dummy.cpp
  3. 33 0
      matrix_helper_test.cpp

+ 4 - 0
matrix.xcodeproj/project.pbxproj

@@ -13,6 +13,7 @@
 		CD0C59D620C412AD00454F82 /* libmatrix.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = CD0C59B520C4123700454F82 /* libmatrix.dylib */; };
 		CD0C59DE20C412C400454F82 /* GoogleMock.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD0C59C520C4127400454F82 /* GoogleMock.framework */; };
 		CD0C59DF20C412C800454F82 /* matrix_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD0C59CC20C4128F00454F82 /* matrix_test.cpp */; };
+		CD0C59E120C4314B00454F82 /* matrix_helper_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD0C59E020C4314B00454F82 /* matrix_helper_test.cpp */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
@@ -67,6 +68,7 @@
 		CD0C59CC20C4128F00454F82 /* matrix_test.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = matrix_test.cpp; sourceTree = "<group>"; };
 		CD0C59D120C412AD00454F82 /* matrix_test.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = matrix_test.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
 		CD0C59D520C412AD00454F82 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = matrix_test/Info.plist; sourceTree = "<group>"; };
+		CD0C59E020C4314B00454F82 /* matrix_helper_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = matrix_helper_test.cpp; sourceTree = "<group>"; };
 		CD0E428D1D9B3955002FFED1 /* matrix.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = matrix.hpp; sourceTree = "<group>"; };
 		CD0E428E1D9B3955002FFED1 /* matrix_helpers.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = matrix_helpers.hpp; sourceTree = "<group>"; };
 /* End PBXFileReference section */
@@ -136,6 +138,7 @@
 			children = (
 				CD0C59D520C412AD00454F82 /* Info.plist */,
 				CD0C59CC20C4128F00454F82 /* matrix_test.cpp */,
+				CD0C59E020C4314B00454F82 /* matrix_helper_test.cpp */,
 			);
 			name = test;
 			sourceTree = "<group>";
@@ -286,6 +289,7 @@
 			isa = PBXSourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				CD0C59E120C4314B00454F82 /* matrix_helper_test.cpp in Sources */,
 				CD0C59DF20C412C800454F82 /* matrix_test.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;

+ 5 - 0
matrix_dummy.cpp

@@ -6,8 +6,13 @@
 //
 
 #include "matrix.hpp"
+#include "matrix_helpers.hpp"
 
 namespace math { namespace matrix {
   template class matrix<int, 2, 2>;
   template class row_reference<int, 2>;
+  template matrix<double, 4, 4> identity();
+  template matrix<double, 4, 4> diagonal(vector::vector<double, 4> const &);
+  template matrix<double, 4, 4> translation(vector::vector<double, 3> const &);
+  template matrix<double, 4, 4> scalar(vector::vector<double, 3> const &);
 } }

+ 33 - 0
matrix_helper_test.cpp

@@ -0,0 +1,33 @@
+//
+//  matrix_helper_test.cpp
+//  matrix
+//
+//  Created by Sam Jaffe on 6/3/18.
+//
+
+#include <gmock/gmock.h>
+
+#include "matrix_helpers.hpp"
+
+template <std::size_t N> using vec = math::vector::vector<double, N>;
+
+TEST(MatrixHelper, IdentityFunctionProducesOnes) {
+  auto iden = math::matrix::identity<double, 4>();
+  VECTOR_FOR_EACH_RANGE(i, 4) {
+    EXPECT_THAT(iden.at(i, i), 1.0);
+  }
+  MATRIX_FOR_EACH_RANGE(i, 4, j, 4) {
+    EXPECT_TRUE(i == j || iden.at(i, j) == 0);
+  }
+}
+
+TEST(MatrixHelper, DiagonalWillFillWithAllZeros) {
+  vec<4> const vector({1.5, 0.5, -1.0, 2.2});
+  auto diag = math::matrix::diagonal(vector);
+  VECTOR_FOR_EACH_RANGE(i, 4) {
+    EXPECT_THAT(diag.at(i, i), vector.at(i));
+  }
+  MATRIX_FOR_EACH_RANGE(i, 4, j, 4) {
+    EXPECT_TRUE(i == j || diag.at(i, j) == 0);
+  }
+}