comparison testcases.py @ 104:8f46e84922f9

Output-only problems are now supported
author Oleg Oshmyan <chortos@inbox.lv>
date Fri, 08 Apr 2011 17:42:30 +0300
parents 4e6f231f055f
children 9f922b11c98a
comparison
equal deleted inserted replaced
103:4e6f231f055f 104:8f46e84922f9
126 'process', 'time_started', 'time_stopped', 126 'process', 'time_started', 'time_stopped',
127 'realinname', 'realoutname', 'maxcputime', 'maxwalltime', 127 'realinname', 'realoutname', 'maxcputime', 'maxwalltime',
128 'maxmemory', 'has_called_back', 'files_to_delete', 128 'maxmemory', 'has_called_back', 'files_to_delete',
129 'cpu_time_limit_string', 'wall_time_limit_string', 129 'cpu_time_limit_string', 'wall_time_limit_string',
130 'time_limit_string') 130 'time_limit_string')
131 needs_realinname = True
131 132
132 if ABCMeta: 133 if ABCMeta:
133 __metaclass__ = ABCMeta 134 __metaclass__ = ABCMeta
134 135
135 def __init__(case, prob, id, isdummy, points): 136 def __init__(case, prob, id, isdummy, points):
147 if case.maxwalltime: 148 if case.maxwalltime:
148 case.wall_time_limit_string = '/%.3f' % case.maxwalltime 149 case.wall_time_limit_string = '/%.3f' % case.maxwalltime
149 else: 150 else:
150 case.wall_time_limit_string = '' 151 case.wall_time_limit_string = ''
151 if not isdummy: 152 if not isdummy:
152 case.realinname = case.problem.config.testcaseinname 153 if case.needs_realinname:
154 case.realinname = case.problem.config.testcaseinname
153 case.realoutname = case.problem.config.testcaseoutname 155 case.realoutname = case.problem.config.testcaseoutname
154 else: 156 else:
155 case.realinname = case.problem.config.dummyinname 157 if case.needs_realinname:
158 case.realinname = case.problem.config.dummyinname
156 case.realoutname = case.problem.config.dummyoutname 159 case.realoutname = case.problem.config.dummyoutname
157 160
158 @abstractmethod 161 @abstractmethod
159 def test(case): 162 def test(case):
160 raise NotImplementedError 163 raise NotImplementedError
333 336
334 337
335 # This is the only test case type not executing any programs to be tested 338 # This is the only test case type not executing any programs to be tested
336 class OutputOnlyTestCase(ValidatedTestCase): 339 class OutputOnlyTestCase(ValidatedTestCase):
337 __slots__ = () 340 __slots__ = ()
338 def cleanup(case): pass 341 needs_realinname = False
342
343 def cleanup(case):
344 pass
345
346 def test(case, callback):
347 case.time_stopped = case.time_started = 0
348 case.has_called_back = True
349 callback()
350 with open(case.problem.config.outname.replace('$', case.id), 'rU') as output:
351 return case.validate(output)
352
339 353
340 class BestOutputTestCase(ValidatedTestCase): 354 class BestOutputTestCase(ValidatedTestCase):
341 __slots__ = () 355 __slots__ = ()
356
342 357
343 # This is the only test case type executing two programs simultaneously 358 # This is the only test case type executing two programs simultaneously
344 class ReactiveTestCase(TestCase): 359 class ReactiveTestCase(TestCase):
345 __slots__ = () 360 __slots__ = ()
346 # The basic idea is to launch the program to be tested and the grader 361 # The basic idea is to launch the program to be tested and the grader