/// <summary> /// Preforms unit tests related to setting and reading value on all the built-in matrix types. /// </summary> /// <param name="doOutOfRangeTest">If true performs a test should throw a caught exception.</param> /// <param name="parallelOptions">A ParallelOptions instance that configures the multithreaded behavior of this operation.</param> static public void MainTest(bool doOutOfRangeTest, ParallelOptions parallelOptions) { //densematrix TestByKeysAndIndexes(() => CreateModelMatrix().ToDenseMatrix(), doOutOfRangeTest); //sparsematrix TestByKeysAndIndexes(() => CreateModelMatrix().ToSparseMatrix(), doOutOfRangeTest); //TransposeView TestByKeysAndIndexes(() => CreateModelMatrix().TransposeView().ToDenseMatrix().TransposeView(), doOutOfRangeTest); //ConvertValueView TestByKeysAndIndexes(() => CreateModelMatrix().ConvertValueView(ValueConverter.DoubleToInt, int.MaxValue).ToDenseMatrix().ConvertValueView(ValueConverter.IntToDouble, double.NaN), doOutOfRangeTest); //SelectRowsAndColsView TestByKeysAndIndexes(() => CreateModelMatrix().SelectRowsAndColsView(new int[] { 2, 1, 0 }, new int[] { 2, 1, 0 }).ToDenseMatrix().SelectRowsAndColsView(new int[] { 2, 1, 0 }, new int[] { 2, 1, 0 }), doOutOfRangeTest); //RenameColsView TestByKeysAndIndexes(() => CreateModelMatrix().RenameColsView(new Dictionary <string, string> { { "x", "X" }, { "y", "Y" }, { "z", "Z" } }).ToDenseMatrix().RenameColsView(new Dictionary <string, string> { { "X", "x" }, { "Y", "y" }, { "Z", "z" } }), doOutOfRangeTest); //PermuteColValuesForEachRowView TestByKeysAndIndexes(() => CreateModelMatrix().PermuteColValuesForEachRowView(new int[] { 2, 1, 0 }).ToDenseMatrix().PermuteColValuesForEachRowView(new int[] { 2, 1, 0 }), doOutOfRangeTest); //MergeColsView TestByKeysAndIndexes(() => CreateModelMatrix().SelectColsView(0).ToDenseMatrix().MergeColsView(/*rowsMustMatch*/ true, CreateModelMatrix().SelectColsView(1, 2).ToDenseMatrix()), doOutOfRangeTest); //MergeRowsView TestByKeysAndIndexes(() => CreateModelMatrix().SelectRowsView(0).ToDenseMatrix().MergeRowsView(/*colsMustMatch*/ true, CreateModelMatrix().SelectRowsView(1, 2).ToDenseMatrix()), doOutOfRangeTest); //rowkeyspaddeddouble TestByKeysAndIndexes(() => CreateModelMatrix().ToPaddedDouble(parallelOptions), doOutOfRangeTest); //rowkeysansi TestByKeysAndIndexes(() => CreateModelMatrix().ConvertValueView(ValueConverter.DoubleToChar, '?').ToDenseAnsi(parallelOptions).ConvertValueView(ValueConverter.CharToDouble, double.NaN), doOutOfRangeTest); //densepairansi ValueConverter <double, UOPair <char> > doubleToUOPairConvert = new ValueConverter <double, UOPair <char> >( r => new UOPair <char>(((int)r).ToString((IFormatProvider)null)[0], ((int)r).ToString((IFormatProvider)null)[0]), pair => double.Parse(pair.First.ToString((IFormatProvider)null), (IFormatProvider)null)); TestByKeysAndIndexes(() => CreateModelMatrix().ConvertValueView(doubleToUOPairConvert, DensePairAnsi.StaticMissingValue).ToDensePairAnsi(parallelOptions).ConvertValueView(doubleToUOPairConvert.Inverted, double.NaN), doOutOfRangeTest); //RowKeysPaddedDouble string paddedDoubleFile = Path.GetTempFileName(); CreateModelMatrix().WritePaddedDouble(paddedDoubleFile, parallelOptions); using (RowKeysPaddedDouble rowKeysPaddedDouble = RowKeysPaddedDouble.GetInstanceFromPaddedDouble(paddedDoubleFile, parallelOptions, FileAccess.ReadWrite, FileShare.ReadWrite)) { TestByKeys(rowKeysPaddedDouble, doOutOfRangeTest); } CreateModelMatrix().WritePaddedDouble(paddedDoubleFile, parallelOptions); using (RowKeysPaddedDouble rowKeysPaddedDouble = RowKeysPaddedDouble.GetInstanceFromPaddedDouble(paddedDoubleFile, parallelOptions, FileAccess.ReadWrite, FileShare.ReadWrite)) { TestByIndexes(rowKeysPaddedDouble, doOutOfRangeTest); } File.Delete(paddedDoubleFile); //RowKeysRowKeysAnsi string rowKeysAnsiFile = Path.GetTempFileName(); CreateModelMatrix().WriteDenseAnsi(rowKeysAnsiFile, parallelOptions); using (RowKeysAnsi rowKeysRowKeysAnsi = RowKeysAnsi.GetInstanceFromDenseAnsi(rowKeysAnsiFile, parallelOptions, FileAccess.ReadWrite, FileShare.ReadWrite)) { TestByKeys(rowKeysRowKeysAnsi.ConvertValueView(ValueConverter.CharToDouble, double.NaN), doOutOfRangeTest); } CreateModelMatrix().WriteDenseAnsi(rowKeysAnsiFile, parallelOptions); using (RowKeysAnsi rowKeysRowKeysAnsi = RowKeysAnsi.GetInstanceFromDenseAnsi(rowKeysAnsiFile, parallelOptions, FileAccess.ReadWrite, FileShare.ReadWrite)) { TestByIndexes(rowKeysRowKeysAnsi.ConvertValueView(ValueConverter.CharToDouble, double.NaN), doOutOfRangeTest); } File.Delete(rowKeysAnsiFile); //RowKeysRowKeysPairAnsi string rowKeysPairAnsiFile = Path.GetTempFileName(); CreateModelMatrix().ConvertValueView(doubleToUOPairConvert, DensePairAnsi.StaticMissingValue).WriteDensePairAnsi(rowKeysPairAnsiFile, parallelOptions); using (RowKeysPairAnsi rowKeysAnsiPair = RowKeysPairAnsi.GetInstanceFromPairAnsi(rowKeysPairAnsiFile, parallelOptions, FileAccess.ReadWrite, FileShare.ReadWrite)) { TestByKeys(rowKeysAnsiPair.ConvertValueView(doubleToUOPairConvert.Inverted, double.NaN), doOutOfRangeTest); } CreateModelMatrix().ConvertValueView(doubleToUOPairConvert, DensePairAnsi.StaticMissingValue).WriteDensePairAnsi(rowKeysPairAnsiFile, parallelOptions); using (RowKeysPairAnsi rowKeysRowKeysAnsi = RowKeysPairAnsi.GetInstanceFromPairAnsi(rowKeysPairAnsiFile, parallelOptions, FileAccess.ReadWrite, FileShare.ReadWrite)) { TestByIndexes(rowKeysRowKeysAnsi.ConvertValueView(doubleToUOPairConvert.Inverted, double.NaN), doOutOfRangeTest); } File.Delete(rowKeysPairAnsiFile); }