public void ConstructorValuesAreAccessibleByIndexer() { Matrix4x1 matrix4x1; matrix4x1 = new Matrix4x1(); for (int x = 0; x < matrix4x1.Columns; x++) { for (int y = 0; y < matrix4x1.Rows; y++) { Assert.AreEqual(0, matrix4x1[x, y], Epsilon); } } double value = 33.33; matrix4x1 = new Matrix4x1(value); for (int x = 0; x < matrix4x1.Columns; x++) { for (int y = 0; y < matrix4x1.Rows; y++) { Assert.AreEqual(value, matrix4x1[x, y], Epsilon); } } GenerateFilledMatrixWithValues(out matrix4x1); for (int y = 0; y < matrix4x1.Rows; y++) { for (int x = 0; x < matrix4x1.Columns; x++) { Assert.AreEqual(y * matrix4x1.Columns + x, matrix4x1[x, y], Epsilon); } } }
public void RowAccessorAreCorrect() { GenerateFilledMatrixWithValues(out Matrix4x4 value); Matrix4x1 row1 = value.Row1; for (int x = 0; x < value.Columns; x++) { Assert.Equal(value[x, 0], row1[x, 0]); } Matrix4x1 row2 = value.Row2; for (int x = 0; x < value.Columns; x++) { Assert.Equal(value[x, 1], row2[x, 0]); } Matrix4x1 row3 = value.Row3; for (int x = 0; x < value.Columns; x++) { Assert.Equal(value[x, 2], row3[x, 0]); } }
public void EqualityOperatorWorksCorrectly() { Matrix4x1 value1 = new Matrix4x1(100); Matrix4x1 value2 = new Matrix4x1(50) * 2; Assert.Equal(value1, value2); Assert.True(value1 == value2, "Equality operator failed."); }
public void ConstantValuesAreCorrect() { Matrix4x1 matrix4x1 = new Matrix4x1(); Assert.Equal(4, matrix4x1.Columns); Assert.Equal(1, matrix4x1.Rows); Assert.Equal(Matrix4x1.ColumnCount, matrix4x1.Columns); Assert.Equal(Matrix4x1.RowCount, matrix4x1.Rows); }
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 ConstantValuesAreCorrect() { Matrix4x1 matrix4x1 = new Matrix4x1(); Assert.AreEqual(4, matrix4x1.Columns); Assert.AreEqual(1, matrix4x1.Rows); Assert.AreEqual(Matrix4x1.ColumnCount, matrix4x1.Columns); Assert.AreEqual(Matrix4x1.RowCount, matrix4x1.Rows); }
public void MuliplyByMatrix4x4ProducesMatrix4x1() { Matrix4x1 matrix1 = new Matrix4x1(3); Matrix4x4 matrix2 = new Matrix4x4(2); Matrix4x1 result = matrix1 * matrix2; Matrix4x1 expected = new Matrix4x1(24, 24, 24, 24); Assert.Equal(expected, result); }
public void AccessorThrowsWhenOutOfBounds() { Matrix4x1 matrix4x1 = new Matrix4x1(); Assert.Throws <ArgumentOutOfRangeException>(() => { matrix4x1[-1, 0] = 0; }); Assert.Throws <ArgumentOutOfRangeException>(() => { matrix4x1[0, -1] = 0; }); Assert.Throws <ArgumentOutOfRangeException>(() => { matrix4x1[4, 0] = 0; }); Assert.Throws <ArgumentOutOfRangeException>(() => { matrix4x1[0, 1] = 0; }); }
public void MuliplyByMatrix4x3ProducesMatrix4x1() { Matrix3x1 matrix1 = new Matrix3x1(3); Matrix4x3 matrix2 = new Matrix4x3(2); Matrix4x1 result = matrix1 * matrix2; Matrix4x1 expected = new Matrix4x1(18, 18, 18, 18); Assert.Equal(expected, result); }
public void MuliplyByMatrix4x1ProducesMatrix4x2() { Matrix1x2 matrix1 = new Matrix1x2(3); Matrix4x1 matrix2 = new Matrix4x1(2); Matrix4x2 result = matrix1 * matrix2; Matrix4x2 expected = new Matrix4x2(6, 6, 6, 6, 6, 6, 6, 6); Assert.Equal(expected, result); }
static Matrix4x1 mul(Matrix4x4 A, Matrix4x1 B) // float4x1 mul(float4x4 A, float4x1 B); { Matrix4x1 result = new Matrix4x1(); result.m00 = (float)((double)A.m00 * (double)B.m00 + (double)A.m01 * (double)B.m10 + (double)A.m02 * (double)B.m20 + (double)A.m03 * (double)B.m30); result.m10 = (float)((double)A.m10 * (double)B.m00 + (double)A.m11 * (double)B.m10 + (double)A.m12 * (double)B.m20 + (double)A.m13 * (double)B.m30); result.m20 = (float)((double)A.m20 * (double)B.m00 + (double)A.m21 * (double)B.m10 + (double)A.m22 * (double)B.m20 + (double)A.m23 * (double)B.m30); result.m30 = (float)((double)A.m30 * (double)B.m00 + (double)A.m31 * (double)B.m10 + (double)A.m32 * (double)B.m20 + (double)A.m33 * (double)B.m30); return(result); }
public void HashCodeGenerationWorksCorrectly() { HashSet <int> hashCodes = new HashSet <int>(); Matrix4x1 value = new Matrix4x1(1); for (int i = 2; i <= 100; i++) { Assert.True(hashCodes.Add(value.GetHashCode()), "Unique hash code generation failure."); value *= i; } }
public void SimpleSubtractionGeneratesCorrectValues() { Matrix4x1 value1 = new Matrix4x1(100); Matrix4x1 value2 = new Matrix4x1(1); Matrix4x1 result = value1 - value2; for (int y = 0; y < Matrix4x1.RowCount; y++) { for (int x = 0; x < Matrix4x1.ColumnCount; x++) { Assert.Equal(100 - 1, result[x, y], Epsilon); } } }
public void RowAccessorAreCorrect() { Matrix4x2 value; GenerateFilledMatrixWithValues(out value); Matrix4x1 row1 = value.Row1; for (int x = 0; x < value.Columns; x++) { Assert.Equal(value[x, 0], row1[x, 0]); } }
public void ScalarMultiplicationIsCorrect() { GenerateFilledMatrixWithValues(out Matrix4x1 matrix4x1); for (double c = -10; c <= 10; c += 0.5) { Matrix4x1 result = matrix4x1 * c; for (int y = 0; y < matrix4x1.Rows; y++) { for (int x = 0; x < matrix4x1.Columns; x++) { Assert.Equal(matrix4x1[x, y] * c, result[x, y], Epsilon); } } } }
public void MemberGetAndSetValuesCorrectly() { Matrix4x1 matrix4x1 = new Matrix4x1(); matrix4x1.M11 = 0; matrix4x1.M21 = 1; matrix4x1.M31 = 2; matrix4x1.M41 = 3; Assert.Equal(0, matrix4x1.M11, Epsilon); Assert.Equal(1, matrix4x1.M21, Epsilon); Assert.Equal(2, matrix4x1.M31, Epsilon); Assert.Equal(3, matrix4x1.M41, Epsilon); Assert.Equal(matrix4x1[0, 0], matrix4x1.M11, Epsilon); Assert.Equal(matrix4x1[1, 0], matrix4x1.M21, Epsilon); Assert.Equal(matrix4x1[2, 0], matrix4x1.M31, Epsilon); Assert.Equal(matrix4x1[3, 0], matrix4x1.M41, Epsilon); }
public void IndexerGetAndSetValuesCorrectly() { Matrix4x1 matrix4x1 = new Matrix4x1(); for (int x = 0; x < matrix4x1.Columns; x++) { for (int y = 0; y < matrix4x1.Rows; y++) { matrix4x1[x, y] = y * matrix4x1.Columns + x; } } for (int y = 0; y < matrix4x1.Rows; y++) { for (int x = 0; x < matrix4x1.Columns; x++) { Assert.Equal(y * matrix4x1.Columns + x, matrix4x1[x, y], Epsilon); } } }
public void ConstructorValuesAreAccessibleByIndexer() { Matrix4x1 matrix4x1; matrix4x1 = new Matrix4x1(); for (int x = 0; x < matrix4x1.Columns; x++) { for (int y = 0; y < matrix4x1.Rows; y++) { Assert.Equal(0, matrix4x1[x, y], Epsilon); } } double value = 33.33; matrix4x1 = new Matrix4x1(value); for (int x = 0; x < matrix4x1.Columns; x++) { for (int y = 0; y < matrix4x1.Rows; y++) { Assert.Equal(value, matrix4x1[x, y], Epsilon); } } GenerateFilledMatrixWithValues(out matrix4x1); for (int y = 0; y < matrix4x1.Rows; y++) { for (int x = 0; x < matrix4x1.Columns; x++) { Assert.Equal(y * matrix4x1.Columns + x, matrix4x1[x, y], Epsilon); } } }
public void AccessorThrowsWhenOutOfBounds() { Matrix4x1 matrix4x1 = new Matrix4x1(); try { matrix4x1[-1, 0] = 0; Assert.Fail("Matrix4x1[-1, 0] did not throw when it should have."); } catch (ArgumentOutOfRangeException) { } try { matrix4x1[0, -1] = 0; Assert.Fail("Matrix4x1[0, -1] did not throw when it should have."); } catch (ArgumentOutOfRangeException) { } try { matrix4x1[4, 0] = 0; Assert.Fail("Matrix4x1[4, 0] did not throw when it should have."); } catch (ArgumentOutOfRangeException) { } try { matrix4x1[0, 1] = 0; Assert.Fail("Matrix4x1[0, 1] did not throw when it should have."); } catch (ArgumentOutOfRangeException) { } }
private void GenerateFilledMatrixWithValues(out Matrix4x1 matrix) { matrix = new Matrix4x1(0, 1, 2, 3); }
public void SimpleSubtractionGeneratesCorrectValues() { Matrix4x1 value1 = new Matrix4x1(100); Matrix4x1 value2 = new Matrix4x1(1); Matrix4x1 result = value1 - value2; for (int y = 0; y < Matrix4x1.RowCount; y++) { for (int x = 0; x < Matrix4x1.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 MemberGetAndSetValuesCorrectly() { Matrix4x1 matrix4x1 = new Matrix4x1(); matrix4x1.M11 = 0; matrix4x1.M21 = 1; matrix4x1.M31 = 2; matrix4x1.M41 = 3; Assert.AreEqual(0, matrix4x1.M11, Epsilon); Assert.AreEqual(1, matrix4x1.M21, Epsilon); Assert.AreEqual(2, matrix4x1.M31, Epsilon); Assert.AreEqual(3, matrix4x1.M41, Epsilon); Assert.AreEqual(matrix4x1[0, 0], matrix4x1.M11, Epsilon); Assert.AreEqual(matrix4x1[1, 0], matrix4x1.M21, Epsilon); Assert.AreEqual(matrix4x1[2, 0], matrix4x1.M31, Epsilon); Assert.AreEqual(matrix4x1[3, 0], matrix4x1.M41, Epsilon); }
public void HashCodeGenerationWorksCorrectly() { HashSet<int> hashCodes = new HashSet<int>(); Matrix4x1 value = new Matrix4x1(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() { Matrix4x1 value1 = new Matrix4x1(100); Matrix4x1 value2 = new Matrix4x1(50) * 2; Assert.AreEqual(value1, value2); Assert.IsTrue(value1 == value2, "Equality operator failed."); }
public void MuliplyByMatrix4x1ProducesMatrix4x3() { Matrix1x3 matrix1 = new Matrix1x3(3); Matrix4x1 matrix2 = new Matrix4x1(2); Matrix4x3 result = matrix1 * matrix2; Matrix4x3 expected = new Matrix4x3(6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6); Assert.Equal(expected, result); }
public void MuliplyByMatrix4x4ProducesMatrix4x1() { Matrix4x1 matrix1 = new Matrix4x1(3); Matrix4x4 matrix2 = new Matrix4x4(2); Matrix4x1 result = matrix1 * matrix2; Matrix4x1 expected = new Matrix4x1(24, 24, 24, 24); Assert.AreEqual(expected, result); }
public void SimpleAdditionGeneratesCorrectValues() { Matrix4x1 value1 = new Matrix4x1(1); Matrix4x1 value2 = new Matrix4x1(99); Matrix4x1 result = value1 + value2; for (int y = 0; y < Matrix4x1.RowCount; y++) { for (int x = 0; x < Matrix4x1.ColumnCount; x++) { Assert.Equal(1 + 99, result[x, y], Epsilon); } } }
public void MuliplyByMatrix4x3ProducesMatrix4x1() { Matrix3x1 matrix1 = new Matrix3x1(3); Matrix4x3 matrix2 = new Matrix4x3(2); Matrix4x1 result = matrix1 * matrix2; Matrix4x1 expected = new Matrix4x1(18, 18, 18, 18); Assert.AreEqual(expected, result); }
public void MuliplyByMatrix4x1ProducesMatrix4x2() { Matrix1x2 matrix1 = new Matrix1x2(3); Matrix4x1 matrix2 = new Matrix4x1(2); Matrix4x2 result = matrix1 * matrix2; Matrix4x2 expected = new Matrix4x2(6, 6, 6, 6, 6, 6, 6, 6); Assert.AreEqual(expected, result); }
public void AccessorThrowsWhenOutOfBounds() { Matrix4x1 matrix4x1 = new Matrix4x1(); Assert.Throws<ArgumentOutOfRangeException>(() => { matrix4x1[-1, 0] = 0; }); Assert.Throws<ArgumentOutOfRangeException>(() => { matrix4x1[0, -1] = 0; }); Assert.Throws<ArgumentOutOfRangeException>(() => { matrix4x1[4, 0] = 0; }); Assert.Throws<ArgumentOutOfRangeException>(() => { matrix4x1[0, 1] = 0; }); }