aboutsummaryrefslogtreecommitdiff
path: root/works/life/lanqiao-selection-match/java-gen-out.rb
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-12-18 19:39:43 +0800
committercrupest <crupest@outlook.com>2021-12-18 19:39:43 +0800
commit32ee3de04af83613e78cf7383c3ca6ead6edae03 (patch)
treefc0ea8f776ca2bedfbdf80d870f5a3b03f5f6b52 /works/life/lanqiao-selection-match/java-gen-out.rb
parentfdf9f9a9d342329a57b8bf568af505b789522044 (diff)
downloadcrupest-32ee3de04af83613e78cf7383c3ca6ead6edae03.tar.gz
crupest-32ee3de04af83613e78cf7383c3ca6ead6edae03.tar.bz2
crupest-32ee3de04af83613e78cf7383c3ca6ead6edae03.zip
import(life): ...
Diffstat (limited to 'works/life/lanqiao-selection-match/java-gen-out.rb')
-rwxr-xr-xworks/life/lanqiao-selection-match/java-gen-out.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/works/life/lanqiao-selection-match/java-gen-out.rb b/works/life/lanqiao-selection-match/java-gen-out.rb
new file mode 100755
index 0000000..bedad2d
--- /dev/null
+++ b/works/life/lanqiao-selection-match/java-gen-out.rb
@@ -0,0 +1,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