Exemplo n.º 1
0
        private void writeCSV(string testFileName, TotalTestResults results)
        {
            List<string> methodOrder = new List<string>();
            methodOrder.Add(RANDOM_NAME);
            foreach (MethodInfo inf in _implementedMethods)
            {
                string name = inf.Name;
                if (!methodOrder.Contains(name))
                {
                    methodOrder.Add(name);
                }
            }

            string header = String.Format(",{0}", RANDOM_NAME);
            foreach (String s in methodOrder)
            {
                if (!s.Equals(RANDOM_NAME) && results.IsUsedMethod(s))
                {
                    header += ("," + s + ",,");
                }
            }

            StringBuilder secondHeader = new StringBuilder();
            secondHeader.Append("# Cities,Path Length");
            for (int i = 1; i < methodOrder.Count; i++)
            {
                string curMethod = methodOrder[i];
                if (results.IsUsedMethod(curMethod))
                {
                    secondHeader.Append(",Time (sec),Path Length,% Improvement");
                }

            }

            StringBuilder bodyFill = new StringBuilder();

            List<int> sortedCities = results.SortedNumberCities();
            foreach (int numCities in sortedCities)
            {
                double randomDistance = results.GetValues(numCities, RANDOM_NAME)[0].Distance;
                bodyFill.Append(numCities + "," + randomDistance);
                foreach (string curMethod in methodOrder)
                {
                    List<SingleTestResult> resultsForCitiesAndMethods =
                        results.GetValues(numCities, curMethod);
                    if (resultsForCitiesAndMethods.Count > 0 && !curMethod.Equals(RANDOM_NAME))
                    {
                        SingleTestResult result = resultsForCitiesAndMethods[0];
                        double increase = result.Distance - randomDistance;
                        double percentChange = (increase / randomDistance) * -100;
                        bodyFill.Append("," + result.TimeInSeconds + "," + result.Distance + "," + percentChange);
                    }

                }
                bodyFill.AppendLine();
            }

            DateTime now = DateTime.Now;
            string format = "_MM_dd_yy__HH_mm_ss";
            string dateTimeAppend = now.ToString(format);
            string newFileName = Path.GetFileNameWithoutExtension(testFileName) + dateTimeAppend + ".csv";
            using (StreamWriter f = new StreamWriter(newFileName))
            {
                f.WriteLine(header);
                f.WriteLine(secondHeader);
                f.WriteLine(bodyFill.ToString());
            }
        }
Exemplo n.º 2
0
        private TotalTestResults runAllTestSuites(List<TestSuiteEntry> tests, BackgroundWorker worker)
        {
            int maxProgress = 0;
            foreach (TestSuiteEntry t in tests)
            {
                if (t.AlgorithmType.Equals("ALL"))
                {
                    maxProgress += (t.NumberOfIterations * _implementedMethods.Count);
                }
                else
                {
                    maxProgress += t.NumberOfIterations;
                }
            }
            TotalTestResults totalResults = new TotalTestResults();
            TestSuiteProgressData progressData = new TestSuiteProgressData(ReasonableTime, 1, 1, 1, maxProgress);
            progressData.MaxTestProgress = tests.Count;
            progressData.CurrentTestProgress = 0;
            worker.ReportProgress(0, progressData);
            for (int testIndex = 0; testIndex < tests.Count; testIndex++ )
            {
                TestSuiteEntry curTest = tests[testIndex];
                Log("Running test suite: {0}: {1}/{2}", curTest.ToString(), (testIndex+1), tests.Count);
                progressData.CurrentTest = curTest.ToString();
                progressData.MaxIterationProgress = curTest.NumberOfIterations;
                progressData.CurrentIterationProgress = 0;
                progressData.MaxMethodProgress = _implementedMethods.Count;
                progressData.CurrentMethodProgress = 0;
                progressData.CurrentTestProgress++;
                worker.ReportProgress(progressData.CompletionPercentage, progressData);

                if (curTest.AlgorithmType.Equals("ALL"))
                {
                    foreach (MethodInfo method in _implementedMethods)
                    {
                        progressData.CurrentMethodProgress++;
                        progressData.CurrentMethod = method.Name;
                        worker.ReportProgress(progressData.CompletionPercentage, progressData);
                        SingleTestResult average = runAllTestIterations(curTest, method, worker, progressData);
                        totalResults.StoreResult(curTest.NumberCities, method.Name, average);
                    }
                }
                else
                {
                    MethodInfo chosenMethod = null;
                    foreach (MethodInfo method in _implementedMethods)
                    {
                        if (method.Name.Equals(curTest.AlgorithmType))
                        {
                            chosenMethod = method;
                        }
                    }
                    if (chosenMethod != null)
                    {
                        progressData.MaxMethodProgress = 1;
                        progressData.CurrentMethodProgress++;
                        progressData.CurrentMethod = chosenMethod.Name;
                        worker.ReportProgress(progressData.CompletionPercentage, progressData);
                        SingleTestResult value = runAllTestIterations(curTest, chosenMethod, worker, progressData);
                        totalResults.StoreResult(curTest.NumberCities, chosenMethod.Name, value);
                    }
                    else
                    {
                        Log("Chosen Algorithm: {0} does not exist!", curTest.AlgorithmType);
                    }
                }

            }
            return totalResults;
        }