/// <summary> /// Generate a dataset of random members accepted by the regex /// </summary> /// <param name="regex">given regex</param> /// <param name="size">number of members</param> /// <param name="maxUnroll">maximum nr of times a loop is unrolled</param> /// <param name="cornerCaseProb">inverse of pobability of taking a corner case (lower/upper bound) of the number of iterations a loop may be unrolled.</param> /// <param name="charClassRestriction">restrict all generated members to this character class (null means no restriction)</param> /// <param name="maxSamplingIter">Maximum number of iterations in order to collect the requested number of samples</param> public static HashSet <string> GenerateRandomDataSet(this Regex regex, int size = 10, string charClassRestriction = null, int maxUnroll = 10, int cornerCaseProb = 5, int maxSamplingIter = 3) { var solver = new CharSetSolver(); var sr = solver.RegexConverter.ConvertToSymbolicRegex(regex); if (charClassRestriction != null) { sr = sr.Restrict(solver.MkCharSetFromRegexCharClass(charClassRestriction)); } var sampler = new SymbolicRegexSampler <BDD>(solver.RegexConverter.srBuilder, sr, maxUnroll, cornerCaseProb); return(sampler.GetPositiveDataset(size)); }
/// <summary> /// Generate a random member accepted by the regex /// </summary> /// <param name="regex">given regex</param> /// <param name="maxUnroll">maximum nr of times a loop is unrolled</param> /// <param name="cornerCaseProb">inverse of pobability of taking a corner case (lower/upper bound) of the number of iterations a loop may be unrolled.</param> /// <param name="charClassRestriction">restrict all generated members to this character class (null means no restriction)</param> public static string GenerateRandomMember(this Regex regex, string charClassRestriction = null, int maxUnroll = 10, int cornerCaseProb = 5) { var solver = new CharSetSolver(); var sr = solver.RegexConverter.ConvertToSymbolicRegex(regex); if (charClassRestriction != null) { sr = sr.Restrict(solver.MkCharSetFromRegexCharClass(charClassRestriction)); } var sampler = new SymbolicRegexSampler <BDD>(solver.RegexConverter.srBuilder, sr, maxUnroll, cornerCaseProb); return(sampler.GenerateRandomMember()); }