blob: bedad2d0182a4166fcd61a10b6fa09706f4465fd (
plain)
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
|
#!/usr/bin/env ruby
require 'timeout'
def run(no, count)
Dir.glob("./codes/*#{no}.java").each do |f|
code = File.read(f)
code.sub!(/public\s+class\s+\S+/, 'public class Main')
java_file = f.sub('codes', 'temp')
File.write(java_file, code)
count.times do |i|
in_file = "./generator/#{no}-#{i + 1}.in"
out_file = "#{f.sub('codes', 'out').sub('.java', '')}-#{i + 1}.out"
pid = Process.spawn "/usr/local/opt/openjdk/bin/java #{java_file} < #{in_file} > #{out_file}"
Timeout.timeout(5) do
Process.wait pid
end
rescue Timeout::Error
puts "Timeout for #{f} when tests #{i + 1} case"
File.delete out_file
Process.kill 'KILL', pid
end
rescue StandardError
puts "Error for #{f}"
end
end
run 'A', 3
run 'B', 3
run 'C', 4
|