//单次测试某位同学的成绩,生成文件到 学号-score.txt 中 public static void TestProject() { var writePath = $"./{Number}-Score.txt"; SudokuTester tester = new SudokuTester(ProjectDir, Number); using (var writer = new StreamWriter(writePath, false)) { try { tester.GetCorrectScore(); var arguments = tester.Scores.Select(i => i.Item1).ToList(); writer.Write("NumberID\t"); writer.WriteLine(string.Join("\t", arguments)); writer.Write(tester.NumberId + "\t"); writer.WriteLine(string.Join("\t", tester.Scores.Select(i => i.Item2))); writer.Flush(); } catch (Exception e) { Logger.Error(e.Message, tester._logFile); } } using (var writer = new StreamWriter(WrongFile, false)) { try { tester.GetWrongScore(); var arguments = tester.Wrongs.Select(i => i.Item1).ToList(); writer.WriteLine(); writer.Write("NumberID\t"); writer.WriteLine(string.Join("\t", arguments)); writer.Write(tester.NumberId + "\t"); writer.WriteLine(string.Join("\t", tester.Wrongs.Select(i => i.Item2))); writer.Flush(); } catch (Exception e) { Logger.Error(e.Message, tester._logFile); } } }
public static void ProcessWrong() { //挑选出需要测试的名单 var testList = ExtractTestList(File.ReadAllLines(BlogFile).Select(i => i.Split('\t')[0]).ToArray()); bool header = true; //是否以追加形式写入文件,不用的测试结果用不同的header标识 var isAppend = !ModeInput.Equals(Mode.Written); //把成绩写入文件,两次不同的测试结果以不同的header作为区分 using (var writer = new StreamWriter(WrongFile, isAppend)) { foreach (var line in testList) { string[] param = line.Split('\t'); SudokuTester tester = new SudokuTester(ProjectDir, param[0]); try { tester.GetWrongScore(); if (header) { var arguments = tester.Wrongs.Select(i => i.Item1).ToList(); writer.WriteLine(); writer.Write("NumberID\t"); writer.WriteLine(string.Join("\t", arguments)); header = false; } writer.Write(tester.NumberId + "\t"); writer.WriteLine(string.Join("\t", tester.Wrongs.Select(i => i.Item2))); writer.Flush(); } catch (Exception e) { Logger.Error(e.Message, tester._logFile); } } } }