judge_system 1.7.2 → 1.7.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a0ae37e4bd7f32f39c5aa442a0bda38d4e4934c
4
- data.tar.gz: 3cbb9f348b28dfc1c13c799c51d97156bd68d706
3
+ metadata.gz: 66a5e610c3f04a03a3c5995f8f7f340c80d6aa6c
4
+ data.tar.gz: 8725d6e567c79b14271dddaf3d71ea08ee1961f6
5
5
  SHA512:
6
- metadata.gz: a87564556cfb3e293e383ebe8e54fe46dcad66a62ac8c85a3a9c38914696bf52d04bbd3503a1b04dca8e7fa78a53c98842291a6106ed5800d0686837a882027f
7
- data.tar.gz: c3d17b3314938c0f705585aab855fd115da606abc8943f3bed382bb7f44a046765a8b48abf235887746160bd97f149cd3173d49b4335339db3d03f35e759b2a8
6
+ metadata.gz: f75e46f42cf3cb8d26fd82095c88b7f9acbd8aba2e437e78b33ce7c22749b8a45f6349b29d60312f40a556096e88579e50bced2acec1ef5d619fe80978b0a9d8
7
+ data.tar.gz: 29258383872cd55bc5a4f5c1b8cfc40e3df33781e407a3676d82bb32e8e67a15bda25610afb8045e962f0d08f7a804c0fe5474d2be147a044c3e11615143746a
@@ -0,0 +1,28 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'spec/*.rb'
4
+ AsciiComments:
5
+ Enabled: false
6
+
7
+ Style/ClassAndModuleChildren:
8
+ Enabled: false
9
+
10
+ Style/Documentation:
11
+ Enabled: false
12
+
13
+ Style/FrozenStringLiteralComment:
14
+ Enabled: false
15
+
16
+ Metrics/BlockLength:
17
+ Exclude:
18
+
19
+ MethodLength:
20
+ Max: 20
21
+
22
+ Metrics/LineLength:
23
+ Max: 120
24
+ Exclude:
25
+ - 'lib/compile_systems/*.rb'
26
+
27
+ Metrics/AbcSize:
28
+ Max: 20
data/README.md CHANGED
@@ -58,7 +58,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
58
58
 
59
59
  ## Contributing
60
60
 
61
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/judge_system. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
61
+ Bug reports and pull requests are welcome on GitHub at https://github.com/getty104/judge_system. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
62
62
 
63
63
 
64
64
  ## License
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "judge_system"
3
+ require 'bundler/setup'
4
+ require 'judge_system'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "judge_system"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start
@@ -1,35 +1,37 @@
1
1
  # coding: utf-8
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'judge_system/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "judge_system"
8
+ spec.name = 'judge_system'
8
9
  spec.version = JudgeSystem::VERSION
9
- spec.authors = ["getty104"]
10
- spec.email = ["hayabusatoshihumi@gmail.com"]
10
+ spec.authors = ['getty104']
11
+ spec.email = ['hayabusatoshihumi@gmail.com']
11
12
 
12
- spec.summary = %q{This is a judge system for online judge }
13
+ spec.summary = 'This is a judge system for online judge '
13
14
  spec.description = "This is a judge system for online judge. \nThis gem work on the wandbox api."
14
- spec.homepage = "https://github.com/getty104/judge_system"
15
- spec.license = "MIT"
15
+ spec.homepage = 'https://github.com/getty104/judge_system'
16
+ spec.license = 'MIT'
16
17
 
17
18
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
19
  # to allow pushing to a single host or delete this section to allow pushing to any host.
19
- # if spec.respond_to?(:metadata)
20
+ # if spec.respond_to?(:metadata)
20
21
  # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
22
  # raise "RubyGems 2.0 or newer is required to protect against " \
22
- #{}"public gem pushes."
23
- #end
23
+ # {}"public gem pushes."
24
+ # end
24
25
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
25
26
  f.match(%r{^(test|spec|features)/})
26
27
  end
27
- spec.bindir = "exe"
28
+ spec.bindir = 'exe'
28
29
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
- spec.require_paths = ["lib"]
30
- spec.add_dependency "rbzip2"
31
- spec.add_dependency "ffi"
32
- spec.add_development_dependency "bundler", "~> 1.13"
33
- spec.add_development_dependency "rake", "~> 10.0"
34
- spec.add_development_dependency "rspec", "~> 3.0"
30
+ spec.require_paths = ['lib']
31
+ spec.add_dependency 'rbzip2'
32
+ spec.add_dependency 'ffi'
33
+ spec.add_development_dependency 'bundler', '~> 1.13'
34
+ spec.add_development_dependency 'rake', '~> 10.0'
35
+ spec.add_development_dependency 'rspec', '~> 3.0'
36
+ spec.add_development_dependency 'rubocop', '~> 0.42.0'
35
37
  end
@@ -1,26 +1,26 @@
1
1
  require 'base64'
2
2
 
3
- File.open("stdin.txt.bz2", "wb") do |file|
4
- file.write Base64.decode64 $stdin.read
5
- file.close
3
+ File.open('stdin.txt.bz2', 'wb') do |file|
4
+ file.write Base64.decode64 $stdin.read
5
+ file.close
6
6
  end
7
7
 
8
- system("bunzip2 stdin.txt.bz2")
8
+ system('bunzip2 stdin.txt.bz2')
9
9
 
10
- stdin = File.open("stdin.txt").read.split("\n<$><*><$>\n")
10
+ stdin = File.open('stdin.txt').read.split("\n<$><*><$>\n")
11
11
  code = stdin[0]
12
12
  input = stdin[1]
13
13
  time = stdin[2]
14
14
 
15
- File.open("./main.c", "w") do |file|
16
- file.puts code
17
- file.close
15
+ File.open('./main.c', 'w') do |file|
16
+ file.puts code
17
+ file.close
18
18
  end
19
19
 
20
- File.open("./test.in", "w") do |file|
21
- file.puts input
22
- file.close
20
+ File.open('./test.in', 'w') do |file|
21
+ file.puts input
22
+ file.close
23
23
  end
24
24
 
25
- system "/opt/wandbox/gcc-head/bin/gcc main.c -o main -O2"
26
- system "timeout -s 9 " + time + " ./main < test.in"
25
+ system('/opt/wandbox/gcc-head/bin/gcc main.c -o main -O2')
26
+ system('timeout -s 9 ' + time + ' ./main < test.in')
@@ -1,26 +1,26 @@
1
1
  require 'base64'
2
2
 
3
- File.open("stdin.txt.bz2", "wb") do |file|
4
- file.write Base64.decode64 $stdin.read
5
- file.close
3
+ File.open('stdin.txt.bz2', 'wb') do |file|
4
+ file.write Base64.decode64 $stdin.read
5
+ file.close
6
6
  end
7
7
 
8
- system("bunzip2 stdin.txt.bz2")
8
+ system('bunzip2 stdin.txt.bz2')
9
9
 
10
- stdin = File.open("stdin.txt").read.split("\n<$><*><$>\n")
10
+ stdin = File.open('stdin.txt').read.split("\n<$><*><$>\n")
11
11
  code = stdin[0]
12
12
  input = stdin[1]
13
13
  time = stdin[2]
14
14
 
15
- File.open("./main.cpp", "w") do |file|
16
- file.puts code
17
- file.close
15
+ File.open('./main.cpp', 'w') do |file|
16
+ file.puts code
17
+ file.close
18
18
  end
19
19
 
20
- File.open("./test.in", "w") do |file|
21
- file.puts input
22
- file.close
20
+ File.open('./test.in', 'w') do |file|
21
+ file.puts input
22
+ file.close
23
23
  end
24
24
 
25
- system "/opt/wandbox/gcc-head/bin/g++ main.cpp -o main -O2"
26
- system "timeout -s 9 " + time + " ./main < test.in"
25
+ system('/opt/wandbox/gcc-head/bin/g++ main.cpp -o main -O2')
26
+ system('timeout -s 9 ' + time + ' ./main < test.in')
@@ -1,25 +1,25 @@
1
1
  require 'base64'
2
2
 
3
- File.open("stdin.txt.bz2", "wb") do |file|
4
- file.write Base64.decode64 $stdin.read
5
- file.close
3
+ File.open('stdin.txt.bz2', 'wb') do |file|
4
+ file.write Base64.decode64 $stdin.read
5
+ file.close
6
6
  end
7
7
 
8
- system("bunzip2 stdin.txt.bz2")
8
+ system('bunzip2 stdin.txt.bz2')
9
9
 
10
- stdin = File.open("stdin.txt").read.split("\n<$><*><$>\n")
10
+ stdin = File.open('stdin.txt').read.split("\n<$><*><$>\n")
11
11
  code = stdin[0]
12
12
  input = stdin[1]
13
13
  time = stdin[2]
14
14
 
15
- File.open("./main.go", "w") do |file|
16
- file.puts code
17
- file.close
15
+ File.open('./main.go', 'w') do |file|
16
+ file.puts code
17
+ file.close
18
18
  end
19
19
 
20
- File.open("./test.in", "w") do |file|
21
- file.puts input
22
- file.close
20
+ File.open('./test.in', 'w') do |file|
21
+ file.puts input
22
+ file.close
23
23
  end
24
24
 
25
- system "timeout -s 9 " + time + " /opt/wandbox/go-head/bin/go run main.go < test.in"
25
+ system('timeout -s 9 ' + time + ' /opt/wandbox/go-head/bin/go run main.go < test.in')
@@ -1,25 +1,25 @@
1
1
  require 'base64'
2
2
 
3
- File.open("stdin.txt.bz2", "wb") do |file|
4
- file.write Base64.decode64 $stdin.read
5
- file.close
3
+ File.open('stdin.txt.bz2', 'wb') do |file|
4
+ file.write Base64.decode64 $stdin.read
5
+ file.close
6
6
  end
7
7
 
8
- system("bunzip2 stdin.txt.bz2")
8
+ system('bunzip2 stdin.txt.bz2')
9
9
 
10
- stdin = File.open("stdin.txt").read.split("\n<$><*><$>\n")
10
+ stdin = File.open('stdin.txt').read.split("\n<$><*><$>\n")
11
11
  code = stdin[0]
12
12
  input = stdin[1]
13
13
  time = stdin[2]
14
14
 
15
- File.open("./main.hs", "w") do |file|
16
- file.puts code
17
- file.close
15
+ File.open('./main.hs', 'w') do |file|
16
+ file.puts code
17
+ file.close
18
18
  end
19
19
 
20
- File.open("./test.in", "w") do |file|
21
- file.puts input
22
- file.close
20
+ File.open('./test.in', 'w') do |file|
21
+ file.puts input
22
+ file.close
23
23
  end
24
24
 
25
- system "timeout -s 9 " + time + " /opt/wandbox/ghc-head/bin/runghc main.hs < test.in"
25
+ system('timeout -s 9 ' + time + ' /opt/wandbox/ghc-head/bin/runghc main.hs < test.in')
@@ -1,25 +1,25 @@
1
1
  require 'base64'
2
2
 
3
- File.open("stdin.txt.bz2", "wb") do |file|
4
- file.write Base64.decode64 $stdin.read
5
- file.close
3
+ File.open('stdin.txt.bz2', 'wb') do |file|
4
+ file.write Base64.decode64 $stdin.read
5
+ file.close
6
6
  end
7
7
 
8
- system("bunzip2 stdin.txt.bz2")
8
+ system('bunzip2 stdin.txt.bz2')
9
9
 
10
- stdin = File.open("stdin.txt").read.split("\n<$><*><$>\n")
10
+ stdin = File.open('stdin.txt').read.split("\n<$><*><$>\n")
11
11
  code = stdin[0]
12
12
  input = stdin[1]
13
13
  time = stdin[2]
14
14
 
15
- File.open("./main.py", "w") do |file|
16
- file.puts code
17
- file.close
15
+ File.open('./main.py', 'w') do |file|
16
+ file.puts code
17
+ file.close
18
18
  end
19
19
 
20
- File.open("./test.in", "w") do |file|
21
- file.puts input
22
- file.close
20
+ File.open('./test.in', 'w') do |file|
21
+ file.puts input
22
+ file.close
23
23
  end
24
24
 
25
- system "timeout -s 9 " + time + " /opt/wandbox/cpython-head/bin/python3 main.py < test.in"
25
+ system('timeout -s 9 ' + time + ' /opt/wandbox/cpython-head/bin/python3 main.py < test.in')
@@ -1,25 +1,25 @@
1
1
  require 'base64'
2
2
 
3
- File.open("stdin.txt.bz2", "wb") do |file|
4
- file.write Base64.decode64 $stdin.read
5
- file.close
3
+ File.open('stdin.txt.bz2', 'wb') do |file|
4
+ file.write Base64.decode64 $stdin.read
5
+ file.close
6
6
  end
7
7
 
8
- system("bunzip2 stdin.txt.bz2")
8
+ system('bunzip2 stdin.txt.bz2')
9
9
 
10
- stdin = File.open("stdin.txt").read.split("\n<$><*><$>\n")
10
+ stdin = File.open('stdin.txt').read.split("\n<$><*><$>\n")
11
11
  code = stdin[0]
12
12
  input = stdin[1]
13
13
  time = stdin[2]
14
14
 
15
- File.open("./main.rb", "w") do |file|
16
- file.puts code
17
- file.close
15
+ File.open('./main.rb', 'w') do |file|
16
+ file.puts code
17
+ file.close
18
18
  end
19
19
 
20
- File.open("./test.in", "w") do |file|
21
- file.puts input
22
- file.close
20
+ File.open('./test.in', 'w') do |file|
21
+ file.puts input
22
+ file.close
23
23
  end
24
24
 
25
- system "timeout -s 9 " + time + " /opt/wandbox/ruby-head/bin/ruby main.rb < test.in"
25
+ system('timeout -s 9 ' + time + ' /opt/wandbox/ruby-head/bin/ruby main.rb < test.in')
@@ -1,26 +1,26 @@
1
1
  require 'base64'
2
2
 
3
- File.open("stdin.txt.bz2", "wb") do |file|
4
- file.write Base64.decode64 $stdin.read
5
- file.close
3
+ File.open('stdin.txt.bz2', 'wb') do |file|
4
+ file.write Base64.decode64 $stdin.read
5
+ file.close
6
6
  end
7
7
 
8
- system("bunzip2 stdin.txt.bz2")
8
+ system('bunzip2 stdin.txt.bz2')
9
9
 
10
- stdin = File.open("stdin.txt").read.split("\n<$><*><$>\n")
10
+ stdin = File.open('stdin.txt').read.split("\n<$><*><$>\n")
11
11
  code = stdin[0]
12
12
  input = stdin[1]
13
13
  time = stdin[2]
14
14
 
15
- File.open("./main.swift", "w") do |file|
16
- file.puts code
17
- file.close
15
+ File.open('./main.swift', 'w') do |file|
16
+ file.puts code
17
+ file.close
18
18
  end
19
19
 
20
- File.open("./test.in", "w") do |file|
21
- file.puts input
22
- file.close
20
+ File.open('./test.in', 'w') do |file|
21
+ file.puts input
22
+ file.close
23
23
  end
24
24
 
25
- system "/opt/wandbox/swift-head/usr/bin/swiftc main.swift -o main"
26
- system "timeout -s 9 " + time + " ./main < test.in"
25
+ system('/opt/wandbox/swift-head/usr/bin/swiftc main.swift -o main')
26
+ system('timeout -s 9 ' + time + ' ./main < test.in')
@@ -1,74 +1,57 @@
1
- require "judge_system/version"
1
+ require 'judge_system/version'
2
2
  require 'zlib_input'
3
- require "net/http"
4
- require "uri"
5
- require "json"
6
- require 'timeout'
7
- require 'pathname'
3
+ require 'net/http'
4
+ require 'uri'
5
+ require 'json'
8
6
 
9
7
  module JudgeSystem
10
- class WandBox
8
+ class WandBox
9
+ def self.compile(compiler: '', code: '', stdin: '')
10
+ body = {
11
+ code: code,
12
+ compiler: compiler,
13
+ stdin: stdin
14
+ }.to_json
11
15
 
12
- def self.compile compiler: "", code: "", stdin: ""
13
- body = {
14
- code: code,
15
- compiler: compiler,
16
- stdin: stdin,
17
- }
18
- uri = URI.parse("http://melpon.org/wandbox/api/compile.json")
19
- request = Net::HTTP::Post.new(uri.request_uri, initheader = { "Content-type" => "application/json" },)
20
- request.body = JSON.generate body
21
- http = Net::HTTP.new(uri.host, uri.port)
22
- http.start do |http|
23
- response = http.request(request)
24
- JSON.parse(response.body)
25
- end
26
- end
16
+ uri = URI.parse('http://melpon.org/wandbox/api/compile.json')
17
+ request = Net::HTTP::Post.new(uri.request_uri, 'Content-type' => 'application/json')
18
+ request.body = body
19
+ http = Net::HTTP.new(uri.host, uri.port)
20
+ response = http.request(request)
21
+ JSON.parse(response.body)
22
+ end
27
23
 
28
- def self.run lang, code, input, time
29
- path = File.expand_path('../', __FILE__ )
30
- sys = File.open("#{path}/compile_systems/#{lang}_system.rb", "r").read
31
- data = nil
32
- spliter = "\n<$><*><$>\n"
33
- stdin = BZip2Input.compress(code + spliter + input + spliter + ("%f" % time))
34
- begin
35
- data = compile( compiler: "ruby-head", code: sys, stdin: stdin )
36
- rescue
37
- return 'RE'
38
- end
39
- error = data["program_error"]
40
- result = data["program_output"]
41
- if error == "Killed\n"
42
- return 'TLE'
43
- elsif result == nil && error
44
- return "RE"
45
- else
46
- return result
47
- end
48
- end
49
- private_class_method :compile, :run
50
-
51
- public
52
- def self.judge lang, code , answer, stdin, time
53
- output = run lang, code, stdin, time
54
- if output == 'TLE'
55
- return 'TLE'
56
- elsif output == 'RE'
57
- return 'RE'
58
- else
59
- result = output == answer
60
- if result
61
- return 'AC'
62
- else
63
- return 'WA'
64
- end
65
- end
66
- end
67
- end
24
+ def self.run(lang, code, input, time)
25
+ path = File.expand_path('../', __FILE__)
26
+ sys = File.open("#{path}/compile_systems/#{lang}_system.rb", 'r').read
27
+ data = nil
28
+ spliter = "\n<$><*><$>\n"
29
+ stdin = BZip2Input.compress(code + spliter + input + spliter + format('%f', time))
30
+ begin
31
+ data = compile(compiler: 'ruby-head', code: sys, stdin: stdin)
32
+ rescue
33
+ return 'RE'
34
+ end
35
+ error = data['program_error']
36
+ result = data['program_output']
37
+ return 'TLE' if error == "Killed\n"
38
+ return 'RE' if result.nil? && error
39
+ result
40
+ end
68
41
 
69
- def judge_result lang: "", code: "" , answer: "", stdin: "", time: 20
70
- WandBox.judge lang, code, answer, stdin, time
71
- end
42
+ private_class_method :compile, :run
72
43
 
73
- module_function :judge_result
44
+ def self.judge(lang, code, answer, stdin, time)
45
+ output = run(lang, code, stdin, time)
46
+ return 'TLE' if output == 'TLE'
47
+ return 'RE' if output == 'RE'
48
+ output == answer ? 'AC' : 'WA'
49
+ end
50
+ end
51
+
52
+ def judge_result(lang: '', code: '', answer: '', stdin: '', time: 20)
53
+ WandBox.judge(lang, code, answer, stdin, time)
54
+ end
55
+
56
+ module_function :judge_result
74
57
  end
@@ -1,3 +1,3 @@
1
1
  module JudgeSystem
2
- VERSION = "1.7.2"
2
+ VERSION = '1.7.3'.freeze
3
3
  end
@@ -1,12 +1,12 @@
1
1
  require 'rbzip2'
2
2
  require 'base64'
3
3
  module BZip2Input
4
- def compress input
5
- string = StringIO.new
6
- bz2 = RBzip2::FFI::Compressor.new string
7
- bz2.write input
8
- bz2.close
9
- Base64.encode64(string.string)
10
- end
11
- module_function :compress
12
- end
4
+ def compress(input)
5
+ string = StringIO.new
6
+ bz2 = RBzip2::FFI::Compressor.new string
7
+ bz2.write input
8
+ bz2.close
9
+ Base64.encode64(string.string)
10
+ end
11
+ module_function :compress
12
+ end
@@ -12,6 +12,12 @@ build:
12
12
  # http://devcenter.wercker.com/docs/steps/index.html
13
13
  steps:
14
14
  - bundle-install
15
+
16
+ - script:
17
+ name: run lint tool
18
+ code: bundle exec rubocop
19
+
15
20
  - script:
16
21
  name: rspec
17
22
  code: bundle exec rspec
23
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: judge_system
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.2
4
+ version: 1.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - getty104
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-02 00:00:00.000000000 Z
11
+ date: 2017-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rbzip2
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.42.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.42.0
83
97
  description: "This is a judge system for online judge. \nThis gem work on the wandbox
84
98
  api."
85
99
  email:
@@ -90,7 +104,7 @@ extra_rdoc_files: []
90
104
  files:
91
105
  - ".gitignore"
92
106
  - ".rspec"
93
- - ".ruby-version"
107
+ - ".rubocop.yml"
94
108
  - ".travis.yml"
95
109
  - CODE_OF_CONDUCT.md
96
110
  - Gemfile
@@ -1 +0,0 @@
1
- 2.3.3