Ejemplo n.º 1
0
        private static string[] ReadTestData()
        {
            // the benchmark data is from http://lh3lh3.users.sourceforge.net/reb.shtml
            const string resourceName   = "Regex.Data.howto";
            var          resourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);

            if (resourceStream == null)
            {
                throw new InvalidOperationException($"Resource '{resourceName}' is not found");
            }
            var content = new byte[resourceStream.Length];

            if (resourceStream.Read(content, 0, content.Length) != content.Length)
            {
                throw new InvalidOperationException($"Unable to read data from resource '{resourceName}'");
            }
            var result = new UTF8Encoding(false).GetString(content).Split('\r', '\n').ToArray();
            var random = new Random(314159);

            for (int i = 1; i < result.Length; ++i)
            {
                var j    = random.Next(i);
                var temp = result[i];
                result[i] = result[j];
                result[j] = temp;
            }
            return(result.ToArray());
        }