judge_system 1.2.1 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 43d41a84b8a1110652bd4dd5b85edfa6e00ca0f4
4
- data.tar.gz: 04765454ee78cc2275839ea9f8326648b4c90820
3
+ metadata.gz: 6bef44e28ea19331d8b7fe9e3beaff4f066ffabb
4
+ data.tar.gz: 11a5efed6d3535483c702248bef664eec7b6d4ab
5
5
  SHA512:
6
- metadata.gz: 15d83599c04aa051ea50dfa28aa7da883dfe69f90c9d8f8effc9ccbf3b2499e73695eddcfadf9cea75a092c9650c48fb23115cb6322863aa77f5ac1444c9dbc9
7
- data.tar.gz: 5ae8abcfffcf38c2bdb4cc27a5aee5b13c4530523d980d6a78c34ca803e23aba6b498ae09c58609c4ef9041bbe2613195523c1444e4b117fcdb57d32ab0eb8bc
6
+ metadata.gz: 9b2c400478b053ae0f2a6a55980e89dd92990580c96a103c7650c16ea8a518b4922022cd9e60f4f6d9f16326bc727059d21dfe33aac3b615815f4b9ffa7fb21f
7
+ data.tar.gz: '06863728db1303afa46c1dd6fa902fb73254067ea578ac90c41c2873c0e3870403586f6a30e18a280a8b618c0dfe0e141bc7061ccbaffc316817ff08a69437c7'
data/lib/judge_system.rb CHANGED
@@ -6,45 +6,32 @@ require 'timeout'
6
6
  require 'pathname'
7
7
 
8
8
  module JudgeSystem
9
- module Wandbox
10
- module Web
11
- def compile compiler: "", code: "", codes: [], options: "", stdin: "", compiler_option_raw: "", runtime_option_raw: "", save: false
12
- body = {
13
- "code" => code,
14
- "compiler" => compiler,
15
- "codes" => codes,
16
- "options" => options,
17
- "stdin" => stdin,
18
- "compiler-option-raw" => compiler_option_raw,
19
- "runtime-option-raw" => runtime_option_raw,
20
- "save" => save,
21
- }
22
- uri = URI.parse("http://melpon.org/wandbox/api/compile.json")
23
-
24
- request = Net::HTTP::Post.new(uri.request_uri, initheader = { "Content-type" => "application/json" },)
25
- request.body = body.to_json
26
- http = Net::HTTP.new(uri.host, uri.port)
27
-
28
-
29
- http.start do |http|
30
- response = http.request(request)
31
- JSON.parse(response.body)
32
- end
33
-
9
+ class WandBox
10
+
11
+ def self.compile compiler: "", code: "", stdin: ""
12
+ body = {
13
+ code: code,
14
+ compiler: compiler,
15
+ stdin: stdin,
16
+ }
17
+ uri = URI.parse("http://melpon.org/wandbox/api/compile.json")
18
+ request = Net::HTTP::Post.new(uri.request_uri, initheader = { "Content-type" => "application/json" },)
19
+ request.body = body.to_json
20
+ http = Net::HTTP.new(uri.host, uri.port)
21
+ http.start do |http|
22
+ response = http.request(request)
23
+ JSON.parse(response.body)
34
24
  end
35
- module_function :compile
36
25
  end
37
- end
38
26
 
39
- module Wandbox
40
- def run lang, code, input, time
27
+ def self.run lang, code, input, time
41
28
  path = File.expand_path('../', __FILE__ )
42
29
  sys = File.open("#{path}/compile_systems/#{lang}_system.cpp", "r").read
43
30
  data = nil
44
31
  spliter = "\n<$><*><$>\n"
45
32
  stdin = code + spliter + input + spliter + time.to_s
46
33
  begin
47
- data = Web.compile({ compiler: "gcc-head", code: sys, stdin: stdin })
34
+ data = compile( compiler: "gcc-head", code: sys, stdin: stdin )
48
35
  rescue
49
36
  return 'RE'
50
37
  end
@@ -58,23 +45,28 @@ module JudgeSystem
58
45
  return result
59
46
  end
60
47
  end
61
- module_function :run
62
- end
63
-
64
- def judge_result lang: "", code: "" , answer: "", stdin: "", time: 100
65
- output = Wandbox.run lang, code, stdin, time
66
- if output == 'TLE'
67
- return 'TLE'
68
- elsif output == 'RE'
69
- return 'RE'
70
- else
71
- result = output == answer
72
- if result
73
- return 'AC'
48
+ private_class_method :compile, :run
49
+ public
50
+ def self.judge lang, code , answer, stdin, time
51
+ output = run lang, code, stdin, time
52
+ if output == 'TLE'
53
+ return 'TLE'
54
+ elsif output == 'RE'
55
+ return 'RE'
74
56
  else
75
- return 'WA'
57
+ result = output == answer
58
+ if result
59
+ return 'AC'
60
+ else
61
+ return 'WA'
62
+ end
76
63
  end
77
64
  end
78
65
  end
66
+
67
+ def judge_result lang: "", code: "" , answer: "", stdin: "", time: 100
68
+ WandBox.judge lang, code, answer, stdin, time
69
+ end
70
+
79
71
  module_function :judge_result
80
72
  end
@@ -1,3 +1,3 @@
1
1
  module JudgeSystem
2
- VERSION = "1.2.1"
2
+ VERSION = "1.2.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: judge_system
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toshifumi Kiyono