public void ConstructorValuesAreAccessibleByIndexer() { Matrix1x2 matrix1x2; matrix1x2 = new Matrix1x2(); for (int x = 0; x < matrix1x2.Columns; x++) { for (int y = 0; y < matrix1x2.Rows; y++) { Assert.AreEqual(0, matrix1x2[x, y], Epsilon); } } double value = 33.33; matrix1x2 = new Matrix1x2(value); for (int x = 0; x < matrix1x2.Columns; x++) { for (int y = 0; y < matrix1x2.Rows; y++) { Assert.AreEqual(value, matrix1x2[x, y], Epsilon); } } GenerateFilledMatrixWithValues(out matrix1x2); for (int y = 0; y < matrix1x2.Rows; y++) { for (int x = 0; x < matrix1x2.Columns; x++) { Assert.AreEqual(y * matrix1x2.Columns + x, matrix1x2[x, y], Epsilon); } } }
public void ColumnAccessorAreCorrect() { GenerateFilledMatrixWithValues(out Matrix4x2 value); Matrix1x2 column1 = value.Column1; for (int y = 0; y < value.Rows; y++) { Assert.Equal(value[0, y], column1[0, y]); } Matrix1x2 column2 = value.Column2; for (int y = 0; y < value.Rows; y++) { Assert.Equal(value[1, y], column2[0, y]); } Matrix1x2 column3 = value.Column3; for (int y = 0; y < value.Rows; y++) { Assert.Equal(value[2, y], column3[0, y]); } }
public void EqualityOperatorWorksCorrectly() { Matrix1x2 value1 = new Matrix1x2(100); Matrix1x2 value2 = new Matrix1x2(50) * 2; Assert.Equal(value1, value2); Assert.True(value1 == value2, "Equality operator failed."); }
public void AccessorThrowsWhenOutOfBounds() { Matrix1x2 matrix1x2 = new Matrix1x2(); Assert.Throws <ArgumentOutOfRangeException>(() => { matrix1x2[-1, 0] = 0; }); Assert.Throws <ArgumentOutOfRangeException>(() => { matrix1x2[0, -1] = 0; }); Assert.Throws <ArgumentOutOfRangeException>(() => { matrix1x2[1, 0] = 0; }); Assert.Throws <ArgumentOutOfRangeException>(() => { matrix1x2[0, 2] = 0; }); }
public void ConstantValuesAreCorrect() { Matrix1x2 matrix1x2 = new Matrix1x2(); Assert.Equal(1, matrix1x2.Columns); Assert.Equal(2, matrix1x2.Rows); Assert.Equal(Matrix1x2.ColumnCount, matrix1x2.Columns); Assert.Equal(Matrix1x2.RowCount, matrix1x2.Rows); }
public void ConstantValuesAreCorrect() { Matrix1x2 matrix1x2 = new Matrix1x2(); Assert.AreEqual(1, matrix1x2.Columns); Assert.AreEqual(2, matrix1x2.Rows); Assert.AreEqual(Matrix1x2.ColumnCount, matrix1x2.Columns); Assert.AreEqual(Matrix1x2.RowCount, matrix1x2.Rows); }
public void MuliplyByMatrix1x3ProducesMatrix1x2() { Matrix3x2 matrix1 = new Matrix3x2(3); Matrix1x3 matrix2 = new Matrix1x3(2); Matrix1x2 result = matrix1 * matrix2; Matrix1x2 expected = new Matrix1x2(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); }
public void MuliplyByMatrix1x4ProducesMatrix1x2() { Matrix4x2 matrix1 = new Matrix4x2(3); Matrix1x4 matrix2 = new Matrix1x4(2); Matrix1x2 result = matrix1 * matrix2; Matrix1x2 expected = new Matrix1x2(24, 24); Assert.Equal(expected, result); }
public void MuliplyByMatrix1x2ProducesMatrix1x3() { Matrix2x3 matrix1 = new Matrix2x3(3); Matrix1x2 matrix2 = new Matrix1x2(2); Matrix1x3 result = matrix1 * matrix2; Matrix1x3 expected = new Matrix1x3(12, 12, 12); Assert.Equal(expected, result); }
public void HashCodeGenerationWorksCorrectly() { HashSet <int> hashCodes = new HashSet <int>(); Matrix1x2 value = new Matrix1x2(1); for (int i = 2; i <= 100; i++) { Assert.True(hashCodes.Add(value.GetHashCode()), "Unique hash code generation failure."); value *= i; } }
public void ColumnAccessorAreCorrect() { Matrix2x2 value; GenerateFilledMatrixWithValues(out value); Matrix1x2 column1 = value.Column1; for (int y = 0; y < value.Rows; y++) { Assert.Equal(value[0, y], column1[0, y]); } }
public void MemberGetAndSetValuesCorrectly() { Matrix1x2 matrix1x2 = new Matrix1x2(); matrix1x2.M11 = 0; matrix1x2.M12 = 1; Assert.Equal(0, matrix1x2.M11, Epsilon); Assert.Equal(1, matrix1x2.M12, Epsilon); Assert.Equal(matrix1x2[0, 0], matrix1x2.M11, Epsilon); Assert.Equal(matrix1x2[0, 1], matrix1x2.M12, Epsilon); }
public void SimpleSubtractionGeneratesCorrectValues() { Matrix1x2 value1 = new Matrix1x2(100); Matrix1x2 value2 = new Matrix1x2(1); Matrix1x2 result = value1 - value2; for (int y = 0; y < Matrix1x2.RowCount; y++) { for (int x = 0; x < Matrix1x2.ColumnCount; x++) { Assert.Equal(100 - 1, result[x, y], Epsilon); } } }
public void ScalarMultiplicationIsCorrect() { GenerateFilledMatrixWithValues(out Matrix1x2 matrix1x2); for (double c = -10; c <= 10; c += 0.5) { Matrix1x2 result = matrix1x2 * c; for (int y = 0; y < matrix1x2.Rows; y++) { for (int x = 0; x < matrix1x2.Columns; x++) { Assert.Equal(matrix1x2[x, y] * c, result[x, y], Epsilon); } } } }
public void IndexerGetAndSetValuesCorrectly() { Matrix1x2 matrix1x2 = new Matrix1x2(); for (int x = 0; x < matrix1x2.Columns; x++) { for (int y = 0; y < matrix1x2.Rows; y++) { matrix1x2[x, y] = y * matrix1x2.Columns + x; } } for (int y = 0; y < matrix1x2.Rows; y++) { for (int x = 0; x < matrix1x2.Columns; x++) { Assert.Equal(y * matrix1x2.Columns + x, matrix1x2[x, y], Epsilon); } } }
public void ConstructorValuesAreAccessibleByIndexer() { Matrix1x2 matrix1x2; matrix1x2 = new Matrix1x2(); for (int x = 0; x < matrix1x2.Columns; x++) { for (int y = 0; y < matrix1x2.Rows; y++) { Assert.Equal(0, matrix1x2[x, y], Epsilon); } } double value = 33.33; matrix1x2 = new Matrix1x2(value); for (int x = 0; x < matrix1x2.Columns; x++) { for (int y = 0; y < matrix1x2.Rows; y++) { Assert.Equal(value, matrix1x2[x, y], Epsilon); } } GenerateFilledMatrixWithValues(out matrix1x2); for (int y = 0; y < matrix1x2.Rows; y++) { for (int x = 0; x < matrix1x2.Columns; x++) { Assert.Equal(y * matrix1x2.Columns + x, matrix1x2[x, y], Epsilon); } } }
public void AccessorThrowsWhenOutOfBounds() { Matrix1x2 matrix1x2 = new Matrix1x2(); try { matrix1x2[-1, 0] = 0; Assert.Fail("Matrix1x2[-1, 0] did not throw when it should have."); } catch (ArgumentOutOfRangeException) { } try { matrix1x2[0, -1] = 0; Assert.Fail("Matrix1x2[0, -1] did not throw when it should have."); } catch (ArgumentOutOfRangeException) { } try { matrix1x2[1, 0] = 0; Assert.Fail("Matrix1x2[1, 0] did not throw when it should have."); } catch (ArgumentOutOfRangeException) { } try { matrix1x2[0, 2] = 0; Assert.Fail("Matrix1x2[0, 2] did not throw when it should have."); } catch (ArgumentOutOfRangeException) { } }
private void GenerateFilledMatrixWithValues(out Matrix1x2 matrix) { matrix = new Matrix1x2(0, 1); }
public void SimpleAdditionGeneratesCorrectValues() { Matrix1x2 value1 = new Matrix1x2(1); Matrix1x2 value2 = new Matrix1x2(99); Matrix1x2 result = value1 + value2; for (int y = 0; y < Matrix1x2.RowCount; y++) { for (int x = 0; x < Matrix1x2.ColumnCount; x++) { Assert.Equal(1 + 99, result[x, y], Epsilon); } } }
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 SimpleSubtractionGeneratesCorrectValues() { Matrix1x2 value1 = new Matrix1x2(100); Matrix1x2 value2 = new Matrix1x2(1); Matrix1x2 result = value1 - value2; for (int y = 0; y < Matrix1x2.RowCount; y++) { for (int x = 0; x < Matrix1x2.ColumnCount; x++) { Assert.AreEqual(100 - 1, result[x, y], Epsilon); } } }
public void MemberGetAndSetValuesCorrectly() { Matrix1x2 matrix1x2 = new Matrix1x2(); matrix1x2.M11 = 0; matrix1x2.M12 = 1; Assert.AreEqual(0, matrix1x2.M11, Epsilon); Assert.AreEqual(1, matrix1x2.M12, Epsilon); Assert.AreEqual(matrix1x2[0, 0], matrix1x2.M11, Epsilon); Assert.AreEqual(matrix1x2[0, 1], matrix1x2.M12, Epsilon); }
public void HashCodeGenerationWorksCorrectly() { HashSet<int> hashCodes = new HashSet<int>(); Matrix1x2 value = new Matrix1x2(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() { Matrix1x2 value1 = new Matrix1x2(100); Matrix1x2 value2 = new Matrix1x2(50) * 2; Assert.AreEqual(value1, value2); Assert.IsTrue(value1 == value2, "Equality operator failed."); }
public void AccessorThrowsWhenOutOfBounds() { Matrix1x2 matrix1x2 = new Matrix1x2(); Assert.Throws<ArgumentOutOfRangeException>(() => { matrix1x2[-1, 0] = 0; }); Assert.Throws<ArgumentOutOfRangeException>(() => { matrix1x2[0, -1] = 0; }); Assert.Throws<ArgumentOutOfRangeException>(() => { matrix1x2[1, 0] = 0; }); Assert.Throws<ArgumentOutOfRangeException>(() => { matrix1x2[0, 2] = 0; }); }
public void MuliplyByMatrix1x3ProducesMatrix1x2() { Matrix3x2 matrix1 = new Matrix3x2(3); Matrix1x3 matrix2 = new Matrix1x3(2); Matrix1x2 result = matrix1 * matrix2; Matrix1x2 expected = new Matrix1x2(18, 18); Assert.AreEqual(expected, result); }
public void MuliplyByMatrix1x2ProducesMatrix1x4() { Matrix2x4 matrix1 = new Matrix2x4(3); Matrix1x2 matrix2 = new Matrix1x2(2); Matrix1x4 result = matrix1 * matrix2; Matrix1x4 expected = new Matrix1x4(12, 12, 12, 12); Assert.AreEqual(expected, result); }