public void CheckAllFilesWithBaseAlgorithm() { IEnumerable <string> files = Directory.EnumerateFiles( PathToSources, "*.graph", SearchOption.AllDirectories); Assert.AreNotEqual(files.Count(), 0, "There are no test files"); Dictionary <Exception, string> exceptions = new Dictionary <Exception, string>(); foreach (var file in files) { long[] xadj; int[] adjncy; int[][] graphNumeration; Loader.LoadGraphFromMETISFormat(file, out xadj, out adjncy); bool valid = MeshRecovery.Validate(xadj, xadj.Length, adjncy, out int meshDimension); int numerate = MeshRecovery.Numerate(xadj, xadj.Length, adjncy, out graphNumeration); bool isGood = valid && numerate == 0; if (isGood) { try { int errCode = NumerationHelper.ValidateNumeration(xadj, adjncy, meshDimension, graphNumeration); Assert.IsTrue(errCode >= 0, $"ValidateNumeartion returns {errCode} for numeration {GraphNumerationToString(graphNumeration)}"); } catch (Exception e) { exceptions.Add(e, Path.GetFileName(file)); } } DirectoryInfo dirInfo = new DirectoryInfo(Path.GetDirectoryName(file)); if (dirInfo.Name == GoodFolder) { Assert.IsTrue(isGood); } else if (dirInfo.Name == BadFolder) { Assert.IsFalse(isGood); } else { Assert.Fail("Should be good and bad files only"); } } if (exceptions.Count > 0) { string output = "List of exceptions: "; foreach (var e in exceptions) { output += Environment.NewLine + "There is problem with file: " + e.Value + ". The reason: " + e.Key.Message + "|"; } Assert.Fail(output); } }
static void PrintResultInRT() { List <string> files = GetAllTestFiles(); if (files.Count == 0) { return; } files.Sort(Comparer <string> .Create((y, x) => x.Split('\\').Last <string>().Length - y.Split('\\').Last <string>().Length)); string new_file_name = PathToResults + "/" + GenerateNewName() + result_type; StreamWriter result = new StreamWriter(new_file_name); System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch(); PrepareResultsHead(result, files.ToArray()); for (int i = 0; i < files.Count; ++i) { string current_file_name = files[i].Split('\\').Last <string>(); Console.WriteLine("Working on " + current_file_name); int meshDimension = 0; long[] xadj; int[] adjncy; bool valid = false; int numerate = 0; int[][] graphNumeration; Loader.LoadGraphFromMETISFormat(files[i], out xadj, out adjncy); timer.Start(); valid = MeshRecovery.Validate(xadj, xadj.Length, adjncy, out meshDimension); numerate = MeshRecovery.Numerate(xadj, xadj.Length, adjncy, out graphNumeration); timer.Stop(); string validationResult = ""; if (valid && numerate == 0) { int validationCode = NumerationHelper.ValidateNumeration(xadj, adjncy, meshDimension, graphNumeration); validationResult = validationCode >= 0 ? "Верно" : "Неверно"; } //TODO: Dinar: check memory usage ? //TODO: Dinar: check memory usage ? WriteRow(result , current_file_name , valid.ToString() , numerate.ToString() , timer.ElapsedMilliseconds.ToString() , IntArrayToList(graphNumeration) , validationResult); timer.Reset(); } result.WriteLine("\tEND OF THE TEST RESULTS"); result.Close(); }
static void PrintResultInExcel() { try { var temp = new Excel.Application(); //don`t forget closing that test app temp.Quit(); } catch { return; } var excelApp = new Excel.Application(); excelApp.Workbooks.Add(); Excel._Worksheet workSheet = excelApp.ActiveSheet; WriteRowExcel(workSheet, 1, head_columns); //workSheet.Cells[1, 6] = "Memory"; string[] files = GetAllTestFiles().ToArray(); if (files.Length == 0) { return; } string new_file_name = GenerateNewName() + excel_type; System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch(); for (int i = 0; i < files.Length; ++i) { int meshDimension = 0; long[] xadj; int[] adjncy; bool valid = false; int numerate = 0; int[][] graphNumeration; string current_file_name = files[i].Split('\\').Last <string>(); Console.WriteLine("Working on " + current_file_name); Loader.LoadGraphFromMETISFormat(files[i], out xadj, out adjncy); timer.Start(); valid = MeshRecovery.Validate(xadj, xadj.Length, adjncy, out meshDimension); numerate = MeshRecovery.Numerate(xadj, xadj.Length, adjncy, out graphNumeration); timer.Stop(); //TODO: Dinar: check memory usage ? Graph graph = new Graph(xadj, adjncy); bool success = valid && numerate == 0; string validationResult = ""; if (success) { int validationCode = NumerationHelper.ValidateNumeration(xadj, adjncy, meshDimension, graphNumeration); validationResult = validationCode >= 0 ? "Верно" : "Неверно"; } WriteRowExcel( workSheet, i + 2, current_file_name, graph.GetVerticesCount().ToString(), graph.GetEdgeCount().ToString(), valid ? "ИСТИНА" : "ЛОЖЬ", numerate.ToString(), validationResult, success ? graphNumeration[0].Length.ToString() : "X", timer.ElapsedMilliseconds.ToString() ); timer.Reset(); } for (int i = 0; i < head_columns.Length; ++i) { workSheet.Columns[i + 1].AutoFit(); } workSheet.Name = "Results"; workSheet.SaveAs(Environment.CurrentDirectory + "/" + PathToExcelResults + "/" + new_file_name); // Make the object visible. excelApp.Visible = true; }