예제 #1
0
        public void BoolGenerator_Value_ProvidesSequenceOfBooleanValues()
        {
            Random        random  = new Random(200);
            BoolGenerator boolGen = new BoolGenerator(random);

            Assert.IsFalse(boolGen.Value());
            Assert.IsTrue(boolGen.Value());
            Assert.IsTrue(boolGen.Value());
            Assert.IsFalse(boolGen.Value());
            Assert.IsTrue(boolGen.Value());
        }
예제 #2
0
        public GeneratePostsIterator(Session session, int seed = 0, int quantity = 100)
        {
            Session  = session;
            Seed     = seed;
            Quantity = quantity;

            Random random = Seed != 0 ? new Random(Seed) : new Random();

            ThreeGen     = new IntegerGenerator(random, 1, 3);
            SixGen       = new IntegerGenerator(random, 1, 6);
            StrLenGen    = new IntegerGenerator(random, 1, 40);
            UpcharGen    = new CharGenerator(random, 'A', 'Z');
            DowncharGen  = new CharGenerator(random, 'a', 'z');
            NumcharGen   = new CharGenerator(random, '0', '9');
            TruthGen     = new BoolGenerator(random);
            NegNumberGen = new DoubleGenerator(random, -10000, -1);
            PosNumberGen = new DoubleGenerator(random, 1, 10000);
            YearGen      = new IntegerGenerator(random, 1900, 2300);
            MonGen       = new IntegerGenerator(random, 1, 12);
            DayGen       = new IntegerGenerator(random, 1, 28);

            NextDate    = TimesCommon.Current.ParseDate(GenerateDate());
            NextAuxDate = TimesCommon.Current.ParseDate(GenerateDate());
        }
예제 #3
0
 public BoolMonitor(string name, BoolGenerator generator, float displayTimeout = 0.5f)
 {
     m_name           = name;
     m_generator      = generator;
     m_displayTimeout = displayTimeout;
 }
예제 #4
0
        /// <summary>
        /// A factory for returning the appropriate generator
        /// </summary>
        /// <param name="thisCustomAttribute">The decoration defining the generator</param>
        /// <param name="thisPropInfo">The reflected values of the property</param>
        /// <returns>IRandomGenerator</returns>
        private IDataGenerator GetGenerator(CustomAttributeData thisCustomAttribute, PropertyInfo thisPropInfo)
        {
            IDataGenerator generator = null;

            switch (thisCustomAttribute.AttributeType.Name)
            {
            case "IntegerGenerator":
                generator = new IntegerGenerator();
                break;

            case "SingleGenerator":
                generator = new SingleGenerator();
                break;

            case "SingleRangeGenerator":
                generator = GetPropertyInfoAttribute <SingleRangeGenerator>(thisPropInfo);
                if (generator == null)
                {
                    generator = new DoubleRangeGenerator(Single.MinValue, Single.MaxValue);
                }
                break;

            case "DoubleGenerator":
                generator = new DoubleGenerator();
                break;

            case "NormallyDistributedDoubleGenerator":
                generator = GetPropertyInfoAttribute <NormallyDistributedDoubleGenerator>(thisPropInfo);
                if (generator == null)
                {
                    generator = new NormallyDistributedDoubleGenerator(0, 1);
                }
                break;

            case "DoubleRangeGenerator":
                generator = GetPropertyInfoAttribute <DoubleRangeGenerator>(thisPropInfo);
                if (generator == null)
                {
                    generator = new DoubleRangeGenerator(double.MinValue, double.MaxValue);
                }
                break;

            case "BoolGenerator":
                generator = new BoolGenerator();
                break;

            case "IntegerRangeGenerator":
                generator = GetPropertyInfoAttribute <IntegerRangeGenerator>(thisPropInfo);
                if (generator == null)
                {
                    generator = new IntegerRangeGenerator(int.MinValue, int.MaxValue);
                }
                break;

            case "StringRangeGenerator":
                generator = GetPropertyInfoAttribute <StringRangeGenerator>(thisPropInfo);
                if (generator == null)
                {
                    generator = new StringRangeGenerator(new string[] { "" });
                }
                break;

            case "DateRangeGenerator":
                generator = GetPropertyInfoAttribute <DateRangeGenerator>(thisPropInfo);
                if (generator == null)
                {
                    generator = new DateRangeGenerator(DateTime.MinValue, DateTime.MaxValue);
                }
                break;

            case "StringFromFileGenerator":
                string pathAsKey = thisCustomAttribute.ConstructorArguments.First().ToString();
                // this is a cached generator, stored for the sake of not having to re-process the file
                if (cacheGenerators.ContainsKey(pathAsKey))
                {
                    generator = cacheGenerators[pathAsKey];
                }
                else
                {
                    // process the gerneator
                    generator = GetPropertyInfoAttribute <StringFromFileGenerator>(thisPropInfo);
                    // add to a cache
                    cacheGenerators.Add(pathAsKey, generator);
                }
                if (generator == null)
                {
                    generator = new StringRangeGenerator(new string[] { "" });
                }
                break;

            case "IntegerSequenceGenerator":
                var key = thisPropInfo.Name + "/" + thisCustomAttribute.AttributeType.Name;
                if (cacheGenerators.ContainsKey(key))
                {
                    generator = cacheGenerators[key];
                }
                else
                {
                    // process the gerneator
                    generator = GetPropertyInfoAttribute <IntegerSequenceGenerator>(thisPropInfo);
                    // add to a cache
                    cacheGenerators.Add(key, generator);
                }
                if (generator == null)
                {
                    generator = new IntegerSequenceGenerator();
                }
                break;

            case "DecimalGenerator":
                generator = new DecimalGenerator();
                break;

            case "DecimalRangeGenerator":
                generator = GetPropertyInfoAttribute <DecimalRangeGenerator>(thisPropInfo);
                if (generator == null)
                {
                    generator = new DecimalRangeGenerator(double.MinValue, double.MaxValue);
                }
                break;

            default:
                break;
            }

            return(generator);
        }