-
Notifications
You must be signed in to change notification settings - Fork 0
/
verify.ps1
72 lines (63 loc) · 2.08 KB
/
verify.ps1
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
param([string]$SubDir)
$exePath = Join-Path (Get-Location) "main.exe"
if (!(Test-Path $exePath))
{
Write-Host "C++ exe not found, trying C# exe"
$exePath = Join-Path (Get-Location) "\bin\Debug\net8.0\main.exe"
}
if (!(Test-Path $exePath))
{
throw "$exePath not found"
}
# Set an environment variable to the subdirectory name so that the C++ code can decide at runtime whether to run part1 or part2
$env:PART_TO_RUN = $SubDir;
$sampleInputs = Get-ChildItem (".\" + $subdir + "\*.in")
foreach ($input in $sampleInputs)
{
Write-Host "Verifying" $input.Name
$answerFile = $input.FullName.Replace(".in", ".ans")
if (Test-Path $answerFile)
{
$stopwatch = [system.diagnostics.stopwatch]::StartNew()
$output = Invoke-Expression "type $input | $exePath"
if ($lastexitcode -ne 0)
{
Write-Error "Program crashed"
continue;
}
elseif ($null -eq $output)
{
Write-Warning "No output from program."
continue;
}
$stopwatch.Stop()
$runtimeInMS = [math]::Round($stopwatch.Elapsed.TotalMilliseconds)
$expected = Get-Content $answerFile
Write-Host "Expected: $expected`r`n Actual: $output"
$differences = (Compare-Object -ReferenceObject $output -DifferenceObject $expected -CaseSensitive)
[bool]$equal = $null -eq $differences
if ($equal)
{
Write-Host -ForegroundColor Green "Test case $input succeeded"
}
else
{
[string]$left = $differences[0].InputObject
[string]$right = $differences[1].InputObject
Write-Host -ForegroundColor Red "Test case $input failed. '$left' doesn't equal '$right'"
}
if ($runtimeInMS -lt 1000)
{
Write-Host "Run completed in $runtimeInMs milliseconds."
}
else
{
Write-Host -ForegroundColor Yellow "Run completed in $runtimeInMs milliseconds. That is too slow!"
}
}
else
{
Write-Error "$answerFile not found."
}
Write-Host ""
}