public static void GenerateTests(TestSettings currentSettings, string path)
        {
            using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None))
            {
                using (var sw = new StreamWriter(fs))
                {
                    var rand = new Random();
                    sw.WriteLine($"{currentSettings.CommandCount}");
                    for (var i = 0; i < currentSettings.CommandCount; i++)
                    {
                        var commandInt           = rand.Next(currentSettings.GetSumOfChances());
                        var sumOfPreviousChances = 0;

                        foreach (var option in currentSettings.AvailableOptionsTuples)
                        {
                            if (commandInt < currentSettings.GetChance(option.Key) + sumOfPreviousChances)
                            {
                                var appendedLineBuilder = new StringBuilder();
                                appendedLineBuilder.Append(option.Key);
                                for (var j = 0; j < option.Value; j++)
                                {
                                    appendedLineBuilder.Append($" {(j == 0 ? rand.Next() % 1000: rand.Next())}");
                                }
                                sw.WriteLine(appendedLineBuilder.ToString());
                                break;
                            }
                            else
                            {
                                sumOfPreviousChances += currentSettings.GetChance(option.Key);
                            }
                        }
                    }
                    fs.Flush();
                }
                TestMenuConsolePages.PrintGreen("Succeeded making test.txt");
                Console.ReadKey();
            }
        }
Exemple #2
0
        public void TestGeneratingProcedure()
        {
            _currentSettings = TestSettings.Deserialize("settings.xml") ?? new TestSettings(1);

            while (true)
            {
                Console.Clear();
                TestMenuConsolePages.ViewMainMenu();
                var input = Console.ReadLine();
                switch (input)
                {
                case "1":
                    _menu.ViewChanceMenu(_currentSettings);
                    Tuple <bool, char, int> change = TestMenuConsolePages.ChangeOption();
                    if (change.Item1)
                    {
                        _currentSettings.SetChance(change.Item2, change.Item3);
                        continue;
                    }
                    else
                    {
                        Console.Clear();
                        continue;
                    }

                case "2":
                    _currentSettings.CommandCount = TestMenuConsolePages.AskForCommandAmount();
                    GenerateTests("test.txt");
                    break;

                default:
                    _currentSettings.Serialize("settings.xml");
                    return;
                }
            }
        }