-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
108 lines (98 loc) · 4.38 KB
/
Program.cs
File metadata and controls
108 lines (98 loc) · 4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using Perfy.DataGathering;
using Perfy.Display;
using Perfy.ProcessHandling;
using Perfy.Testing;
namespace Perfy
{
internal class Program
{
static void Main(string[] args)
{
if (args.Length == 0)
{
DisplayMethods.PrintError("No arguments detected. Note that as a cmdlet, this does not work without arguments. Run cmd and navigate to this project's bin folder. Printing the help menu:");
DisplayMethods.HelpMenu();
return;
}
if(args.Contains("-h") || args.Contains("--help"))
{
DisplayMethods.HelpMenu();
return;
}
Interpreter.ArgDictionary argDictionary = Interpreter.GrabArgs(args);
if (!argDictionary.Flags.TryGetValue("runCommand", out string? rcmd))
rcmd = ":script :inputs";
if (argDictionary.UnnamedArgs.Count == 0)
DisplayMethods.PrintWarning("No scripts provided to test.");
List<Tester> testers = [];
IDataSource dataSource;
if (argDictionary.Flags.TryGetValue("onecase", out string? singleCase))
{
Dictionary<string, string> colonVals = Interpreter.ColonString(singleCase);
if(colonVals.Count != 1)
{
DisplayMethods.PrintError($"Invalid onecase value {singleCase}");
Environment.Exit(0);
}
string key = colonVals.Keys.ToArray()[0];
dataSource = new SingularSource(new TestCase()
{
Inputs = key.Split(','),
Outputs = colonVals[key].Split(',')
});
}
else if (argDictionary.Flags.TryGetValue("datasource", out string? data))
{
Dictionary<string, string> sourceConfig = Interpreter.ColonString(data);
if(sourceConfig.TryGetValue("jsfile", out string? filePath))
dataSource = new JSDataFile(filePath);
else
{
DisplayMethods.PrintError("Invalid data flag value.");
Environment.Exit(0);
return;
}
//else if(sourceConfig.TryGetValue("case", out string? Input))
}
else
{
dataSource = new SingularSource(new TestCase()
{
Inputs = [],
Outputs = []
});
}
foreach (string script in argDictionary.UnnamedArgs)
{
ProcessHandler processHandler;
if (argDictionary.Flags.TryGetValue("timeoutms", out string? timeout))
processHandler = new ProcessHandler(rcmd.Replace(":script", script), Interpreter.SafeInterpret<int>(timeout, "Timeout value must be a positive integer", (int i) => i > 0));
else
processHandler = new ProcessHandler(rcmd.Replace(":script", script));
Tester tester;
if (argDictionary.Flags.TryGetValue("batch", out string? batch))
tester = new BatchTester(dataSource.Clone(), processHandler, Interpreter.SafeInterpret<int>(batch, "Batch size must be a positive integer", (int i) => i > 0));
else
tester = new SingleProcessTester(dataSource.Clone(), processHandler);
//tester.OnTestCaseReturned += EchoTest;
//tester.TestingEnded += (self, results) =>
//{
// Console.WriteLine("\nOverall Statistics:");
// Console.WriteLine("Accuracy: {0}%\tTime: {1}ms", results.AverageAccuracy * 100, results.TotalElapsedMs);
//};
testers.Add(tester);
}
DisplayHandler displayHandler = new Racer([..testers], 400);
Thread displayThread = new(displayHandler.Listen);
Thread[] threads = new Thread[testers.Count];
for(int i = 0;i < threads.Length;i++)
threads[i] = new Thread(testers[i].Start);
displayThread.Start();
foreach (Thread t in threads)
t.Start();
foreach (Thread t in threads)
t.Join();
displayThread.Join();
}
}
}