# -*- coding: utf-8 -*-
# $Id: Cl.py 1634 2013-04-12 15:36:36Z amelung $
#
# Copyright (c) 2007-2011 Otto-von-Guericke-Universität Magdeburg
#
# This file is part of ECSpooler.
import random
import logging
# local imports
# The placeholder for the names of the packages that the model and
# student solution will be put in
# load Cl function to do a simple test
try:
# load Cl function to do a test which allows permutation of list elems
# try:
# permTest = file(join(dirname(__file__), 'permTest.lisp'), 'r').read()
# except IOError, ioe:
# logging.warn('%s: %s' % (sys.exc_info()[0], ioe))
# permTest = ''
SYNTAX_TEMPLATE = \
"""
;; -------------------------------------------------------------------
${SOURCE}
;; -------------------------------------------------------------------
"""
"""
;; helper functions
${helpFunctions}
;; -------------------------------------------------------------------
${SOURCE}
;; -------------------------------------------------------------------
(defun main ()
(progn
${testData}))
"""
WRAPPER_TEMPLATE = \
'''
;; load the model and the student packages
(load "${%s}.lisp") ; student package
(defparameter ${%s} (main))
(load "${%s}.lisp") ; model package
(defparameter ${%s} (main))
;; test function
${testFunction}
;; print test results
(format t "isEqual=~a;;expected=~a;;received=~a~%%"
(test ${%s} ${%s}) ; model, student
${%s} ; model
${%s}) ; student
)
# input schema
'modelSolution',
),
'helpFunctions',
),
'testData',
#accessor = # must return a list; default is one element per line
'A function call consists of the ' +
'function name (given in the exercise directives) ' +
'and test data as parameters of this funtion, e.g, '+
"tally 'a '(a b c 1 2 3 b c a)"+
'Each function call must be written in a single line.',
),
))
# testSchema
'simple',
),
# TestEnvironment(
# 'permutation',
# label = 'Permutation',
# description = 'Permutations are allowed.',
# test = permTest,
# syntax = SYNTAX_TEMPLATE,
# semantic = WRAPPER_TEMPLATE,
# lineNumberOffset = 6,
# compiler = config.INTERPRETER,
# interpreter = config.INTERPRETER,
# ),
))
"""
This backend tests Common Lisp programs by comparing student and
model solution on given test data.
"""
"""
This constructor is needed to reset the logging environment.
"""
# -- syntax check ---------------------------------------------------------
"""
@see: lib.AbtractProgrammingBackend._preProcessCheckSyntax
"""
result = ''
else:
return result, 'student'
"""
@see: lib.AbtractProgrammingBackend._postProcessCheckSyntax
"""
# With SBCL, the first line on NetBSD is always
#
#
# This line is removed here.
# Also, in case of an error, the last line of SBCL's output is
# always
#
# unhandled condition in --disable-debugger mode, quitting
#
# This and the preceding empty line are also removed.
# -- semantic check -------------------------------------------------------
"""
@see: lib.AbtractProgrammingBackend._postProcessCheckSyntax
"""
"""
Checks semantic of a Haskell programs.
@return: a BackendResult object with result value and message
@see: lib.ProgrammingBackend._process_checkSemantics
"""
def mk_pkg_name():
l=list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
return ''.join(l)
PKG_MODEL=None
while True:
if PKG_MODEL!=PKG_STUDENT:
break
# test for available test specs
msg = 'No test specification selected.'
# test for defined repeat fields in the schema definition
assert repeatFields, 'No RepeatField found.'
# test for available test data
msg = 'No test data defined.'
# get model solution and students' submission
"Semantic check requires valid 'model solution' (%s)" % \
"Semantic check requires valid 'student solution' (%s)" % \
# prepare source code for model and student' solution which will be
# stored in seperate files as modules
#log.debug('modelSrc: %s\n' % modelSrc)
#log.debug('studentSrc: %s\n' % studentSrc)
# define return values
# run selected test specifications
if not solved: break
# get the interpreter
# get wrapper code for semantic check
# get values for all other input fields from schema which are
# available in the job data, e.g., helpFunctions
# insert test function into wrapper code
# replace package names
(NS_STUDENT, PKG_STUDENT)):
# remove all remaining placeholders
#log.debug('wrapper: %s\n' % wrapper)
# run with all test data
for t in testdata:
# add testdata to model and student modules' source code
# remove all remaining placeholders
try:
# 1st write model solution
# 2nd write students' solution
# last write the wrapper and execute
except Exception, e:
msg = 'Internal error during semantic check: %s: %s' % \
# an error occured
result = "\nYour submission failed. Test case was: " \
"'%s' (%s) \n\n Received result: %s" \
# has the students' solution passed this tests?
else:
#log.debug('result: %s' % result)
#log.debug('isEqual: %s' % isEqual)
#log.debug('expected: %s' % expected)
#log.debug('received: %s' % received)
if isEqual != 'T':
# TODO: i18n
feedback = "\nYour submission failed. Test " \
"case was: '%s' (%s)" \
feedback += '\n\n Expected result: %s\n ' \
'Received result: %s' \
break # means: end testing right now
# end inner for loop
#end out for loop
if solved:
# TODO: i18n
feedback = '\nYour submission passed all tests.'