Beispiel #1
0
        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);
                }
            }
        }
Beispiel #2
0
        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]);
            }
        }
Beispiel #3
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.");
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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; });
        }
Beispiel #7
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);
        }
Beispiel #8
0
        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);
        }
Beispiel #9
0
        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);
        }
Beispiel #10
0
        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);
        }
Beispiel #11
0
        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;
            }
        }
Beispiel #12
0
        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);
        }
Beispiel #13
0
        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);
                }
            }
        }
Beispiel #14
0
        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]);
            }
        }
Beispiel #15
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);
                    }
                }
            }
        }
Beispiel #16
0
        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);
                }
            }
        }
Beispiel #17
0
        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);
                }
            }
        }
Beispiel #18
0
        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);
                }
            }
        }
Beispiel #19
0
        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)
            { }
        }
Beispiel #20
0
        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);
        }
Beispiel #21
0
 private void GenerateFilledMatrixWithValues(out Matrix2x1 matrix)
 {
     matrix = new Matrix2x1(0, 1);
 }
Beispiel #22
0
        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);
                }
            }
        }
Beispiel #23
0
        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);
        }
Beispiel #24
0
 private void GenerateFilledMatrixWithValues(out Matrix2x1 matrix)
 {
     matrix = new Matrix2x1(0, 1);
 }
Beispiel #25
0
        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;
            }
        }
Beispiel #26
0
        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.");
        }
Beispiel #27
0
        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; });
        }
Beispiel #28
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);
                }
            }
        }
Beispiel #29
0
        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);
        }
Beispiel #30
0
        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);
        }
Beispiel #31
0
        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);
        }
Beispiel #32
0
        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);
        }