# -*- coding: utf-8 -*-
# $Id: Scheme.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 logging
# local imports
# load Scheme function to do a simple test
try:
# load Haskell function to do a test which allows permutation of list elems
try:
SYNTAX_TEMPLATE = \
""";; import SICP streams
(require (file "%s"))
;; -------------------------------------------------------------------
${SOURCE}
;; -------------------------------------------------------------------
"""(module ${MODULE} mzscheme
(require (file "%s")) ;; import SICP streams
(define (main) ${testData})
;; -------------------------------------------------------------------
${SOURCE}
;; -------------------------------------------------------------------
;; helper functions
${helpFunctions}
(provide main))
WRAPPER_TEMPLATE = \
""";; required modules
(require (prefix model. (file "model.scm")))
(require (prefix student. (file "student.scm")))
;; test function
${testFunction}
;; print test results
(let-values (((ms ss) (values (model.main) (student.main))))
(printf "isEqual=~s;;expected=~s;;received=~s" (test ms ss) ms ss))
"""
# 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',
),
'permutation',
),
))
"""
This backend tests Scheme 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
"""
try:
# find line number in result
#log.debug("xxx: %s" % matches)
if matches:
# set line number minus x lines and return
except Exception, e:
return message
# -- 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
"""
# 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
# 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 in wrapper code
# remove all remaining placeholders
# 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)
# 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.'