public void ValidateRowKeysPairAnsiGetInstanceFromPairAnsiFileAccess() { ParallelOptions parOptObj = new ParallelOptions(); UOPair<char> uoPairObj = new UOPair<char>('?', '?'); DensePairAnsi dpaObj = DensePairAnsi.CreateEmptyInstance( new string[] { "R0", "R1", "R2" }, new string[] { "C0", "C1", "C2", "C3" }, uoPairObj); dpaObj.WriteDensePairAnsi(Constants.FastQTempTxtFileName, parOptObj); using (RowKeysPairAnsi rkaObj = RowKeysPairAnsi.GetInstanceFromPairAnsi( Constants.FastQTempTxtFileName, parOptObj, FileAccess.ReadWrite, FileShare.ReadWrite)) { Assert.AreEqual(4, rkaObj.ColCount); Assert.AreEqual(3, rkaObj.RowCount); } if (File.Exists(Constants.FastQTempTxtFileName)) File.Delete(Constants.FastQTempTxtFileName); Console.WriteLine( "RowKeysPairAnsi BVT : Validation of GetInstanceFromDenseAnsi(file-access) method successful"); ApplicationLog.WriteLine( "RowKeysPairAnsi BVT : Validation of GetInstanceFromDenseAnsi(file-access) method successful"); }
public void ValidateRowKeysPairAnsiGetInstanceFromRowKeysAnsiFileAccess() { DenseMatrix <string, string, double> denseMatObj = GetDenseMatrix(); ParallelOptions parOptObj = new ParallelOptions(); denseMatObj.WritePaddedDouble(Constants.FastQTempTxtFileName, parOptObj); using (RowKeysPaddedDouble rkpdObj = RowKeysPaddedDouble.GetInstanceFromPaddedDouble(Constants.FastQTempTxtFileName, parOptObj)) { rkpdObj.WriteRowKeys(Constants.KeysTempFile); } using (RowKeysPairAnsi rkaObj = RowKeysPairAnsi.GetInstanceFromRowKeysAnsi( Constants.KeysTempFile, parOptObj, FileAccess.ReadWrite, FileShare.ReadWrite)) { Assert.AreEqual(denseMatObj.ColCount, rkaObj.ColCount); Assert.AreEqual(denseMatObj.RowCount, rkaObj.RowCount); Assert.AreEqual(denseMatObj.RowKeys, rkaObj.RowKeys); Assert.AreEqual(denseMatObj.ColKeys, rkaObj.ColKeys); } if (File.Exists(Constants.FastQTempTxtFileName)) { File.Delete(Constants.FastQTempTxtFileName); } if (File.Exists(Constants.KeysTempFile)) { File.Delete(Constants.KeysTempFile); } Console.WriteLine( "RowKeysPairAnsi BVT : Validation of GetInstanceFromRowKeysAnsi(file-access) method successful"); ApplicationLog.WriteLine( "RowKeysPairAnsi BVT : Validation of GetInstanceFromRowKeysAnsi(file-access) method successful"); }
/// <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> public static 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); }