From 5bfb1079cc40d893b7014608b0ef9cc6137a7af0 Mon Sep 17 00:00:00 2001 From: Ivan Matantsev Date: Thu, 25 Oct 2018 17:09:34 -0700 Subject: [PATCH 1/3] move regex to right place to reduce test time --- test/Microsoft.ML.TestFramework/BaseTestBaseline.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/test/Microsoft.ML.TestFramework/BaseTestBaseline.cs b/test/Microsoft.ML.TestFramework/BaseTestBaseline.cs index 55bd13a328..40caa92dda 100644 --- a/test/Microsoft.ML.TestFramework/BaseTestBaseline.cs +++ b/test/Microsoft.ML.TestFramework/BaseTestBaseline.cs @@ -59,6 +59,7 @@ protected BaseTestBaseline(ITestOutputHelper output) : base(output) private const string OutputRootUnixRegExp = @"\/[^\\\t ]+\/TestOutput" + @"\/[^\\\t ]+"; private static readonly string BinRegUnixExp = @"\/[^\\\t ]+\/bin\/" + Mode; private static readonly string Bin64RegUnixExp = @"\/[^\\\t ]+\/bin\/x64\/" + Mode; + private static readonly Regex MatchNumbers = new Regex(@"\b[0-9]+\.?[0-9]*(E-[0-9]*)?\b", RegexOptions.IgnoreCase | RegexOptions.Compiled); /// /// When the progress log is appended to the end of output (in test runs), this line precedes the progress log. @@ -506,16 +507,14 @@ protected bool CheckEqualityFromPathsCore(string relPath, string basePath, strin private void GetNumbersFromFile(ref string firstString, ref string secondString, int digitsOfPrecision) { - // The Regex matches both positive and negative decimal point numbers present in a string. - // The numbers could be a part of a word. They can also be in Exponential form eg. 3E-9 - Regex _matchNumer = new Regex(@"-?\b[0-9]+\.?[0-9]*(E-[0-9]*)?\b", RegexOptions.IgnoreCase | RegexOptions.Compiled); - MatchCollection firstCollection = _matchNumer.Matches(firstString); - MatchCollection secondCollection = _matchNumer.Matches(secondString); + + MatchCollection firstCollection = MatchNumbers.Matches(firstString); + MatchCollection secondCollection = MatchNumbers.Matches(secondString); if (firstCollection.Count == secondCollection.Count) MatchNumberWithTolerance(firstCollection, secondCollection, digitsOfPrecision); - firstString = _matchNumer.Replace(firstString, "%Number%"); - secondString = _matchNumer.Replace(secondString, "%Number%"); + firstString = MatchNumbers.Replace(firstString, "%Number%"); + secondString = MatchNumbers.Replace(secondString, "%Number%"); } private void MatchNumberWithTolerance(MatchCollection firstCollection, MatchCollection secondCollection, int digitsOfPrecision) From ca276be367fffc58692cacd1ee9f3db52d3306e0 Mon Sep 17 00:00:00 2001 From: Ivan Matantsev Date: Thu, 25 Oct 2018 17:25:03 -0700 Subject: [PATCH 2/3] proper regex --- test/Microsoft.ML.TestFramework/BaseTestBaseline.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.ML.TestFramework/BaseTestBaseline.cs b/test/Microsoft.ML.TestFramework/BaseTestBaseline.cs index 40caa92dda..07846101d5 100644 --- a/test/Microsoft.ML.TestFramework/BaseTestBaseline.cs +++ b/test/Microsoft.ML.TestFramework/BaseTestBaseline.cs @@ -59,7 +59,7 @@ protected BaseTestBaseline(ITestOutputHelper output) : base(output) private const string OutputRootUnixRegExp = @"\/[^\\\t ]+\/TestOutput" + @"\/[^\\\t ]+"; private static readonly string BinRegUnixExp = @"\/[^\\\t ]+\/bin\/" + Mode; private static readonly string Bin64RegUnixExp = @"\/[^\\\t ]+\/bin\/x64\/" + Mode; - private static readonly Regex MatchNumbers = new Regex(@"\b[0-9]+\.?[0-9]*(E-[0-9]*)?\b", RegexOptions.IgnoreCase | RegexOptions.Compiled); + private static readonly Regex MatchNumbers = new Regex(@"-?\b[0-9]+\.?[0-9]*(E-[0-9]*)?\b", RegexOptions.IgnoreCase | RegexOptions.Compiled); /// /// When the progress log is appended to the end of output (in test runs), this line precedes the progress log. From 152833d7efe15c42b3176fec1a9774640899c1f1 Mon Sep 17 00:00:00 2001 From: Ivan Matantsev Date: Thu, 25 Oct 2018 17:25:44 -0700 Subject: [PATCH 3/3] and comments --- test/Microsoft.ML.TestFramework/BaseTestBaseline.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/Microsoft.ML.TestFramework/BaseTestBaseline.cs b/test/Microsoft.ML.TestFramework/BaseTestBaseline.cs index 07846101d5..0102f8d4e4 100644 --- a/test/Microsoft.ML.TestFramework/BaseTestBaseline.cs +++ b/test/Microsoft.ML.TestFramework/BaseTestBaseline.cs @@ -59,6 +59,8 @@ protected BaseTestBaseline(ITestOutputHelper output) : base(output) private const string OutputRootUnixRegExp = @"\/[^\\\t ]+\/TestOutput" + @"\/[^\\\t ]+"; private static readonly string BinRegUnixExp = @"\/[^\\\t ]+\/bin\/" + Mode; private static readonly string Bin64RegUnixExp = @"\/[^\\\t ]+\/bin\/x64\/" + Mode; + // The Regex matches both positive and negative decimal point numbers present in a string. + // The numbers could be a part of a word. They can also be in Exponential form eg. 3E-9 private static readonly Regex MatchNumbers = new Regex(@"-?\b[0-9]+\.?[0-9]*(E-[0-9]*)?\b", RegexOptions.IgnoreCase | RegexOptions.Compiled); ///