public static void GetDifference(long firstId, long secondId, string outputDirectory, params Expression <Func <Result, double> >[] selector) { (Result[], Session)first; (Result[], Session)second; using (var con = DataStrageManager.CreateConnection()) { first = DataStrageManager.Load(firstId, con); second = DataStrageManager.Load(secondId, con); } using (var wtr = new ReportWriter($"{outputDirectory}/{first.Item2.Description}_{second.Item2.Description}.tsv", false)) { wtr.WriteLine( "first_description\tsecond_description\tmethod\tdegrees\tradians\tfirst_result\tsecond_result\tdifference", WriteOn.Stream); foreach (var impl in selector.Select(x => (method: x.Compile(), name: NameBuilder.BuildName(x)))) { wtr.WriteLine(impl.name, WriteOn.Console); for (int i = 0; i < first.Item1.Length; i++) { var f = first.Item1[i]; var s = second.Item1[i]; wtr.WriteLine( $"{first.Item2.Description}\t{second.Item2.Description}\t{impl.name}\t{f.InputDegrees:g17}\t{f.InputRadians:g17}\t{impl.method(f):g17}\t{impl.method(s):g17}\t{Math.Abs(impl.method(f) - impl.method(s)):g17}", WriteOn.Stream); } } } }
private static void Check(long first, long second, SQLiteConnection connection, ReportWriter writer, Func <Result, double>[] selector) { var(fResults, fSession) = DataStrageManager.Load(first, connection); var(sResults, sSession) = DataStrageManager.Load(second, connection); if (first == second) { writer.WriteLine(Format(fSession, sSession, "ー")); return; } if (fResults.Length != sResults.Length) { writer.WriteLine(Format(fSession, sSession, "LengthMismatch!")); return; } var diffResult = true; for (int i = 0; i < fResults.Length; i++) { var f = fResults[i]; var s = sResults[i]; foreach (var func in selector) { if (func(f) != func(s)) { diffResult = false; break; } } } writer.WriteLine(Format(fSession, sSession, diffResult ? "○" : "×")); }