From 9f764018d3c5152ff691eef86bd5e0ad7d00779d Mon Sep 17 00:00:00 2001 From: Godzil Date: Tue, 18 Feb 2020 12:20:40 +0000 Subject: [PATCH] Add a couple of test for code that wasn't tested before. --- tests/matrix_test.cpp | 21 +++++++++++++++++++-- tests/transformation_test.cpp | 11 +++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/tests/matrix_test.cpp b/tests/matrix_test.cpp index e51b92b..18d891c 100644 --- a/tests/matrix_test.cpp +++ b/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, diff --git a/tests/transformation_test.cpp b/tests/transformation_test.cpp index 6653d1c..703855a 100644 --- a/tests/transformation_test.cpp +++ b/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); } \ No newline at end of file