namespace HeuristicLab.BenchmarkSuite.Views { using System; using System.Collections.Generic; using System.Globalization; using System.Linq; public static class ViewHelper { public static string StringifyInput(ExampleArgumentType type, int offset, string floatFormat, Example example, string valueSeparator) { switch (type) { case ExampleArgumentType.Integer: return example.InputInteger[offset].ToString(); case ExampleArgumentType.IntegerVector: return "[" + string.Join(", ", example.InputIntegerVector[offset]) + "]"; case ExampleArgumentType.Float: return example.InputFloat[offset].ToString(floatFormat, CultureInfo.CurrentUICulture); case ExampleArgumentType.FloatVector: return "[" + string.Join(", ", example.InputFloatVector[offset].Select(x => x.ToString(floatFormat, CultureInfo.InvariantCulture))) + "]"; case ExampleArgumentType.Boolean: return example.InputBoolean[offset].ToString(); case ExampleArgumentType.Char: return example.InputChar[offset].ToString(); case ExampleArgumentType.String: return example.InputString[offset]; case ExampleArgumentType.StringVector: return "[" + string.Join(", ", example.InputStringVector[offset]) + "]"; default: return string.Empty; } } public static string StringifyOutput(ExampleArgumentType type, int offset, string floatFormat, Example example, string valueSeparator) { switch (type) { case ExampleArgumentType.Integer: return example.OutputInteger[offset].ToString(); case ExampleArgumentType.IntegerVector: return "[" + string.Join(", ", example.OutputIntegerVector[offset]) + "]"; case ExampleArgumentType.Float: return example.OutputFloat[offset].ToString(floatFormat, CultureInfo.InvariantCulture); case ExampleArgumentType.FloatVector: return "[" + string.Join(", ", example.OutputFloatVector[offset].Select(x => x.ToString(floatFormat, CultureInfo.InvariantCulture))) + "]"; case ExampleArgumentType.Boolean: return example.OutputBoolean[offset].ToString(); case ExampleArgumentType.Char: return example.OutputChar[offset].ToString(); case ExampleArgumentType.String: return example.OutputString[offset]; case ExampleArgumentType.Print: return example.OutputPrint; case ExampleArgumentType.StringVector: return "[" + string.Join(", ", example.OutputStringVector[offset]) + "]"; default: return string.Empty; } } private const string IntegerColumnHeader = "int"; private const string IntegersColumnHeader = "int[]"; private const string DoubleColumnHeader = "float"; private const string DoublesColumnHeader = "float[]"; private const string BooleanColumnHeader = "bool"; private const string CharColumnHeader = "char"; private const string StringColumnHeader = "string"; private const string PrintColumnHeader = "print"; private const string StringsColumnHeader = "string[]"; public static string GetHeaderTypeName(ExampleArgumentType type) { switch (type) { case ExampleArgumentType.Integer: return IntegerColumnHeader; case ExampleArgumentType.Float: return DoubleColumnHeader; case ExampleArgumentType.Boolean: return BooleanColumnHeader; case ExampleArgumentType.Char: return CharColumnHeader; case ExampleArgumentType.String: return StringColumnHeader; case ExampleArgumentType.Print: return PrintColumnHeader; case ExampleArgumentType.IntegerVector: return IntegersColumnHeader; case ExampleArgumentType.FloatVector: return DoublesColumnHeader; case ExampleArgumentType.StringVector: return StringsColumnHeader; default: return string.Empty; } } public static Dictionary CreateArgumentCountDict() { return Enum.GetValues(typeof(ExampleArgumentType)).Cast().ToDictionary(type => type, _ => 0); } } }