当前位置: 首页>>代码示例>>C#>>正文


C# CharSetSolver.GenerateMember方法代码示例

本文整理汇总了C#中CharSetSolver.GenerateMember方法的典型用法代码示例。如果您正苦于以下问题:C# CharSetSolver.GenerateMember方法的具体用法?C# CharSetSolver.GenerateMember怎么用?C# CharSetSolver.GenerateMember使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CharSetSolver的用法示例。


在下文中一共展示了CharSetSolver.GenerateMember方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestRegex

        static void TestRegex(Regex regex)
        {
            var solver = new CharSetSolver();
            string myregex = regex.ToString();

            //Regex.CompileToAssembly(new RegexCompilationInfo[] { new RegexCompilationInfo(myregex, RegexOptions.None, "EvilRegex", "RegexTransfomer", true) },
            //    new System.Reflection.AssemblyName("EvilRegex"));

            var sfa = solver.Convert(myregex, regex.Options).RemoveEpsilons();
            var sfaDet = sfa.Determinize();
            var sfaMin = sfaDet.Minimize();

            //solver.ShowGraph(sfa, "sfa");
            //solver.ShowGraph(sfaDet, "sfaDet");
            //solver.ShowGraph(sfaMin, "sfaMin");

            var cs = solver.ToCS(sfaMin, true, "MyRegex", "RegexTransfomer");

            var regexMin = solver.ConvertToRegex(sfaMin);

            Console.WriteLine("------- given regex --------");
            Console.WriteLine(myregex);
            Console.WriteLine("----------------------------");

            Console.WriteLine("-------- regexMin ----------");
            Console.WriteLine(regexMin);
            Console.WriteLine("----------------------------");

            Console.WriteLine("-------- cs ----------------");
            Console.WriteLine(cs.SourceCode);
            Console.WriteLine("----------------------------");

            string sIn = solver.GenerateMember(sfaMin);
            string sOut = solver.GenerateMember(sfaMin.Complement());
            string s = sIn;
            int t1;
            int t2;
            int t3;
            for (int i = 0; i < 2; i++)
            {
                //original regex
                t1 = System.Environment.TickCount;
                bool res1 = false;
                for (int j = 0; j < 100000; j++)
                    res1 = Regex.IsMatch(s, regex.ToString(), regex.Options);
                //res1 = evilregex.IsMatch(s);
                t1 = System.Environment.TickCount - t1;

                ////minimized regex
                //t2 = System.Environment.TickCount;
                //bool res2 = false;
                //for (int j = 0; j < 100000; j++)
                //    res2 = Regex.IsMatch(s, regexMin, regex.Options);
                //t2 = System.Environment.TickCount - t2;

                //code from minimized regex
                t3 = System.Environment.TickCount;
                bool res3 = false;
                for (int j = 0; j < 100000; j++)
                    res3 = cs.IsMatch(s);
                t3 = System.Environment.TickCount - t3;
                Console.WriteLine(String.Format("{0}ms({1}), {2}ms({3})", t1, res1, t3, res3));
                s = sOut;
            }
            Console.WriteLine("done...(press any key)");
            Console.ReadKey();
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:67,代码来源:CodeGenTests.cs

示例2: CheckValidity

        void CheckValidity(CharSetSolver css, Automaton<BDD> aut, Regex regex)
        {
            if (!aut.IsEmpty)
                for (int i = 0; i < 1000; i++)
                {
                    var str = css.GenerateMember(aut);
                    if (!str.Contains("\u200C") && !str.Contains("\u200D") && !str.Contains("\n"))
                        Assert.IsTrue(regex.IsMatch(str), str);
                }

            var aut_compl = aut.Complement().Minimize();
            if (!aut_compl.IsEmpty)
                for (int i = 0; i < 1000; i++)
                {
                    var str = css.GenerateMember(aut_compl);
                    if (!str.Contains("\u200C") && !str.Contains("\u200D") && !str.Contains("\n"))
                        if (regex.IsMatch(str))
                            Assert.IsFalse(true, regex + ":" + StringUtility.Escape(str));
                }
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:20,代码来源:MiscRegexConversionTests.cs

示例3: TestGeneratedCssEncodePerformance

        public void TestGeneratedCssEncodePerformance()
        {
            CharSetSolver css = new CharSetSolver(BitWidth.BV16);
            var A = css.Convert("^.{100,}$"); //at least 50 chars
            var utf16 = css.Convert(@"^([\0-\uD7FF\uE000-\uFFFD]|([\uD800-\uDBFF][\uDC00-\uDFFF]))*$");
            A = A.Intersect(utf16);
            //css.Chooser.RandomSeed = 123;
            List<string> samples = new List<string>();
            //construct a sample set of 100000 strings of length >= 50 that are valid inputs
            while (samples.Count < 100)
            {
                string input = css.GenerateMember(A);//margus
                samples.Add(input);
               // if (TryActualCssEncode(input, out tmp) == 0)
               //     samples.Add(input);
            }
            //now use the sample set for performace comparison

            var antiXssTimes = new List<int>();
            var CssEncodeTimes = new List<int>();
            var CssEncodeTimes_B = new List<int>();
            var CssEncodeTimes_F = new List<int>();

            int NrOfReps = 100;

            for (int j = 0; j < NrOfReps; j++)
            {
                //the AntiXss encoder
                int t_AntiXss = System.Environment.TickCount;
                for (int i = 0; i < samples.Count; i++)
                {
                    string tmp = System.Web.Security.AntiXss.AntiXssEncoder.CssEncode(samples[i]);
                }
                t_AntiXss = System.Environment.TickCount - t_AntiXss;
                antiXssTimes.Add(t_AntiXss);
                //generated encoder without exploration
                int t_CssEncode = System.Environment.TickCount;
                for (int i = 0; i < samples.Count; i++)
                {
                    string tmp = CssEncode.Apply(samples[i]);
                }
                t_CssEncode = System.Environment.TickCount - t_CssEncode;
                CssEncodeTimes.Add(t_CssEncode);
                //generated encoder with Boolean exploration
                int t_CssEncode_B = System.Environment.TickCount;
                for (int i = 0; i < samples.Count; i++)
                {
                    string tmp = CssEncode_B.Apply(samples[i]);
                }
                t_CssEncode_B = System.Environment.TickCount - t_CssEncode_B;
                CssEncodeTimes_B.Add(t_CssEncode_B);
                //generated encoder with Full exploration
                int t_CssEncode_F = System.Environment.TickCount;
                for (int i = 0; i < samples.Count; i++)
                {
                    string tmp = CssEncode_F.Apply(samples[i]);
                }
                t_CssEncode_F = System.Environment.TickCount - t_CssEncode_F;
                CssEncodeTimes_F.Add(t_CssEncode_F);
            }
            //compute the average times
            int antiXssTime = ComputeAverage(antiXssTimes);
            int CssEncodeTime = ComputeAverage(CssEncodeTimes);
            int CssEncodeTime_B = ComputeAverage(CssEncodeTimes_B);
            int CssEncodeTime_F = ComputeAverage(CssEncodeTimes_F);

            double[] stdevs = CombinedStandardDeviation(antiXssTimes, CssEncodeTimes, CssEncodeTimes_B, CssEncodeTimes_F);
            Console.WriteLine("antiXssTime={0}, CssEncodeTime={1}, CssEncodeTime_B={2}, CssEncodeTime_F={3}, stddvAntiXSS={4}, stddvCssEncode={5}, stddvCssEncodeB={6}, stddvCssEncodeF={7}",
                               antiXssTime, CssEncodeTime, CssEncodeTime_B, CssEncodeTime_F, stdevs[0], stdevs[1], stdevs[2], stdevs[3]);
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:70,代码来源:Bek2Tests.cs

示例4: TestGeneratedUtf8EncodeFlat

        public void TestGeneratedUtf8EncodeFlat()
        {
            int K = 100; //number of strings
            int L = 10000; //length of each string

            string _1;
            string _2;
            string _3;
            TryGeneratedUtf8EncodeFlat("\uDAE1\uDCA5", out _1);
            TryGeneratedUtf8Encode_F("\uDAE1\uDCA5", out _2);
            TryActualUtf8Encode("\uDAE1\uDCA5", out _3);

            Assert.AreEqual<string>(_1, _2);
            Assert.AreEqual<string>(_1, _3);

            CharSetSolver css = new CharSetSolver(BitWidth.BV16);
            var A = css.Convert("^.{" + L + "}$");
            //var utf16 = css.Convert(@"^([\0-\uD7FF\uE000-\uFFFD]|([\uD800-\uDBFF][\uDC00-\uDFFF]))*$");
            //var utf16 = css.Convert(@"^([\uD800-\uDBFF][\uDC00-\uDFFF])*$");
            var utf16 = css.Convert(@"^([\0-\uD7FF\uE000-\uFFFD])*$");
            A = Automaton<BDD>.MkProduct(A, utf16);

            //css.Chooser.RandomSeed = 123;

            string[] inputs = new string[K];

            for (int i = 0; i < K; i++)
            {
                inputs[i] = css.GenerateMember(A);
            }

            for (int i = 0; i < K; i++)
            {
                string out_expected;
                string out_bek;
                string out_bek_stream;
                string out_bek_orig;
                int stat_expected = TryActualUtf8Encode(inputs[i], out out_expected);
                int stat_actual = TryGeneratedUtf8EncodeFlat(inputs[i], out out_bek);
                int stat_actual_stream = TryGeneratedUtf8EncodeStream(inputs[i], out out_bek_stream);
                int stat_actual_orig = TryGeneratedUtf8Encode_F(inputs[i], out out_bek_orig);
                Assert.AreEqual<string>(out_expected, out_bek_orig);
                Assert.AreEqual<string>(out_expected, out_bek);
                Assert.AreEqual<string>(out_expected, out_bek_stream);
            }

            int timeOur = System.Environment.TickCount;
            for (int i = 0; i < K; i++)
            {
                string tmp;
                TryGeneratedUtf8EncodeFlat(inputs[i], out tmp);
            }
            timeOur = System.Environment.TickCount - timeOur;

            int timeOurStream = System.Environment.TickCount;
            for (int i = 0; i < K; i++)
            {
                string tmp;
                TryGeneratedUtf8EncodeStream(inputs[i], out tmp);
            }
            timeOurStream = System.Environment.TickCount - timeOurStream;

            int timeOurOrig = System.Environment.TickCount;
            for (int i = 0; i < K; i++)
            {
                string tmp;
                TryGeneratedUtf8Encode(inputs[i], out tmp);
            }
            timeOurOrig = System.Environment.TickCount - timeOurOrig;

            int timeSys = System.Environment.TickCount;
            for (int i = 0; i < K; i++)
            {
                string tmp;
                TryActualUtf8Encode(inputs[i], out tmp);
            }
            timeSys = System.Environment.TickCount - timeSys;

            Console.WriteLine("timeOurStream:{3}ms, timeOur:{0}ms, timeOurOrig:{1}ms, timeSys:{2}ms", timeOur, timeOurOrig, timeSys, timeOurStream);
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:80,代码来源:Bek2Tests.cs

示例5: TestGeneratedCssEncode

 public void TestGeneratedCssEncode()
 {
     CharSetSolver css = new CharSetSolver(BitWidth.BV16);
     var A = css.Convert(".{50,}"); //at least 100 characters
     var utf16 = css.Convert(@"^([\0-\uD7FF\uE000-\uFFFD]|([\uD800-\uDBFF][\uDC00-\uDFFF]))*$");
     A = A.Intersect(utf16);
     //css.Chooser.RandomSeed = 123;
     int okCnt = 0;
     int error1Cnt = 0;
     int error2Cnt = 0;
     int diffErrors = 0;
     for (int i = 0; i < 1000; i++)
     {
         string input = css.GenerateMember(A);
         string out_expected;
         string out_CssEncode;
         string out_CssEncode_B;
         string out_CssEncode_F;
         int stat_expected = TryActualCssEncode(input, out out_expected);
         int stat_CssEncode = TryGeneratedCssEncode(input, out out_CssEncode);
         int stat_CssEncode_B = TryGeneratedCssEncode_B(input, out out_CssEncode_B);
         int stat_CssEncode_F = TryGeneratedCssEncode_F(input, out out_CssEncode_F);
         Assert.AreEqual<string>(out_expected, out_CssEncode);
         Assert.AreEqual<string>(out_expected, out_CssEncode_B);
         Assert.AreEqual<string>(out_expected, out_CssEncode_F);
         Assert.AreEqual<int>(stat_CssEncode, stat_CssEncode_B);
         Assert.AreEqual<int>(stat_CssEncode, stat_CssEncode_F);
         if (stat_expected != stat_CssEncode)
             diffErrors += 1;
         if (stat_expected == 0)
             okCnt += 1;
         else if (stat_expected == 1)
             error1Cnt += 1;
         else
             error2Cnt += 1;
     }
     Console.WriteLine("okCnt={0}, error1Cnt={1}, error2Cnt={2}, diffErrors={3}", okCnt, error1Cnt, error2Cnt, diffErrors);
 }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:38,代码来源:Bek2Tests.cs


注:本文中的CharSetSolver.GenerateMember方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。