DataSharp/Mathematics/UnitTest.cs
/// <summary>
/// Unit test method for the Vector class.
/// </summary>
Unit test method for the Vector class.
Unit test method for the Vector class .
public static void VectorTest()
        {
            double[] values = { 1.1, 2.2, 3.3, 4.4, 5.5 };
            Vector v1 = new Vector(values);
            Vector v2 = new Vector(v1);
            v2 = v2 - 1;
            Console.WriteLine($"v1 = {v1}");
            Console.WriteLine($"v2 = {v2}");
            Console.WriteLine();
            Console.WriteLine($"The sub-vector with range [1, 3] of v1 is {v1.GetSubVector(1, 3)}\n");
            Console.WriteLine($"v1 + 3 = {v1 + 3}");
            Console.WriteLine($"5 + v1 = {5 + v1}");
            Console.WriteLine($"v1 + v2 = {v1 + v2}");
            Console.WriteLine();
            Console.WriteLine($"v1 - 1 = {v1 - 1}");
            Console.WriteLine($"5 - v1 = {5 - v1}");
            Console.WriteLine($"v1 - v2 = {v1 - v2}");
            Console.WriteLine();
            Console.WriteLine($"v1 * 2 = {v1 * 2}");
            Console.WriteLine($"3 * v1 = {3 * v1}");
            Console.WriteLine($"v1 * v2 = {v1 * v2}");
            Console.WriteLine();
            Console.WriteLine($"v1 / 0.5 = {v1 / 0.5}");
            Console.WriteLine();
            Vector v3 = new Vector(new double[] { 1, 1 });
            Console.WriteLine($"v3 = {v3}");
            Console.WriteLine($"After normalization, v3 = {v3.Normalize()}");
            Console.WriteLine();
            Console.WriteLine($"Sum of v1 = {v1.SumComponents()}");
            Console.WriteLine($"Sum of squared components of v1 = {v1.SumSquaredComponents()}");
            Vector v4 = new Vector(1, 2, 3, 4, 5);
            Vector v5 = new Vector(2, 7, 5);
            Console.WriteLine($"Vector v4 = {v4}");
            Console.WriteLine($"Vector v5 = {v5}");
            Console.WriteLine($"The convolution of v4 * V5 = {Vector.ComputeConvolution(v4, v5)}");
            Console.WriteLine($"The correlation of v4 * v5 = {Vector.ComputeCorrelation(v4, v5)}");
            Console.WriteLine($"The element-wise product of v1 .* v4 = {Vector.ElementWiseMultiplication(v1,v4)}");
            Console.WriteLine($"Tile v5 to a 3 * 4 matrix where v5 is a row vector:\n{v5.Tile(4, 1)}");
            Console.WriteLine($"Tile v5 to a 6 * 2 matrix where v5 is a column vector:\n{v5.Tile(2, 2, false)}");
        }
public static void VectorTest ( ) { double [ ] values = { 1.1 , 2.2 , 3.3 , 4.4 , 5.5 } ; Vector v1 = new Vector ( values ) ; Vector v2 = new Vector ( v1 ) ; v2 = v2 - 1 ; Console . WriteLine ( $" v1 =  { v1 } " ) ; Console . WriteLine ( $" v2 =  { v2 } " ) ; Console . WriteLine ( ) ; Console . WriteLine ( $" The sub-vector with range [1, 3] of v1 is  { v1 . GetSubVector ( 1 , 3 ) } \n " ) ; Console . WriteLine ( $" v1 + 3 =  { v1 + 3 } " ) ; Console . WriteLine ( $" 5 + v1 =  { 5 + v1 } " ) ; Console . WriteLine ( $" v1 + v2 =  { v1 + v2 } " ) ; Console . WriteLine ( ) ; Console . WriteLine ( $" v1 - 1 =  { v1 - 1 } " ) ; Console . WriteLine ( $" 5 - v1 =  { 5 - v1 } " ) ; Console . WriteLine ( $" v1 - v2 =  { v1 - v2 } " ) ; Console . WriteLine ( ) ; Console . WriteLine ( $" v1 * 2 =  { v1 * 2 } " ) ; Console . WriteLine ( $" 3 * v1 =  { 3 * v1 } " ) ; Console . WriteLine ( $" v1 * v2 =  { v1 * v2 } " ) ; Console . WriteLine ( ) ; Console . WriteLine ( $" v1 / 0.5 =  { v1 / 0.5 } " ) ; Console . WriteLine ( ) ; Vector v3 = new Vector ( new double [ ] { 1 , 1 } ) ; Console . WriteLine ( $" v3 =  { v3 } " ) ; Console . WriteLine ( $" After normalization, v3 =  { v3 . Normalize ( ) } " ) ; Console . WriteLine ( ) ; Console . WriteLine ( $" Sum of v1 =  { v1 . SumComponents ( ) } " ) ; Console . WriteLine ( $" Sum of squared components of v1 =  { v1 . SumSquaredComponents ( ) } " ) ; Vector v4 = new Vector ( 1 , 2 , 3 , 4 , 5 ) ; Vector v5 = new Vector ( 2 , 7 , 5 ) ; Console . WriteLine ( $" Vector v4 =  { v4 } " ) ; Console . WriteLine ( $" Vector v5 =  { v5 } " ) ; Console . WriteLine ( $" The convolution of v4 * V5 =  { Vector . ComputeConvolution ( v4 , v5 ) } " ) ; Console . WriteLine ( $" The correlation of v4 * v5 =  { Vector . ComputeCorrelation ( v4 , v5 ) } " ) ; Console . WriteLine ( $" The element-wise product of v1 .* v4 =  { Vector . ElementWiseMultiplication ( v1 , v4 ) } " ) ; Console . WriteLine ( $" Tile v5 to a 3 * 4 matrix where v5 is a row vector: \n { v5 . Tile ( 4 , 1 ) } " ) ; Console . WriteLine ( $" Tile v5 to a 6 * 2 matrix where v5 is a column vector: \n { v5 . Tile ( 2 , 2 , false ) } " ) ; }
Unit test method for the Vector class.
Unit test method for the Vector class .