/// <summary>
        /// An auxiliary method for testing the action of regular expressions.
        /// Limited to a single column, which should be sufficient for this purpose.
        /// Multiple rows are allowed to test the effect of one regex on several strings.
        /// </summary>
        private static void TestRegex(string regexStr, string[] stringsInit, string[] stringsExpect)
        {
            const string name = "Test";

            IMatrixData[]   supplTables       = null;
            IDocumentData[] documents         = null;
            List <string>   stringColumnNames = new List <string> {
                "Column Name"
            };
            List <string[]> stringColumnsInit = new List <string[]> {
                stringsInit
            };
            List <string[]> stringColumnsExpect = new List <string[]> {
                stringsExpect
            };
            Parameters param =
                new Parameters(new Parameter[] {
                new MultiChoiceParam("Columns", new[] { 0 })
                {
                    Values = stringColumnNames
                },
                new StringParam("Regular expression", regexStr), new BoolParam("Keep original columns", false),
                new BoolParam("Strings separated by semicolons are independent", false)
            });
            IMatrixData mdata = PerseusFactory.CreateNewMatrixData();

            mdata.Clear();
            mdata.Name = name;
            mdata.SetAnnotationColumns(stringColumnNames, stringColumnsInit, mdata.CategoryColumnNames, new List <string[][]>(),
                                       mdata.NumericColumnNames, mdata.NumericColumns, mdata.MultiNumericColumnNames, mdata.MultiNumericColumns);
            var ptc = new ProcessTextColumns();

            ptc.ProcessData(mdata, param, ref supplTables, ref documents, null);
            const bool ignoreCase = false;

            for (int rowInd = 0; rowInd < stringColumnsInit[0].Length; rowInd++)
            {
                Assert.AreEqual(mdata.StringColumns[0][rowInd], stringColumnsExpect[0][rowInd], ignoreCase);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// An auxiliary method for testing the action of regular expressions.
        /// Limited to a single column, which should be sufficient for this purpose.
        /// Multiple rows are allowed to test the effect of one regex on several strings.
        /// </summary>
        private static void TestRegex(string regexStr, string[] stringsInit, string[] stringsExpect)
        {
            const string name = "Test";

            IMatrixData[]   supplTables       = null;
            IDocumentData[] documents         = null;
            List <string>   stringColumnNames = new List <string> {
                "Column Name"
            };
            List <string[]> stringColumnsInit = new List <string[]> {
                stringsInit
            };
            List <string[]> stringColumnsExpect = new List <string[]> {
                stringsExpect
            };
            ProcessTextColumns ptc   = new ProcessTextColumns();
            IMatrixData        mdata = PerseusFactory.CreateMatrixData();

            mdata.Clear();
            mdata.Name = name;
            mdata.SetAnnotationColumns(stringColumnNames, stringColumnsInit, mdata.CategoryColumnNames, new List <string[][]>(),
                                       mdata.NumericColumnNames, mdata.NumericColumns, mdata.MultiNumericColumnNames, mdata.MultiNumericColumns);
            string     errorStr = string.Empty;
            Parameters param    = ptc.GetParameters(mdata, ref errorStr);

            param.GetParam <int[]>("Columns").Value              = new[] { 0 };
            param.GetParam <string>("Regular expression").Value  = regexStr;
            param.GetParam <bool>("Keep original columns").Value = false;
            param.GetParam <bool>("Strings separated by semicolons are independent").Value = false;
            ptc.ProcessData(mdata, param, ref supplTables, ref documents, null);
            for (int rowInd = 0; rowInd < stringColumnsInit[0].Length; rowInd++)
            {
                string expected = mdata.StringColumns[0][rowInd];
                string actual   = stringColumnsExpect[0][rowInd];
                StringAssert.AreEqualIgnoringCase(expected, actual);
            }
        }