@@ -104,40 +104,40 @@ def setup_test_cases_content(self):
104
104
105
105
for i , tc in enumerate ([x for x in test_cases if x .is_pretest ]):
106
106
self .append_tescase_to_statement (zip , content , tc , i )
107
- last = i
108
-
109
- if last > 0 :
110
- last += 1
107
+ last = i + 1
111
108
112
109
for i , tc in enumerate ([x for x in test_cases if not x .is_pretest ]):
113
110
self .append_tescase_to_statement (zip , content , tc , i + last )
114
111
115
112
self .test_cases_content = '\n ' .join (content )
116
113
117
114
def append_tescase_to_statement (self , zip , content , tc , i ):
118
- content .append (f'## Sample Input { i + 1 } ' )
119
- content .append ('' )
115
+ content .append (f'## Test Case { i + 1 } ' )
120
116
121
117
if tc .is_private :
122
118
content .append ('*Hidden: this is a private test case!* ' )
123
119
124
120
else :
121
+ content .append ('### Input' )
125
122
content .append ('```' )
126
- content .append (zip .read (tc .input_file ).decode ('utf-8' ))
123
+ if tc .input_file != '' :
124
+ content .append (zip .read (tc .input_file ).decode ('utf-8' ))
127
125
content .append ('```' )
128
126
129
- content .append ('' )
130
- content .append (f'## Sample Output { i + 1 } ' )
131
- content .append ('' )
132
-
133
- if tc .is_private :
134
- content .append ('*Hidden: this is a private test case!* ' )
135
-
136
- else :
127
+ content .append ('' )
128
+ content .append ('### Output' )
137
129
content .append ('```' )
138
- content .append (zip .read (tc .output_file ).decode ('utf-8' ))
130
+ if tc .output_file != '' :
131
+ content .append (zip .read (tc .output_file ).decode ('utf-8' ))
139
132
content .append ('```' )
140
133
134
+ if tc .explanation_file != '' :
135
+ content .append ('' )
136
+ content .append ('### Explanation' )
137
+
138
+ if tc .explanation_file != '' :
139
+ content .append (zip .read (tc .explanation_file ).decode ('utf-8' ))
140
+
141
141
content .append ('' )
142
142
143
143
def infer_test_cases_from_zip (self ):
@@ -157,6 +157,22 @@ def infer_test_cases_from_zip(self):
157
157
input = [x for x in files if '.in' in x or ('input' in x and '.' in x )]
158
158
output = [x for x in files if '.out' in x or ('output' in x and '.' in x )]
159
159
160
+ # Not all explanations are mandatory, so there can be gaps!
161
+ input .sort ()
162
+ output .sort ()
163
+ explanation = []
164
+ for i in range (len (input )):
165
+ in_file = input [i ]
166
+
167
+ xpl_file = in_file .replace ('input' , 'explanation' ) if 'input' in in_file else in_file .replace ('in' , 'xpl' )
168
+ found = [x for x in files if xpl_file in x ]
169
+ found .sort ()
170
+
171
+ if len (found ) > 0 :
172
+ explanation .append (found [0 ])
173
+ else :
174
+ explanation .append ('' )
175
+
160
176
cases = []
161
177
for i in range (len (input )):
162
178
list = ProblemTestCase .objects .filter (dataset_id = self .problem .pk , input_file = input [i ],
@@ -173,6 +189,7 @@ def infer_test_cases_from_zip(self):
173
189
ptc .order = i
174
190
ptc .input_file = input [i ]
175
191
ptc .output_file = output [i ]
192
+ ptc .explanation_file = explanation [i ]
176
193
ptc .points = 0
177
194
178
195
cases .append (ptc )
@@ -242,6 +259,9 @@ def _load_test_case_from_doc(self, doc, field, is_pretest):
242
259
if test .get ('out' ):
243
260
ptc .output_file = test ['out' ]
244
261
262
+ if test .get ('xpl' ):
263
+ ptc .explanation_file = test ['xpl' ]
264
+
245
265
if test .get ('points' ):
246
266
ptc .points = test ['points' ]
247
267
else :
@@ -287,6 +307,7 @@ class ProblemTestCase(models.Model):
287
307
default = 'C' )
288
308
input_file = models .CharField (max_length = 100 , verbose_name = _ ('input file name' ), blank = True )
289
309
output_file = models .CharField (max_length = 100 , verbose_name = _ ('output file name' ), blank = True )
310
+ explanation_file = models .CharField (max_length = 100 , verbose_name = _ ('explanation file name' ), blank = True )
290
311
generator_args = models .TextField (verbose_name = _ ('generator arguments' ), blank = True )
291
312
points = models .IntegerField (verbose_name = _ ('point value' ), blank = True , null = True )
292
313
is_pretest = models .BooleanField (verbose_name = _ ('case is pretest?' ), default = False )
0 commit comments