Exemple #1
0
        public static string Text(int minSize, int maxSize)
        {
            maxSize = Math.Max(minSize, maxSize);
            int size = RandomInteger.NextInteger(minSize, maxSize);

            StringBuilder result = new StringBuilder();

            result.Append(RandomString.Pick(_allWords));

            while (result.Length < size)
            {
                String next = RandomString.Pick(_allWords);
                if (RandomBoolean.Chance(4, 6))
                {
                    next = " " + next.ToLower();
                }
                else if (RandomBoolean.Chance(2, 5))
                {
                    next = RandomString.Pick(":,-") + next.ToLower();
                }
                else if (RandomBoolean.Chance(3, 5))
                {
                    next = RandomString.Pick(":,-") + " " + next.ToLower();
                }
                else
                {
                    next = RandomString.Pick(".!?") + " " + next;
                }

                result.Append(next);
            }

            return(result.ToString());
        }
        public void TestNextInteger()
        {
            float value = RandomInteger.NextInteger(5);

            Assert.True(value <= 5);

            value = RandomInteger.NextInteger(2, 5);
            Assert.True(value <= 5 && value >= 2);
        }
Exemple #3
0
        public static TimeSpan NextTime()
        {
            int hour   = RandomInteger.NextInteger(0, 24);
            int min    = RandomInteger.NextInteger(0, 60);
            int sec    = RandomInteger.NextInteger(0, 60);
            int millis = RandomInteger.NextInteger(0, 1000);

            return(new TimeSpan(hour, min, sec, millis));
        }
Exemple #4
0
        public static T Pick <T>(T[] values)
        {
            if (values == null || values.Length == 0)
            {
                return(default(T));
            }

            return(values[RandomInteger.NextInteger(values.Length)]);
        }
        public void TestUpdateInteger()
        {
            float value = RandomInteger.UpdateInteger(0, 5);

            Assert.True(value <= 5 && value >= -5);

            value = RandomInteger.UpdateInteger(5, 0);

            value = RandomInteger.UpdateInteger(0);
            Assert.True(value == 0);
        }
Exemple #6
0
        public static string Pick(String[] values)
        {
            if (values == null || values.Length == 0)
            {
                return("");
            }

            int index = RandomInteger.NextInteger(values.Length);

            return(values[index]);
        }
Exemple #7
0
        public static char Pick(string values)
        {
            if (values == null || values.Length == 0)
            {
                return('\0');
            }

            int index = RandomInteger.NextInteger(values.Length);

            return(values[index]);
        }
Exemple #8
0
        public static T Pick <T>(List <T> values)
        {
            if (values == null || values.Count == 0)
            {
                return(default(T));
            }

            int index = RandomInteger.NextInteger(values.Count);

            return(values[index]);
        }
Exemple #9
0
        public static string Phone()
        {
            StringBuilder result = new StringBuilder();

            result.Append("(")
            .Append(RandomInteger.NextInteger(111, 999))
            .Append(") ")
            .Append(RandomInteger.NextInteger(111, 999))
            .Append("-")
            .Append(RandomInteger.NextInteger(0, 9999));

            return(result.ToString());
        }
Exemple #10
0
        public static string Words(int min, int max)
        {
            StringBuilder result = new StringBuilder();

            int count = RandomInteger.NextInteger(min, max);

            for (int i = 0; i < count; i++)
            {
                result.Append(RandomString.Pick(_allWords));
            }

            return(result.ToString());
        }
Exemple #11
0
        public static string NextString(int minLength, int maxLength)
        {
            StringBuilder result = new StringBuilder();

            int length = RandomInteger.NextInteger(minLength, maxLength);

            for (int i = 0; i < length; i++)
            {
                int index = RandomInteger.NextInteger(_chars.Length);
                result.Append(_chars[index]);
            }

            return(result.ToString());
        }
        public void TestSequence()
        {
            var list = RandomInteger.Sequence(1, 5);

            Assert.True(list.Count <= 5 && list.Count >= 1);

            list = RandomInteger.Sequence(-1, 0);
            Assert.True(list.Count == 0);

            list = RandomInteger.Sequence(-1, -4);
            Assert.True(list.Count == 0);

            list = RandomInteger.Sequence(4, 4);
            Assert.True(list.Count == 4);

            list = RandomInteger.Sequence(5);
            Assert.True(list.Count == 5);
        }
Exemple #13
0
        public static string Phrase(int minSize, int maxSize)
        {
            maxSize = Math.Max(minSize, maxSize);
            int size = RandomInteger.NextInteger(minSize, maxSize);

            if (size <= 0)
            {
                return("");
            }

            StringBuilder result = new StringBuilder();

            result.Append(RandomString.Pick(_allWords));
            while (result.Length < size)
            {
                result.Append(" ").Append(RandomString.Pick(_allWords).ToLower());
            }

            return(result.ToString());
        }
Exemple #14
0
        public static DateTime NextDate(int minYear, int maxYear)
        {
            int currentYear = DateTime.Now.Year;

            minYear = minYear == 0 ? currentYear - RandomInteger.NextInteger(10) : minYear;
            maxYear = maxYear == 0 ? currentYear : maxYear;

            int year  = RandomInteger.NextInteger(minYear, maxYear);
            int month = RandomInteger.NextInteger(1, 13);
            int day   = RandomInteger.NextInteger(1, 32);

            if (month == 2)
            {
                day = Math.Min(28, day);
            }
            else if (month == 4 || month == 6 || month == 9 || month == 11)
            {
                day = Math.Min(30, day);
            }
            return(new DateTime(year, month, day, 0, 0, 0, 0, DateTimeKind.Utc));
        }
Exemple #15
0
        public static char NextAlphaChar()
        {
            int index = RandomInteger.NextInteger(_alpha.Length);

            return(_alpha[index]);
        }
Exemple #16
0
 public static DateTime NextDateTime(int minYear, int maxYear)
 {
     return(NextDate(minYear, maxYear)
            .AddSeconds(RandomInteger.NextInteger(3600 * 24 * 365)));
 }