MCPcopy Create free account
hub / github.com/Geode-solutions/OpenGeode / test_matrix_2x2

Function test_matrix_2x2

tests/geometry/test-square-matrix.cpp:31–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29#include <geode/tests/common.hpp>
30
31void test_matrix_2x2()
32{
33 geode::Logger::info( "Test Matrix 2x2" );
34 const geode::SquareMatrix2D matrix{ { geode::Vector2D{ { -1, 1 } },
35 geode::Vector2D{ { 2, 2 } } } };
36
37 geode::OpenGeodeGeometryException::test( matrix.value( 0, 0 ) == -1,
38 "[TEST] Wrong value for matrix coeff [0,0]" );
39 geode::OpenGeodeGeometryException::test( matrix.value( 0, 1 ) == 1,
40 "[TEST] Wrong value for matrix coeff [0,1]" );
41 geode::OpenGeodeGeometryException::test( matrix.value( 1, 0 ) == 2,
42 "[TEST] Wrong value for matrix coeff [1,0]" );
43 geode::OpenGeodeGeometryException::test( matrix.value( 1, 1 ) == 2,
44 "[TEST] Wrong value for matrix coeff [1,1]" );
45
46 const auto mult_result = matrix * geode::Vector2D{ { 3, 5 } };
47 const geode::Vector2D answer{ { 2, 16 } };
48 geode::OpenGeodeGeometryException::test( mult_result == answer,
49 "[TEST] Wrong result for matrix multiplication: ", mult_result.string(),
50 " instead of [3,5]" );
51
52 const auto det = matrix.determinant();
53 geode::OpenGeodeGeometryException::test(
54 det == -4, "[TEST] Wrong determinant value: ", det, " instead of -4" );
55
56 const auto transpose_matrix = matrix.transpose();
57 geode::OpenGeodeGeometryException::test(
58 transpose_matrix.value( 0, 0 ) == -1,
59 "[TEST] Wrong value for transpose matrix coeff [0,0]" );
60 geode::OpenGeodeGeometryException::test(
61 transpose_matrix.value( 0, 1 ) == 2,
62 "[TEST] Wrong value for transpose matrix coeff [0,1]" );
63 geode::OpenGeodeGeometryException::test(
64 transpose_matrix.value( 1, 0 ) == 1,
65 "[TEST] Wrong value for transpose matrix coeff [1,0]" );
66 geode::OpenGeodeGeometryException::test(
67 transpose_matrix.value( 1, 1 ) == 2,
68 "[TEST] Wrong value for transpose matrix coeff [1,1]" );
69
70 const auto inverse_matrix = matrix.inverse();
71 geode::OpenGeodeGeometryException::test(
72 inverse_matrix.value( 0, 0 ) == -0.5,
73 "[TEST] Wrong value for inverse matrix coeff [0,0]: ",
74 inverse_matrix.value( 0, 0 ), " instead of ", -0.5 );
75 geode::OpenGeodeGeometryException::test(
76 inverse_matrix.value( 0, 1 ) == 0.25,
77 "[TEST] Wrong value for inverse matrix coeff [0,1]: ",
78 inverse_matrix.value( 0, 1 ), " instead of ", 0.25 );
79 geode::OpenGeodeGeometryException::test(
80 inverse_matrix.value( 1, 0 ) == 0.5,
81 "[TEST] Wrong value for inverse matrix coeff [1,0]: ",
82 inverse_matrix.value( 1, 0 ), " instead of ", 0.5 );
83 geode::OpenGeodeGeometryException::test(
84 inverse_matrix.value( 1, 1 ) == 0.25,
85 "[TEST] Wrong value for inverse matrix coeff [1,1]: ",
86 inverse_matrix.value( 1, 1 ), " instead of ", 0.25 );
87}
88

Callers 1

testFunction · 0.85

Calls 7

infoFunction · 0.85
determinantMethod · 0.80
transposeMethod · 0.80
testFunction · 0.70
valueMethod · 0.45
stringMethod · 0.45
inverseMethod · 0.45

Tested by

no test coverage detected