Example #1
0
        /// <summary>
        /// Generates a random text that consists of random number of random words separated by spaces.
        /// </summary>
        /// <param name="min">(optional) a minimum number of words.</param>
        /// <param name="max">a maximum number of words.</param>
        /// <returns>a random text.</returns>
        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());
        }
Example #2
0
        public void TestNextString()
        {
            string value = RandomString.NextString(3, 5);

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

            for (int i = 0; i < value.Length; i++)
            {
                Assert.True(chars.IndexOf(value[i]) != -1 ||
                            symbols.IndexOf(value[i]) != -1 ||
                            digits.IndexOf(value[i]) != -1
                            );
            }
        }
Example #3
0
        public void testDistort()
        {
            string value = RandomString.Distort("abc");

            Assert.True(value.Length == 3 || value.Length == 4);
            Assert.True(value.Substring(0, 3) == "Abc" ||
                        value.Substring(0, 3).Equals("abc")
                        );

            if (value.Length == 4)
            {
                Assert.True(symbols.IndexOf(value.Substring(3)) != -1);
            }
        }
Example #4
0
        public void TestPick()
        {
            Assert.True(RandomString.Pick("") == '\0');
            char charVariable = RandomString.Pick(chars);

            Assert.True(chars.IndexOf(charVariable) != -1);

            string[] valuesEmpty = { };
            Assert.True(RandomString.Pick(valuesEmpty) == "");

            string[] values = { "ab", "cd" };
            string   result = RandomString.Pick(values);

            Assert.True(result == "ab" || result == "cd");
        }
Example #5
0
        /// <summary>
        /// Generates a random person's name which has the following structure
        /// optional prefix - first name - second name - optional suffix
        /// </summary>
        /// <returns>a random name.</returns>
        public static string Name()
        {
            StringBuilder result = new StringBuilder();

            if (RandomBoolean.Chance(3, 5))
            {
                result.Append(RandomString.Pick(_namePrefixes)).Append(" ");
            }

            result.Append(RandomString.Pick(_firstNames))
            .Append(" ")
            .Append(RandomString.Pick(_lastNames));

            if (RandomBoolean.Chance(5, 10))
            {
                result.Append(" ").Append(RandomString.Pick(_nameSuffixes));
            }

            return(result.ToString());
        }
Example #6
0
        /// <summary>
        /// Generates a random phrase which consists of few words separated by spaces.
        /// The first word is capitalized, others are not.
        /// </summary>
        /// <param name="minSize">(optional) minimum string length.</param>
        /// <param name="maxSize">maximum string length.</param>
        /// <returns>a random phrase.</returns>
        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());
        }
Example #7
0
 /// <summary>
 /// Generates a random noun. The result value is capitalized.
 /// </summary>
 /// <returns>a random noun.</returns>
 public static string Stuff()
 {
     return(RandomString.Pick(_stuffs));
 }
Example #8
0
 /// <summary>
 /// Generates a random color name. The result value is capitalized.
 /// </summary>
 /// <returns>a random color name.</returns>
 public static string Color()
 {
     return(RandomString.Pick(_colors));
 }
Example #9
0
 /// <summary>
 /// Generates a random word from available first names, last names, colors, stuffs, adjectives, or verbs.
 /// </summary>
 /// <returns>a random word.</returns>
 public static string Word()
 {
     return(RandomString.Pick(_allWords));
 }
Example #10
0
 /// <summary>
 /// Generates a random verb. The result value is capitalized.
 /// </summary>
 /// <returns>a random verb.</returns>
 public static string Verb()
 {
     return(RandomString.Pick(_verbs));
 }
Example #11
0
 /// <summary>
 /// Generates a random adjective. The result value is capitalized.
 /// </summary>
 /// <returns>a random adjective.</returns>
 public static string Adjective()
 {
     return(RandomString.Pick(_adjectives));
 }
Example #12
0
 public void TestNextAlphaChar()
 {
     Assert.True(chars.IndexOf(RandomString.NextAlphaChar()) != -1);
 }