view 2.00/problem.py @ 19:d4fc9341664e 1.20.2

Fixed an exception when tests.zip contained test cases in its root
author Oleg Oshmyan <chortos@inbox.lv>
date Sun, 13 Jun 2010 12:46:49 +0000
parents f2279b7602d3
children ec6f1a132109
line wrap: on
line source

#!/usr/bin/python
# Copyright (c) 2010 Chortos-2 <chortos@inbox.lv>

try:
	import config as _config, testcases as _testcases
except ImportError as e:
	import __main__
	__main__.import_error(e)

# LIBRARY and STDIO refer to interactive aka reactive problems
BATCH, OUTONLY, LIBRARY, STDIO, BESTOUT = xrange(5)

class Problem(object):
	__slots__ = 'name', 'config', 'cache', 'testcases'
	
	def __init__(prob, name):
		if not isinstance(name, basestring):
			# This shouldn't happen, of course
			raise TypeError, "Problem() argument 1 must be string, not " + str(type(name)).split('\'')[1]
		prob.name = name
		prob.config = _config.load_problem(name)
		prob.cache = type('Cache', (object,), {'padoutputtolength': 0})()
		prob.testcases = _testcases.load_problem(prob)
	
	def test(prob):
		real = max = 0
		for case in prob.testcases:
			r, m = case()
			real += r
			max += m
		return real, max