@@ -11,12 +11,12 @@ public class MatrixExtensionsTests
1111 public void Multiply_ShouldThrowInvalidOperationException_WhenOperandsAreNotCompatible ( )
1212 {
1313 // Arrange
14- var source = new double [ , ] { { 1 , 1 , 1 } , { 1 , 1 , 1 } , { 1 , 1 , 1 } } ;
15- var operand = new double [ , ] { { 1 } , { 1 } } ;
16-
14+ var source = new double [ , ] { { 1 , 1 , 1 } , { 1 , 1 , 1 } , { 1 , 1 , 1 } } ;
15+ var operand = new double [ , ] { { 1 } , { 1 } } ;
16+
1717 // Act
1818 Action action = ( ) => source . Multiply ( operand ) ;
19-
19+
2020 // Assert
2121 action . Should ( ) . Throw < InvalidOperationException > ( )
2222 . WithMessage ( "The width of a first operand should match the height of a second." ) ;
@@ -31,7 +31,7 @@ public void Multiply_ShouldCalculateDotProductMultiplicationResult(
3131 public void Copy_ShouldReturnImmutableCopyOfMatrix ( )
3232 {
3333 // Arrange
34- var sutMatrix = new double [ , ] { { 1 , 1 , 1 } , { 1 , 1 , 1 } , { 1 , 1 , 1 } } ;
34+ var sutMatrix = new double [ , ] { { 1 , 1 , 1 } , { 1 , 1 , 1 } , { 1 , 1 , 1 } } ;
3535
3636 // Act
3737 var actualMatrix = sutMatrix . Copy ( ) ;
@@ -40,42 +40,84 @@ public void Copy_ShouldReturnImmutableCopyOfMatrix()
4040 actualMatrix . Should ( ) . NotBeSameAs ( sutMatrix ) ;
4141 actualMatrix . Should ( ) . BeEquivalentTo ( sutMatrix ) ;
4242 }
43-
43+
4444 [ Test , TestCaseSource ( nameof ( MatrixTransposeTestCases ) ) ]
4545 public void Transpose_ShouldReturnTransposedMatrix (
4646 double [ , ] source , double [ , ] target ) =>
4747 source . Transpose ( ) . Should ( ) . BeEquivalentTo ( target ) ;
48-
48+
4949 [ Test ]
5050 public void MultiplyVector_ShouldCalculateDotProductMultiplicationResult ( )
5151 {
5252 // Arrange
53- var source = new double [ , ] { { 2 , 2 , - 1 } , { 0 , - 2 , - 1 } , { 0 , 0 , 5 } } ;
54- var operand = new double [ ] { 2 , 2 , 3 } ;
55- var result = new double [ ] { 5 , - 7 , 15 } ;
53+ var source = new double [ , ] { { 2 , 2 , - 1 } , { 0 , - 2 , - 1 } , { 0 , 0 , 5 } } ;
54+ var operand = new double [ ] { 2 , 2 , 3 } ;
55+ var result = new double [ ] { 5 , - 7 , 15 } ;
5656
5757 // Act
5858 var actualMatrix = source . MultiplyVector ( operand ) ;
5959
6060 // Assert
6161 actualMatrix . Should ( ) . BeEquivalentTo ( result ) ;
6262 }
63-
63+
6464 [ Test ]
6565 public void Subtract_ShouldThrowArgumentException_WhenOperandsAreNotCompatible ( )
6666 {
6767 // Arrange
68- var source = new double [ , ] { { 1 , 1 , 1 } , { 1 , 1 , 1 } , { 1 , 1 , 1 } } ;
69- var operand = new double [ , ] { { 1 } , { 1 } } ;
70-
68+ var source = new double [ , ] { { 1 , 1 , 1 } , { 1 , 1 , 1 } , { 1 , 1 , 1 } } ;
69+ var operand = new double [ , ] { { 1 } , { 1 } } ;
70+
7171 // Act
7272 Action action = ( ) => source . Subtract ( operand ) ;
73-
73+
7474 // Assert
7575 action . Should ( ) . Throw < ArgumentException > ( )
7676 . WithMessage ( "Dimensions of matrices must be the same" ) ;
7777 }
78-
78+
79+ [ Test ]
80+ public static void EqualMatricesShouldReturnTrue ( )
81+ {
82+ // Arrange
83+ var A = new double [ , ] { { 1 , 2 , 3 } , { 1 , 2 , 3 } , { 1 , 2 , 3 } } ;
84+ var B = new double [ , ] { { 1 , 2 , 3 } , { 1 , 2 , 3 } , { 1 , 2 , 3 } } ;
85+
86+ // Act
87+ var result = A . IsEqual ( B ) ;
88+
89+ // Assert
90+ Assert . True ( result ) ;
91+ }
92+
93+ [ Test ]
94+ public static void NonEqualMatricesShouldReturnFalse ( )
95+ {
96+ // Arrange
97+ var A = new double [ , ] { { 1 , 2 , 3 } , { 1 , 2 , 3 } , { 1 , 2 , 3 } } ;
98+ var B = new double [ , ] { { 1 , 2 , 3 } , { 1 , 2 , 6 } , { 1 , 2 , 3 } } ;
99+
100+ // Act
101+ var result = A . IsEqual ( B ) ;
102+
103+ // Assert
104+ Assert . False ( result ) ;
105+ }
106+
107+ [ Test ]
108+ public static void DifferentSizeMatricesShouldReturnFalse ( )
109+ {
110+ // Arrange
111+ var A = new double [ , ] { { 1 , 2 , 3 } , { 1 , 2 , 3 } , { 1 , 2 , 3 } } ;
112+ var B = new double [ , ] { { 1 , 2 , 3 } , { 1 , 2 , 3 } } ;
113+
114+ // Act
115+ var result = A . IsEqual ( B ) ;
116+
117+ // Assert
118+ Assert . False ( result ) ;
119+ }
120+
79121 [ Test , TestCaseSource ( nameof ( MatrixSubtractTestCases ) ) ]
80122 public void Subtract_ShouldCalculateSubtractionResult (
81123 double [ , ] source , double [ , ] operand , double [ , ] result ) =>
@@ -96,7 +138,7 @@ public void Subtract_ShouldCalculateSubtractionResult(
96138 new double [ , ] { { 11 , - 22 , 29 } , { 9 , - 27 , 32 } , { 13 , - 17 , 26 } }
97139 }
98140 } ;
99-
141+
100142 private static readonly object [ ] MatrixTransposeTestCases =
101143 {
102144 new object [ ]
@@ -110,7 +152,7 @@ public void Subtract_ShouldCalculateSubtractionResult(
110152 new double [ , ] { { 5 , 6 } , { 8 , 9 } }
111153 }
112154 } ;
113-
155+
114156 private static readonly object [ ] MatrixSubtractTestCases =
115157 {
116158 new object [ ]
0 commit comments