-
Notifications
You must be signed in to change notification settings - Fork 13
/
test_case.rb
33 lines (26 loc) · 917 Bytes
/
test_case.rb
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
class TestCase < ActiveRecord::Base
include ActiveModel::ForbiddenAttributesProtection
has_many :test_case_relations, inverse_of: :test_case, dependent: :destroy
has_many :test_sets, through: :test_case_relations
belongs_to :problem, inverse_of: :test_cases, touch: :rejudge_at
validate do
errors.add :input, "cannot be nil" if input.nil?
errors.add :output, "cannot be nil" if output.nil?
end
include RankedModel
ranks :problem_order, with_same: :problem_id
def input=(text)
text << "\n" unless text.end_with?("\n")
super(text.encode(text.encoding, universal_newline: true))
end
def output=(text)
text << "\n" unless text.end_with?("\n")
super(text.encode(text.encoding, universal_newline: true))
end
def truncated_input
JudgeSubmissionWorker.truncate_output(input)
end
def truncated_output
JudgeSubmissionWorker.truncate_output(output)
end
end