public void ConstructorValuesAreAccessibleByIndexer() { Matrix2x1 matrix2x1; matrix2x1 = new Matrix2x1(); for (int x = 0; x < matrix2x1.Columns; x++) { for (int y = 0; y < matrix2x1.Rows; y++) { Assert.AreEqual(0, matrix2x1[x, y], Epsilon); } } double value = 33.33; matrix2x1 = new Matrix2x1(value); for (int x = 0; x < matrix2x1.Columns; x++) { for (int y = 0; y < matrix2x1.Rows; y++) { Assert.AreEqual(value, matrix2x1[x, y], Epsilon); } } GenerateFilledMatrixWithValues(out matrix2x1); for (int y = 0; y < matrix2x1.Rows; y++) { for (int x = 0; x < matrix2x1.Columns; x++) { Assert.AreEqual(y * matrix2x1.Columns + x, matrix2x1[x, y], Epsilon); } } }
public void RowAccessorAreCorrect() { GenerateFilledMatrixWithValues(out Matrix2x4 value); Matrix2x1 row1 = value.Row1; for (int x = 0; x < value.Columns; x++) { Assert.Equal(value[x, 0], row1[x, 0]); } Matrix2x1 row2 = value.Row2; for (int x = 0; x < value.Columns; x++) { Assert.Equal(value[x, 1], row2[x, 0]); } Matrix2x1 row3 = value.Row3; for (int x = 0; x < value.Columns; x++) { Assert.Equal(value[x, 2], row3[x, 0]); } }
public void EqualityOperatorWorksCorrectly() { Matrix2x1 value1 = new Matrix2x1(100); Matrix2x1 value2 = new Matrix2x1(50) * 2; Assert.Equal(value1, value2); Assert.True(value1 == value2, "Equality operator failed."); }
public void MuliplyByMatrix2x4ProducesMatrix2x1() { Matrix4x1 matrix1 = new Matrix4x1(3); Matrix2x4 matrix2 = new Matrix2x4(2); Matrix2x1 result = matrix1 * matrix2; Matrix2x1 expected = new Matrix2x1(24, 24); Assert.Equal(expected, result); }
public void MuliplyByMatrix4x2ProducesMatrix4x1() { Matrix2x1 matrix1 = new Matrix2x1(3); Matrix4x2 matrix2 = new Matrix4x2(2); Matrix4x1 result = matrix1 * matrix2; Matrix4x1 expected = new Matrix4x1(12, 12, 12, 12); Assert.Equal(expected, result); }
public void AccessorThrowsWhenOutOfBounds() { Matrix2x1 matrix2x1 = new Matrix2x1(); Assert.Throws <ArgumentOutOfRangeException>(() => { matrix2x1[-1, 0] = 0; }); Assert.Throws <ArgumentOutOfRangeException>(() => { matrix2x1[0, -1] = 0; }); Assert.Throws <ArgumentOutOfRangeException>(() => { matrix2x1[2, 0] = 0; }); Assert.Throws <ArgumentOutOfRangeException>(() => { matrix2x1[0, 1] = 0; }); }
public void ConstantValuesAreCorrect() { Matrix2x1 matrix2x1 = new Matrix2x1(); Assert.AreEqual(2, matrix2x1.Columns); Assert.AreEqual(1, matrix2x1.Rows); Assert.AreEqual(Matrix2x1.ColumnCount, matrix2x1.Columns); Assert.AreEqual(Matrix2x1.RowCount, matrix2x1.Rows); }
public void ConstantValuesAreCorrect() { Matrix2x1 matrix2x1 = new Matrix2x1(); Assert.Equal(2, matrix2x1.Columns); Assert.Equal(1, matrix2x1.Rows); Assert.Equal(Matrix2x1.ColumnCount, matrix2x1.Columns); Assert.Equal(Matrix2x1.RowCount, matrix2x1.Rows); }
public void MuliplyByMatrix2x3ProducesMatrix2x1() { Matrix3x1 matrix1 = new Matrix3x1(3); Matrix2x3 matrix2 = new Matrix2x3(2); Matrix2x1 result = matrix1 * matrix2; Matrix2x1 expected = new Matrix2x1(18, 18); Assert.Equal(expected, result); }
public void MuliplyByMatrix2x1ProducesMatrix2x2() { Matrix1x2 matrix1 = new Matrix1x2(3); Matrix2x1 matrix2 = new Matrix2x1(2); Matrix2x2 result = matrix1 * matrix2; Matrix2x2 expected = new Matrix2x2(6, 6, 6, 6); Assert.Equal(expected, result); }
public void HashCodeGenerationWorksCorrectly() { HashSet <int> hashCodes = new HashSet <int>(); Matrix2x1 value = new Matrix2x1(1); for (int i = 2; i <= 100; i++) { Assert.True(hashCodes.Add(value.GetHashCode()), "Unique hash code generation failure."); value *= i; } }
public void MemberGetAndSetValuesCorrectly() { Matrix2x1 matrix2x1 = new Matrix2x1(); matrix2x1.M11 = 0; matrix2x1.M21 = 1; Assert.Equal(0, matrix2x1.M11, Epsilon); Assert.Equal(1, matrix2x1.M21, Epsilon); Assert.Equal(matrix2x1[0, 0], matrix2x1.M11, Epsilon); Assert.Equal(matrix2x1[1, 0], matrix2x1.M21, Epsilon); }
public void SimpleSubtractionGeneratesCorrectValues() { Matrix2x1 value1 = new Matrix2x1(100); Matrix2x1 value2 = new Matrix2x1(1); Matrix2x1 result = value1 - value2; for (int y = 0; y < Matrix2x1.RowCount; y++) { for (int x = 0; x < Matrix2x1.ColumnCount; x++) { Assert.Equal(100 - 1, result[x, y], Epsilon); } } }
public void RowAccessorAreCorrect() { Matrix2x2 value; GenerateFilledMatrixWithValues(out value); Matrix2x1 row1 = value.Row1; for (int x = 0; x < value.Columns; x++) { Assert.Equal(value[x, 0], row1[x, 0]); } }
public void ScalarMultiplicationIsCorrect() { GenerateFilledMatrixWithValues(out Matrix2x1 matrix2x1); for (double c = -10; c <= 10; c += 0.5) { Matrix2x1 result = matrix2x1 * c; for (int y = 0; y < matrix2x1.Rows; y++) { for (int x = 0; x < matrix2x1.Columns; x++) { Assert.Equal(matrix2x1[x, y] * c, result[x, y], Epsilon); } } } }
public void IndexerGetAndSetValuesCorrectly() { Matrix2x1 matrix2x1 = new Matrix2x1(); for (int x = 0; x < matrix2x1.Columns; x++) { for (int y = 0; y < matrix2x1.Rows; y++) { matrix2x1[x, y] = y * matrix2x1.Columns + x; } } for (int y = 0; y < matrix2x1.Rows; y++) { for (int x = 0; x < matrix2x1.Columns; x++) { Assert.Equal(y * matrix2x1.Columns + x, matrix2x1[x, y], Epsilon); } } }
public void ConstructorValuesAreAccessibleByIndexer() { Matrix2x1 matrix2x1; matrix2x1 = new Matrix2x1(); for (int x = 0; x < matrix2x1.Columns; x++) { for (int y = 0; y < matrix2x1.Rows; y++) { Assert.Equal(0, matrix2x1[x, y], Epsilon); } } double value = 33.33; matrix2x1 = new Matrix2x1(value); for (int x = 0; x < matrix2x1.Columns; x++) { for (int y = 0; y < matrix2x1.Rows; y++) { Assert.Equal(value, matrix2x1[x, y], Epsilon); } } GenerateFilledMatrixWithValues(out matrix2x1); for (int y = 0; y < matrix2x1.Rows; y++) { for (int x = 0; x < matrix2x1.Columns; x++) { Assert.Equal(y * matrix2x1.Columns + x, matrix2x1[x, y], Epsilon); } } }
public void AccessorThrowsWhenOutOfBounds() { Matrix2x1 matrix2x1 = new Matrix2x1(); try { matrix2x1[-1, 0] = 0; Assert.Fail("Matrix2x1[-1, 0] did not throw when it should have."); } catch (ArgumentOutOfRangeException) { } try { matrix2x1[0, -1] = 0; Assert.Fail("Matrix2x1[0, -1] did not throw when it should have."); } catch (ArgumentOutOfRangeException) { } try { matrix2x1[2, 0] = 0; Assert.Fail("Matrix2x1[2, 0] did not throw when it should have."); } catch (ArgumentOutOfRangeException) { } try { matrix2x1[0, 1] = 0; Assert.Fail("Matrix2x1[0, 1] did not throw when it should have."); } catch (ArgumentOutOfRangeException) { } }
private void GenerateFilledMatrixWithValues(out Matrix2x1 matrix) { matrix = new Matrix2x1(0, 1); }
public void SimpleSubtractionGeneratesCorrectValues() { Matrix2x1 value1 = new Matrix2x1(100); Matrix2x1 value2 = new Matrix2x1(1); Matrix2x1 result = value1 - value2; for (int y = 0; y < Matrix2x1.RowCount; y++) { for (int x = 0; x < Matrix2x1.ColumnCount; x++) { Assert.AreEqual(100 - 1, result[x, y], Epsilon); } } }
public void MuliplyByMatrix4x2ProducesMatrix4x1() { Matrix2x1 matrix1 = new Matrix2x1(3); Matrix4x2 matrix2 = new Matrix4x2(2); Matrix4x1 result = matrix1 * matrix2; Matrix4x1 expected = new Matrix4x1(12, 12, 12, 12); Assert.AreEqual(expected, result); }
public void HashCodeGenerationWorksCorrectly() { HashSet<int> hashCodes = new HashSet<int>(); Matrix2x1 value = new Matrix2x1(1); for (int i = 2; i <= 100; i++) { if (!hashCodes.Add(value.GetHashCode())) { Assert.Fail("Unique hash code generation failure."); } value *= i; } }
public void EqualityOperatorWorksCorrectly() { Matrix2x1 value1 = new Matrix2x1(100); Matrix2x1 value2 = new Matrix2x1(50) * 2; Assert.AreEqual(value1, value2); Assert.IsTrue(value1 == value2, "Equality operator failed."); }
public void AccessorThrowsWhenOutOfBounds() { Matrix2x1 matrix2x1 = new Matrix2x1(); Assert.Throws<ArgumentOutOfRangeException>(() => { matrix2x1[-1, 0] = 0; }); Assert.Throws<ArgumentOutOfRangeException>(() => { matrix2x1[0, -1] = 0; }); Assert.Throws<ArgumentOutOfRangeException>(() => { matrix2x1[2, 0] = 0; }); Assert.Throws<ArgumentOutOfRangeException>(() => { matrix2x1[0, 1] = 0; }); }
public void SimpleAdditionGeneratesCorrectValues() { Matrix2x1 value1 = new Matrix2x1(1); Matrix2x1 value2 = new Matrix2x1(99); Matrix2x1 result = value1 + value2; for (int y = 0; y < Matrix2x1.RowCount; y++) { for (int x = 0; x < Matrix2x1.ColumnCount; x++) { Assert.Equal(1 + 99, result[x, y], Epsilon); } } }
public void MuliplyByMatrix2x1ProducesMatrix2x3() { Matrix1x3 matrix1 = new Matrix1x3(3); Matrix2x1 matrix2 = new Matrix2x1(2); Matrix2x3 result = matrix1 * matrix2; Matrix2x3 expected = new Matrix2x3(6, 6, 6, 6, 6, 6); Assert.Equal(expected, result); }
public void MuliplyByMatrix2x3ProducesMatrix2x1() { Matrix3x1 matrix1 = new Matrix3x1(3); Matrix2x3 matrix2 = new Matrix2x3(2); Matrix2x1 result = matrix1 * matrix2; Matrix2x1 expected = new Matrix2x1(18, 18); Assert.AreEqual(expected, result); }
public void MuliplyByMatrix2x1ProducesMatrix2x2() { Matrix1x2 matrix1 = new Matrix1x2(3); Matrix2x1 matrix2 = new Matrix2x1(2); Matrix2x2 result = matrix1 * matrix2; Matrix2x2 expected = new Matrix2x2(6, 6, 6, 6); Assert.AreEqual(expected, result); }
public void MemberGetAndSetValuesCorrectly() { Matrix2x1 matrix2x1 = new Matrix2x1(); matrix2x1.M11 = 0; matrix2x1.M21 = 1; Assert.AreEqual(0, matrix2x1.M11, Epsilon); Assert.AreEqual(1, matrix2x1.M21, Epsilon); Assert.AreEqual(matrix2x1[0, 0], matrix2x1.M11, Epsilon); Assert.AreEqual(matrix2x1[1, 0], matrix2x1.M21, Epsilon); }