Browse Source

Add a couple of test for code that wasn't tested before.

Godzil 4 years ago
parent
commit
9f764018d3
2 changed files with 30 additions and 2 deletions
  1. 19 2
      tests/matrix_test.cpp
  2. 11 0
      tests/transformation_test.cpp

+ 19 - 2
tests/matrix_test.cpp

@@ -30,7 +30,7 @@ TEST(MatrixTest, Constructing_and_inspecting_a_4x4_Matrix)
     ASSERT_EQ(m.get(3, 2), 15.5);
 }
 
-TEST(MatrixTest, A_2x2_matric_ought_to_be_representable)
+TEST(MatrixTest, Change_a_single_value_and_check_it)
 {
     double values[] = {-3, 5,
                         1, -2};
@@ -41,9 +41,13 @@ TEST(MatrixTest, A_2x2_matric_ought_to_be_representable)
     ASSERT_EQ(m.get(0, 1), 5);
     ASSERT_EQ(m.get(1, 0), 1);
     ASSERT_EQ(m.get(1, 1), -2);
+
+    m.set(0, 0, 12);
+
+    ASSERT_EQ(m.get(0, 0), 12);
 }
 
-TEST(MatrixTest, A_3x3_matric_ought_to_be_representable)
+TEST(MatrixTest, A_3x3_matrix_ought_to_be_representable)
 {
     double values[] = {-3, 5, 0,
                        1,  -2, -7,
@@ -56,6 +60,19 @@ TEST(MatrixTest, A_3x3_matric_ought_to_be_representable)
     ASSERT_EQ(m.get(2, 2), 1);
 }
 
+TEST(MatrixTest, A_2x2_matrix_ought_to_be_representable)
+{
+    double values[] = {-3, 5,
+                       1, -2};
+
+    Matrix2 m = Matrix2(values);
+
+    ASSERT_EQ(m.get(0, 0), -3);
+    ASSERT_EQ(m.get(0, 1), 5);
+    ASSERT_EQ(m.get(1, 0), 1);
+    ASSERT_EQ(m.get(1, 1), -2);
+}
+
 TEST(MatrixTest, Matrix_equality_with_identical_matrix)
 {
     double values1[] = {1, 2, 3, 4,

+ 11 - 0
tests/transformation_test.cpp

@@ -188,4 +188,15 @@ TEST(TransformationTest, Chained_transformation_must_be_applied_in_reverse_order
 
     Matrix T = C * B * A;
     ASSERT_EQ(T * p, Point(15, 0, 7));
+}
+
+TEST(TransformationTest, Check_that_deg_to_rad_is_working)
+{
+    double angle180 = deg_to_rad(180);
+    double angle90 = deg_to_rad(90);
+    double angle270 = deg_to_rad(270);
+
+    ASSERT_EQ(angle180, M_PI);
+    ASSERT_EQ(angle90, M_PI / 2.);
+    ASSERT_EQ(angle270, M_PI * 1.5);
 }