Example #1
0
        public void ConstructorValuesAreAccessibleByIndexer()
        {
            Matrix1x3 matrix1x3;

            matrix1x3 = new Matrix1x3();

            for (int x = 0; x < matrix1x3.Columns; x++)
            {
                for (int y = 0; y < matrix1x3.Rows; y++)
                {
                    Assert.Equal(0, matrix1x3[x, y], Epsilon);
                }
            }

            double value = 33.33;
            matrix1x3 = new Matrix1x3(value);

            for (int x = 0; x < matrix1x3.Columns; x++)
            {
                for (int y = 0; y < matrix1x3.Rows; y++)
                {
                    Assert.Equal(value, matrix1x3[x, y], Epsilon);
                }
            }

            GenerateFilledMatrixWithValues(out matrix1x3);

            for (int y = 0; y < matrix1x3.Rows; y++)
            {
                for (int x = 0; x < matrix1x3.Columns; x++)
                {
                    Assert.Equal(y * matrix1x3.Columns + x, matrix1x3[x, y], Epsilon);
                }
            }
        }
Example #2
0
        public void ConstantValuesAreCorrect()
        {
            Matrix1x3 matrix1x3 = new Matrix1x3();

            Assert.Equal(1, matrix1x3.Columns);
            Assert.Equal(3, matrix1x3.Rows);
            Assert.Equal(Matrix1x3.ColumnCount, matrix1x3.Columns);
            Assert.Equal(Matrix1x3.RowCount, matrix1x3.Rows);
        }
Example #3
0
        public void IndexerGetAndSetValuesCorrectly()
        {
            Matrix1x3 matrix1x3 = new Matrix1x3();

            for (int x = 0; x < matrix1x3.Columns; x++)
            {
                for (int y = 0; y < matrix1x3.Rows; y++)
                {
                    matrix1x3[x, y] = y * matrix1x3.Columns + x;
                }
            }

            for (int y = 0; y < matrix1x3.Rows; y++)
            {
                for (int x = 0; x < matrix1x3.Columns; x++)
                {
                    Assert.Equal(y * matrix1x3.Columns + x, matrix1x3[x, y], Epsilon);
                }
            }
        }
Example #4
0
        public void AccessorThrowsWhenOutOfBounds()
        {
            Matrix1x3 matrix1x3 = new Matrix1x3();

            try
            {
                matrix1x3[-1, 0] = 0;
                Assert.Fail("Matrix1x3[-1, 0] did not throw when it should have.");
            }
            catch (ArgumentOutOfRangeException)
            { }

            try
            {
                matrix1x3[0, -1] = 0;
                Assert.Fail("Matrix1x3[0, -1] did not throw when it should have.");
            }
            catch (ArgumentOutOfRangeException)
            { }

            try
            {
                matrix1x3[1, 0] = 0;
                Assert.Fail("Matrix1x3[1, 0] did not throw when it should have.");
            }
            catch (ArgumentOutOfRangeException)
            { }

            try
            {
                matrix1x3[0, 3] = 0;
                Assert.Fail("Matrix1x3[0, 3] did not throw when it should have.");
            }
            catch (ArgumentOutOfRangeException)
            { }
        }
Example #5
0
 private void GenerateFilledMatrixWithValues(out Matrix1x3 matrix)
 {
     matrix = new Matrix1x3(0, 
                            1, 
                            2);
 }
Example #6
0
        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);
        }
Example #7
0
        public void AccessorThrowsWhenOutOfBounds()
        {
            Matrix1x3 matrix1x3 = new Matrix1x3();

            Assert.Throws<ArgumentOutOfRangeException>(() => { matrix1x3[-1, 0] = 0; });
            Assert.Throws<ArgumentOutOfRangeException>(() => { matrix1x3[0, -1] = 0; });
            Assert.Throws<ArgumentOutOfRangeException>(() => { matrix1x3[1, 0] = 0; });
            Assert.Throws<ArgumentOutOfRangeException>(() => { matrix1x3[0, 3] = 0; });
        }
Example #8
0
        public void EqualityOperatorWorksCorrectly()
        {
            Matrix1x3 value1 = new Matrix1x3(100);
            Matrix1x3 value2 = new Matrix1x3(50) * 2;

            Assert.Equal(value1, value2);
            Assert.True(value1 == value2, "Equality operator failed.");
        }
Example #9
0
        public void HashCodeGenerationWorksCorrectly()
        {
            HashSet<int> hashCodes = new HashSet<int>();
            Matrix1x3 value = new Matrix1x3(1);

            for (int i = 2; i <= 100; i++)
            {
                Assert.True(hashCodes.Add(value.GetHashCode()), "Unique hash code generation failure.");

                value *= i;
            }
        }
Example #10
0
        public void MemberGetAndSetValuesCorrectly()
        {
            Matrix1x3 matrix1x3 = new Matrix1x3();

            matrix1x3.M11 = 0;
            matrix1x3.M12 = 1;
            matrix1x3.M13 = 2;

            Assert.Equal(0, matrix1x3.M11, Epsilon);
            Assert.Equal(1, matrix1x3.M12, Epsilon);
            Assert.Equal(2, matrix1x3.M13, Epsilon);

            Assert.Equal(matrix1x3[0, 0], matrix1x3.M11, Epsilon);
            Assert.Equal(matrix1x3[0, 1], matrix1x3.M12, Epsilon);
            Assert.Equal(matrix1x3[0, 2], matrix1x3.M13, Epsilon);
        }
Example #11
0
        public void MuliplyByMatrix1x3ProducesMatrix1x4()
        {
            Matrix3x4 matrix1 = new Matrix3x4(3);
            Matrix1x3 matrix2 = new Matrix1x3(2);
            Matrix1x4 result = matrix1 * matrix2;
            Matrix1x4 expected = new Matrix1x4(18, 
                                               18, 
                                               18, 
                                               18);

            Assert.Equal(expected, result);
        }
Example #12
0
        public void MuliplyByMatrix1x4ProducesMatrix1x3()
        {
            Matrix4x3 matrix1 = new Matrix4x3(3);
            Matrix1x4 matrix2 = new Matrix1x4(2);
            Matrix1x3 result = matrix1 * matrix2;
            Matrix1x3 expected = new Matrix1x3(24, 
                                               24, 
                                               24);

            Assert.Equal(expected, result);
        }
Example #13
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);
        }
Example #14
0
 private void GenerateFilledMatrixWithValues(out Matrix1x3 matrix)
 {
     matrix = new Matrix1x3(0,
                            1,
                            2);
 }
Example #15
0
        public void SimpleSubtractionGeneratesCorrectValues()
        {
            Matrix1x3 value1 = new Matrix1x3(100);
            Matrix1x3 value2 = new Matrix1x3(1);
            Matrix1x3 result = value1 - value2;

            for (int y = 0; y < Matrix1x3.RowCount; y++)
            {
                for (int x = 0; x < Matrix1x3.ColumnCount; x++)
                {
                    Assert.Equal(100 - 1, result[x, y], Epsilon);
                }
            }
        }
Example #16
0
        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);
        }
Example #17
0
        public void SimpleAdditionGeneratesCorrectValues()
        {
            Matrix1x3 value1 = new Matrix1x3(1);
            Matrix1x3 value2 = new Matrix1x3(99);
            Matrix1x3 result = value1 + value2;

            for (int y = 0; y < Matrix1x3.RowCount; y++)
            {
                for (int x = 0; x < Matrix1x3.ColumnCount; x++)
                {
                    Assert.AreEqual(1 + 99, result[x, y], Epsilon);
                }
            }
        }