소스 검색

Add tests for mutable row_reference, operator!=, and concat to reach 100% code coverage.

Sam Jaffe 5 년 전
부모
커밋
18a3cd69be
1개의 변경된 파일20개의 추가작업 그리고 1개의 파일을 삭제
  1. 20 1
      test/matrix_test.cxx

+ 20 - 1
test/matrix_test.cxx

@@ -17,7 +17,7 @@ matr2 identity2() { return matr2({{{1, 0}, {0, 1}}}); }
 
 TEST(Matrix, Equality) {
   EXPECT_THAT(identity2i(), matr2i({{{1, 0}, {0, 1}}}));
-  EXPECT_THAT(identity2i(), ::testing::Not(matr2i({{{0, 1}, {0, 1}}})));
+  EXPECT_THAT(identity2i(), ::testing::Ne(matr2i({{{0, 1}, {0, 1}}})));
 }
 
 TEST(Matrix, AtRowBeyondBoundaryThrowsException) {
@@ -118,6 +118,19 @@ TEST(Matrix, VectorMultiplicationProducesVector) {
   EXPECT_THAT(A * x, vec2i({1, 5}));
 }
 
+TEST(Matrix, ConcatenationExtends) {
+  using namespace math::matrix;
+  auto A = matr2i({{{1, 2}, {2, 3}}});
+  auto B = matr2i({{{1, 0}, {1, 1}}});
+  EXPECT_THAT(A.concat(B, concat_strategy::horizontal),
+              (matrix<int, 2, 4>({{{1, 2, 1, 0}, {2, 3, 1, 1}}})));
+  EXPECT_THAT(A.concat(B, concat_strategy::vertical),
+              (matrix<int, 4, 2>({{{1, 2}, {2, 3}, {1, 0}, {1, 1}}})));
+  EXPECT_THAT(A.concat(B, concat_strategy::diagonal),
+              (matrix<int, 4, 4>(
+                  {{{1, 2, 0, 0}, {2, 3, 0, 0}, {0, 0, 1, 0}, {0, 0, 1, 1}}})));
+}
+
 // TEST(Matrix, Composition) {
 //  using namespace math::matrix;
 //  using vec4 = math::vector::vector<double, 4>;
@@ -140,6 +153,12 @@ TEST(Matrix, MatrixConstructableFromVector) {
   EXPECT_THAT(m(2, 0), v[2]);
 }
 
+TEST(Matrix, RowAllowsMutation) {
+  matr2i A = identity2i();
+  A[0][0] = 2;
+  EXPECT_THAT(A, matr2i({{{2, 0}, {0, 1}}}));
+}
+
 TEST(Matrix, CanAlterEntireRowInOneExpression) {
   matr2i A = identity2i();
   matr2i const B = 2 * A;