TValue IList <TValue> .this[int colIndex]
 {
     get
     {
         return(Matrix.GetValueOrMissing(RowIndex, colIndex));
     }
     set
     {
         Matrix.SetValueOrMissing(RowIndex, colIndex, value);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Do a series of unit tests in which the matrix is access by rowIndex and colIndex.
        /// </summary>
        /// <param name="matrix">The matrix to test. It should have the values of the matrix from CreateModelMatrix()</param>
        /// <param name="doOutOfRangeTest">If true, does a test that throws and catches an exception related to being out of bounds.</param>
        public static void TestByIndexes(Matrix <string, string, double> matrix, bool doOutOfRangeTest)
        {
            //Loop for index and keys
            //Get the missing value
            double missingValue = matrix.MissingValue;
            //TryGetValue - true
            double valueAX;

            Helper.CheckCondition(matrix.TryGetValue(0, 0, out valueAX) && valueAX == 1);
            //TryGetValue - false
            double valueCZ;

            Helper.CheckCondition(!matrix.TryGetValue(2, 2, out valueCZ) && matrix.IsMissing(valueCZ));


            //TryGetValue that is not in range should throw some exception
            if (doOutOfRangeTest)
            {
                try
                {
                    double valueDW;
                    matrix.TryGetValue(3, 3, out valueDW);
                    Helper.CheckCondition(false);
                }
                catch (Exception)
                {
                }
            }

            //SetValueOrMissing - value -> value
            matrix.SetValueOrMissing(0, 0, 6);
            Helper.CheckCondition(matrix.TryGetValue(0, 0, out valueAX) && valueAX == 6);
            //SetValueOrMissing - value -> missing
            matrix.SetValueOrMissing(0, 0, double.NaN);
            Helper.CheckCondition(!matrix.TryGetValue(0, 0, out valueAX));
            //SetValueOrMissing - missing -> value
            matrix.SetValueOrMissing(0, 0, 7);
            Helper.CheckCondition(matrix.TryGetValue(0, 0, out valueAX) && valueAX == 7);
            //SetValueOrMissing - missing -> missing
            matrix.SetValueOrMissing(2, 2, double.NaN);
            Helper.CheckCondition(!matrix.TryGetValue(2, 2, out valueCZ));
            //Remove - true
            Helper.CheckCondition(matrix.Remove(0, 0));
            //Remove - false
            Helper.CheckCondition(!matrix.Remove(0, 0));
            //this get value
            Helper.CheckCondition(2 == matrix[0, 1]);
            //this set to value
            matrix[0, 1] = 8;
            Helper.CheckCondition(8 == matrix[0, 1]);
            //this get missing - expect error
            try
            {
                double valueCX = matrix[2, 0];
                Helper.CheckCondition(false);
            }
            catch (Exception)
            {
            }

            //this set to missing - expect error
            try
            {
                matrix[0, 0] = double.NaN;
                Helper.CheckCondition(false);
            }
            catch (Exception)
            {
            }
        }