Ejemplo n.º 1
0
        public CaseModel Func_GetValue_SetValue()
        {
            return(new CaseModel()
            {
                NameSign = @"获取/设置值",
                ExeEvent = () => {
                    GS answer = new GS()
                    {
                        Age = RandomData.GetInt(),
                        DateOfBirth = RandomData.GetDateTime(),
                        Name = RandomData.GetChineseString(),
                        Price = RandomData.GetDouble(),
                        Sex = RandomData.Item(EnumInfo.GetALLItem <GS.SexEnum>()),
                    };

                    GS result = new GS();

                    ShineUponParser parser = new ShineUponParser(typeof(GS));
                    foreach (ShineUponInfo info in parser.GetDictionary().Values)
                    {
                        KeyString ks = parser.GetValue_KeyString(info, answer);
                        parser.SetValue_Object(info, result, ks.Value);
                    }

                    return true;
                },
            });
        }
Ejemplo n.º 2
0
        private XmlNode CreateRandomNode(XmlDocument xmldocument)
        {
            char[] ISBN_Sour = new List <char>(CommonData.ASCII_Number())
            {
                '-'
            }.ToArray();
            char[]     Ascii_words        = CommonData.ASCII_WordText();
            char[]     Ascii_lowerenglish = CommonData.ASCII_LowerEnglish();
            XmlElement book = xmldocument.CreateElement(@"book");
            Dictionary <string, string> Dic_Attrs = new Dictionary <string, string>()
            {
                { @"Type", RandomData.GetChineseString(2) + @"课" },
                { @"ISBN", RandomData.GetString(ISBN_Sour, RandomData.GetInt(4, 13)) }
            };

            foreach (KeyValuePair <string, string> item in Dic_Attrs)
            {
                book.SetAttributeNode(XmlHelper.CreateNewAttribute(xmldocument, item.Key, item.Value));
            }
            Dictionary <string, string> Dic_Nodes = new Dictionary <string, string>()
            {
                { @"title", RandomData.GetString(Ascii_words, RandomData.GetInt(4, 10)) },
                { @"author", RandomData.GetString(Ascii_lowerenglish, RandomData.GetInt(2, 4)) },
                { @"price", RandomData.GetDouble().ToString() },
            };

            foreach (KeyValuePair <string, string> item in Dic_Nodes)
            {
                book.AppendChild(XmlHelper.CreateNewElement(xmldocument, item.Key, item.Value));
            }
            return(book);
        }
 private CaseModel ExeEvent_Random_Double()
 {
     return(new CaseModel()
     {
         NameSign = @"随机 Double 值",
         ExeEvent = () => {
             for (int i = 0; i < 50; i++)
             {
                 Print.WriteLine(RandomData.GetDouble());
             }
         },
     });
 }
Ejemplo n.º 4
0
        protected override object MutateGene(PropertyInfo gene, int index, object originalValue, object suggestedRandomValue)
        {
            if (NumberHelper.TryGetValue(originalValue, out var value))
            {
                var addValue  = (value * ADD_RATE) * (decimal)RandomData.GetDouble(); // something around 10% (ADD_RATE), then a random fraction of it
                var shouldAdd = RandomData.GetBool();                                 // add or subtract

                var result = shouldAdd
                    ? value + addValue
                    : value - addValue;

                return(_options.IsInRange(result)
                    ? NumberHelper.CastValueToProperType(gene.PropertyType, result)
                    : suggestedRandomValue);
            }
            else
            {
                return(suggestedRandomValue);
            }
        }
 private static double GetDouble(int?min, int?max)
 {
     return((max.GetValueOrDefault(int.MaxValue) - min.GetValueOrDefault()) * RandomData.GetDouble() + min.GetValueOrDefault());
 }
 static FloatValueGenerator()
 {
     _generatorFunc = new Dictionary <Type, Func <int?, int?, object> >()
     {
         { typeof(float), (min, max) => HasRangeSet(min, max) ? (float)GetDouble(min, max) : (float)RandomData.GetDouble() * float.MaxValue },
         { typeof(float?), (min, max) => HasRangeSet(min, max) ? (float?)GetDouble(min, max) : (float?)RandomData.GetDouble() * float.MaxValue },
         { typeof(double), (min, max) => HasRangeSet(min, max) ? GetDouble(min, max) : RandomData.GetDouble() *double.MaxValue },
         { typeof(double?), (min, max) => HasRangeSet(min, max) ? GetDouble(min, max) : (double?)RandomData.GetDouble() * double.MaxValue },
         { typeof(decimal), (min, max) => HasRangeSet(min, max) ? (decimal)GetDouble(min, max) : (decimal)RandomData.GetDouble() * decimal.MaxValue },
         { typeof(decimal?), (min, max) => HasRangeSet(min, max) ? (decimal?)GetDouble(min, max) : (decimal?)RandomData.GetDouble() * decimal.MaxValue },
     };
 }