/// <summary> /// Outputs the given results to a text file. /// </summary> private void OutputResults(TestResultCollection results, TestConfig config) { StreamWriter sw; IEnumerable<string> dirs = Directory.EnumerateDirectories(Directory.GetCurrentDirectory()); if(!dirs.Contains<string>("Test Results")) Directory.CreateDirectory(Directory.GetCurrentDirectory() + "/Test Results/"); try { sw = new StreamWriter(Directory.GetCurrentDirectory() + "/Test Results/" + config.OutputFile + ".txt"); } catch(Exception e) { Console.Write("Failed to open stream for test output file.\nException: " + e.Message + "\n"); return; } sw.Write("Test Run On: " + config.StartTime.ToLongDateString() + " at " + config.EndTime.ToLongTimeString() + sw.NewLine); sw.Write("Map: " + config.MapName + sw.NewLine); sw.Write("Number of Obstacles on Map: " + config.NumberOfObstacles + sw.NewLine); sw.Write("Average path length: " + results.AverageLength + sw.NewLine); sw.Write("Average ticks taken: " + results.AverageTicksForPath + sw.NewLine); sw.Write("Test Finished On: " + config.EndTime.ToLongDateString() + " at " + config.StartTime.ToLongTimeString() + sw.NewLine); sw.Flush(); sw.Close(); }
/// <summary> /// Run button click event function. This function initializes the tests, and shows the testing window dialog. /// </summary> private void buttonRun_Click(object sender, EventArgs e) { if (ValidateInput()) { // Check algorithm PathfinderAlgorithm algo = PathfinderAlgorithm.AStar; if (comboBoxAlgorithm.Text == "A*") algo = PathfinderAlgorithm.AStar; else if (comboBoxAlgorithm.Text == "Dijkstra") algo = PathfinderAlgorithm.Dijkstra; else if (comboBoxAlgorithm.Text == "Scent Map") algo = PathfinderAlgorithm.ScentMap; // Set up the test configuration TestConfig config = new TestConfig(Convert.ToInt32(numericUpDownDist.Value), Convert.ToInt32(numericUpDownNOfRuns.Text), textBoxOutputFilename.Text, algo, LevelHandler.Level.Map, LevelHandler.Level.Map.Name); // Run Tests... TestRun test = new TestRun(config); test.ShowDialog(); this.Close(); } }
TestResultCollection results; // The list of results #endregion Fields #region Constructors public TestWorker(TestConfig config) { this.config = config; cancel = false; rand = new Random(DateTime.Now.Millisecond); results = new TestResultCollection(); WorkerReportsProgress = true; }
/// <summary> /// Runs the test and shows the progress window. /// </summary> /// <param name="config">The testing configuration to use.</param> public void Run(TestConfig config) { // Show as a dialog this.Show(); // Initialize progress bar progressBarTests.Maximum = 100; progressBarTests.Minimum = 0; progressBarTests.Value = 0; // Initialize percentage label percLabel.Text = "0"; // Initialize background worker worker = new TestWorker(config); worker.ProgressChanged += new ProgressChangedEventHandler(workerReport); worker.OnComplete += new TestCompletedEventHandler(workerComplete); // Run background worker thread worker.RunWorkerAsync(); }
TestWorker worker; // The background worker, testing runs on it's own background thread #endregion Fields #region Constructors public TestRun(TestConfig config) { InitializeComponent(); this.config = config; }
/// <summary> /// Outputs the given results to a text file. /// </summary> private void OutputResults(TestResultCollection results, TestConfig config) { StreamWriter sw; IEnumerable<string> dirs = Directory.EnumerateDirectories(Directory.GetCurrentDirectory()); if(!dirs.Contains<string>("Test Results")) Directory.CreateDirectory(Directory.GetCurrentDirectory() + "/Test Results/"); try { sw = new StreamWriter(Directory.GetCurrentDirectory() + "/Test Results/" + config.OutputFile + ".txt"); } catch(Exception e) { Console.Write("Failed to open stream for test output file.\nException: " + e.Message + "\n"); return; } sw.Write("Test Run On: " + config.StartTime.ToLongDateString() + " at " + config.EndTime.ToLongTimeString() + sw.NewLine + sw.NewLine); sw.Write("----- Configuration -----" + sw.NewLine); sw.Write("Algorithm: " + config.Algorithm.ToString() + sw.NewLine); sw.Write("Map: " + config.MapName + sw.NewLine); sw.Write("Number of Obstacles on Map: " + config.NumberOfObstacles + sw.NewLine); sw.Write("Manhattan distance between start and target: " + config.PathDistance + sw.NewLine); sw.Write("Number of tests: " + config.NumberOfTestRuns + sw.NewLine + sw.NewLine); sw.Write("----- Results ----" + sw.NewLine); sw.Write("Average path length: \t\t" + results.AverageLength + " (STDEV: " + results.STDEVLength + ")" + sw.NewLine); sw.Write("Average nodes searched: \t" + results.AveragedNodesSearched + " (STDEV: " + results.STDEVNodesSearched + ")" + sw.NewLine); sw.Write("Average ms taken: \t\t" + ((double)results.AverageTicksForPath * TestResult.MS_PER_TICK) + " (STDEV: " + results.STDEVMillisecondsTaken + ")" + sw.NewLine); sw.Flush(); sw.Close(); }
public TestCompletedArgs(TestResultCollection results, TestConfig config, bool cancelled) { this.cancelled = cancelled; this.results = results; this.config = config; }