Class: Judge0::Submission

Inherits:
Object
  • Object
show all
Defined in:
lib/submission.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Submission

Returns a new instance of Submission.

Yields:

  • (_self)

Yield Parameters:



14
15
16
17
18
19
# File 'lib/submission.rb', line 14

def initialize(options = {})
  options.each do |key, value|
    instance_variable_set("@#{key}", value)
  end
  yield(self) if block_given?
end

Instance Attribute Details

#compile_outObject (readonly)

Returns the value of attribute compile_out.



11
12
13
# File 'lib/submission.rb', line 11

def compile_out
  @compile_out
end

#cpu_extra_timeObject

Returns the value of attribute cpu_extra_time.



3
4
5
# File 'lib/submission.rb', line 3

def cpu_extra_time
  @cpu_extra_time
end

#cpu_time_limitObject

Returns the value of attribute cpu_time_limit.



3
4
5
# File 'lib/submission.rb', line 3

def cpu_time_limit
  @cpu_time_limit
end

#enable_per_process_and_thread_memory_limitObject

Returns the value of attribute enable_per_process_and_thread_memory_limit.



3
4
5
# File 'lib/submission.rb', line 3

def enable_per_process_and_thread_memory_limit
  @enable_per_process_and_thread_memory_limit
end

#enable_per_process_and_thread_time_limitObject

Returns the value of attribute enable_per_process_and_thread_time_limit.



3
4
5
# File 'lib/submission.rb', line 3

def enable_per_process_and_thread_time_limit
  @enable_per_process_and_thread_time_limit
end

#expected_outputObject

Returns the value of attribute expected_output.



3
4
5
# File 'lib/submission.rb', line 3

def expected_output
  @expected_output
end

#language_idObject

Returns the value of attribute language_id.



3
4
5
# File 'lib/submission.rb', line 3

def language_id
  @language_id
end

#max_file_sizeObject

Returns the value of attribute max_file_size.



3
4
5
# File 'lib/submission.rb', line 3

def max_file_size
  @max_file_size
end

#max_processes_and_or_threadsObject

Returns the value of attribute max_processes_and_or_threads.



3
4
5
# File 'lib/submission.rb', line 3

def max_processes_and_or_threads
  @max_processes_and_or_threads
end

#memoryObject (readonly)

Returns the value of attribute memory.



11
12
13
# File 'lib/submission.rb', line 11

def memory
  @memory
end

#memory_limitObject

Returns the value of attribute memory_limit.



3
4
5
# File 'lib/submission.rb', line 3

def memory_limit
  @memory_limit
end

#number_of_runsObject

Returns the value of attribute number_of_runs.



3
4
5
# File 'lib/submission.rb', line 3

def number_of_runs
  @number_of_runs
end

#source_codeObject

Returns the value of attribute source_code.



3
4
5
# File 'lib/submission.rb', line 3

def source_code
  @source_code
end

#stack_limitObject

Returns the value of attribute stack_limit.



3
4
5
# File 'lib/submission.rb', line 3

def stack_limit
  @stack_limit
end

#status_descriptionObject (readonly)

Returns the value of attribute status_description.



11
12
13
# File 'lib/submission.rb', line 11

def status_description
  @status_description
end

#status_idObject (readonly)

Returns the value of attribute status_id.



11
12
13
# File 'lib/submission.rb', line 11

def status_id
  @status_id
end

#stderrObject (readonly)

Returns the value of attribute stderr.



11
12
13
# File 'lib/submission.rb', line 11

def stderr
  @stderr
end

#stdinObject

Returns the value of attribute stdin.



3
4
5
# File 'lib/submission.rb', line 3

def stdin
  @stdin
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



11
12
13
# File 'lib/submission.rb', line 11

def stdout
  @stdout
end

#timeObject (readonly)

Returns the value of attribute time.



11
12
13
# File 'lib/submission.rb', line 11

def time
  @time
end

#tokenObject (readonly)

Returns the value of attribute token.



11
12
13
# File 'lib/submission.rb', line 11

def token
  @token
end

#wall_time_limitObject

Returns the value of attribute wall_time_limit.



3
4
5
# File 'lib/submission.rb', line 3

def wall_time_limit
  @wall_time_limit
end

Instance Method Details

#resultObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/submission.rb', line 55

def result
  {
    stdout: @stdout,
    time: @time,
    memory: @memory,
    stderr: @stderr,
    compile_out: @compile_out,
    message: @message,
    status: {
      id: @status_id, 
      description: @status_description
    }
  }
end

#runObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/submission.rb', line 21

def run
  res = wait_response(get_token)

  @stdout = res['stdout']
  @time = res['time'].to_f
  @memory = res['memory']
  @stderr = res['stderr']
  @compile_out = res['compile_out']
  @message = res['message']
  @status_id = res['status']['id']
  @status_description = res['status']['description']

  result
end

#tests_battery(tests) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/submission.rb', line 36

def tests_battery (tests)
  tests.map! do |test|
    if test.respond_to?(:input) && test.respond_to?(:output)
      @stdin = test.input
      @expected_output = test.output
    elsif test.include?(:input) && test.respond_to?(:output)
      @stdin = test[:input]
      @expected_output = test[:output]
    else
      @stdin = test[0]
      @expected_output = test[1]
    end
    get_token
  end
  tests.map do |test|
    wait_response(test)
  end
end