-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTester.cs
71 lines (67 loc) · 1.57 KB
/
Tester.cs
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
using System.Globalization;
namespace Power
{
internal class Tester
{
private ITask task;
private string path;
private string[] data = {};
// private string expect = "";
// private string actual = "";
public Tester(ITask task, string path)
{
this.task = task;
this.path = path;
}
public void RunAllTests()
{
int count = 0;
while(true)
{
bool result = RunTest(count);
if(!result)
{
break;
}
count++;
}
}
public bool RunTest(int count)
{
string inFile = $"{path}test.{count}.in";
string outFile = $"{path}test.{count}.out";
if(!File.Exists(inFile) || !File.Exists(outFile))
{
return false;
}
RunTest(inFile, outFile, count);
return true;
}
bool RunTest(string inFile, string outFile, int count)
{
try
{
NumberFormatInfo nfi = new NumberFormatInfo();
nfi.NumberDecimalSeparator = ".";
data = File.ReadAllLines(inFile);
double expect = double.Parse(File.ReadAllText(outFile).Trim(), nfi);
double actual = double.Parse(task.Run(data).Trim(), nfi);
bool result = (actual == expect);
if(result)
{
Console.WriteLine($"Test #{count} - PASS");
}
else
{
Console.WriteLine($"Test #{count} - FAIL ({expect} != {actual})");
}
return actual == expect;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return false;
}
}
}
}