Skip to content
Snippets Groups Projects
Commit 3811c435 authored by Tim Hunt's avatar Tim Hunt
Browse files

Integrate answer tests more closely with Moodle.

parent cd3c9c6b
Branches
No related tags found
No related merge requests found
<?php
// This file is part of Stack - http://stack.bham.ac.uk//
//
// Stack is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Stack is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Stack. If not, see <http://www.gnu.org/licenses/>.
/**
* This script runs the answers tests and verifies the results.
*
* This serves two purposes. First, it verifies that the answer tests are working
* correctly, and second it serves to document the expected behaviour of answer
* tests, which is useful for learning how they work.
*
* @copyright 2012 University of Birmingham
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(__FILE__).'/../../../config.php');
require_once($CFG->dirroot .'/course/lib.php');
require_once($CFG->libdir .'/filelib.php');
require_once(dirname(__FILE__) . '/locallib.php');
require_once(dirname(__FILE__) . '/stack/options.class.php');
require_once(dirname(__FILE__) . '/stack/answertest/controller.class.php');
require_once(dirname(__FILE__) . '/stack/answertest/simpletest/fixtures.class.php');
$anstest = optional_param('anstest', '', PARAM_ALPHA);
// Authentication.
require_login();
$context = context_system::instance();
require_capability('moodle/site:config', $context);
// Set up the page object.
$PAGE->set_context($context);
$PAGE->set_url('/question/type/stack/answertests.php');
$title = stack_string('stackInstall_testsuite_title');
$PAGE->set_title($title);
// Get the list of available tests.
$availabletests = stack_answertest_test_data::get_available_tests();
$availabletests['ALL'] = stack_string('all');
if (!array_key_exists($anstest, $availabletests)) {
$anstest = '';
}
if ($anstest === 'ALL') {
$tests = stack_answertest_test_data::get_all();
} else if (!$anstest) {
$tests = array();
} else {
$tests = stack_answertest_test_data::get_tests_for($anstest);
}
// Set up the results table.
$columns = array(
'name' => stack_string('answertest'),
'passed' => stack_string('testsuitecolpassed'),
'studentanswer' => stack_string('studentanswer'),
'teacheranswer' => stack_string('teacheranswer'),
'options' => stack_string('options'),
'error' => stack_string('testsuitecolerror'),
'rawmark' => stack_string('testsuitecolrawmark'),
'expectedscore' => stack_string('testsuitecolexpectedscore'),
'feedback' => stack_string('feedback'),
'answernote' => stack_string('answernote'),
);
if ($anstest !== 'ALL') {
array_shift($columns);
}
$table = new flexible_table('stack_answertests');
$table->define_columns(array_keys($columns));
$table->define_headers(array_values($columns));
$table->set_attribute('class', 'generaltable generalbox stacktestsuite');
$table->define_baseurl($PAGE->url);
$table->setup();
// Start output.
echo $OUTPUT->header();
echo $OUTPUT->heading($title);
echo html_writer::tag('p', stack_string('stackInstall_testsuite_intro'));
echo html_writer::tag('p', stack_string('stackInstall_testsuite_choose'));
echo $OUTPUT->single_select($PAGE->url, 'anstest', $availabletests, $anstest);
// Run the tests.
$allpassed = true;
foreach ($tests as $test) {
list($passed, $error, $rawmark, $feedback, $ansnote) = stack_answertest_test_data::run_test($test);
$allpassed = $allpassed && $passed;
if ($passed) {
$class = 'pass';
$passedcol = stack_string('testsuitepass');
} else {
$class = 'fail';
$passedcol = stack_string('testsuitefail');
}
$row = array(
'name' => $test->name,
'passed' => $passedcol,
'studentanswer' => s($test->studentanswer),
'teacheranswer' => s($test->teacheranswer),
'options' => s($test->options),
'error' => $error,
'rawmark' => $rawmark,
'expectedscore' => $test->expectedscore,
'feedback' => $feedback,
'answernote' => $ansnote,
);
$table->add_data_keyed($row, $class);
}
$table->finish_output();
// Overall summary.
if ($anstest) {
if ($allpassed) {
echo $OUTPUT->heading(stack_string('stackInstall_testsuite_pass'), 2, 'pass');
} else {
echo $OUTPUT->heading(stack_string('stackInstall_testsuite_fail'), 2, 'fail');
}
}
// Finish output.
echo $OUTPUT->footer();
...@@ -55,6 +55,7 @@ $string['true'] = 'True'; ...@@ -55,6 +55,7 @@ $string['true'] = 'True';
$string['ddl_empty'] = 'No choices were provided for this drop-down. Please input a set of values link a,b,c,d'; $string['ddl_empty'] = 'No choices were provided for this drop-down. Please input a set of values link a,b,c,d';
// Support scripts (CAS chat, healthcheck, etc.) // Support scripts (CAS chat, healthcheck, etc.)
$string['all'] = 'All';
$string['chat'] = 'Send to the CAS'; $string['chat'] = 'Send to the CAS';
$string['chat_desc'] = 'The <a href="{$a->link}">CAS chat script</a> lets you test the connection to the CAS, and try out Maxima syntax.'; $string['chat_desc'] = 'The <a href="{$a->link}">CAS chat script</a> lets you test the connection to the CAS, and try out Maxima syntax.';
$string['chatintro'] = 'This page enables CAS text to be evaluated directly. It is a simple script which is a useful minimal example, and a handy way to check if the CAS is working, and to test various inputs.'; $string['chatintro'] = 'This page enables CAS text to be evaluated directly. It is a simple script which is a useful minimal example, and a handy way to check if the CAS is working, and to test various inputs.';
...@@ -69,6 +70,25 @@ $string['healthchecklatex'] = 'Check LaTeX is being converted correctly'; ...@@ -69,6 +70,25 @@ $string['healthchecklatex'] = 'Check LaTeX is being converted correctly';
$string['healthchecklatexintro'] = 'STACK generates LaTeX on the fly, and enables teachers to write LaTeX in questions. It assumes that LaTeX will be converted by a moodle filter. Below are samples of displayed and inline expressions in LaTeX which should be appear correctly in your browser. Problems here indicate incorrect moodle filter settings, not faults with STACK itself. Stack only uses the single and double dollar notation itself, but some question authors may be relying on the other forms.'; $string['healthchecklatexintro'] = 'STACK generates LaTeX on the fly, and enables teachers to write LaTeX in questions. It assumes that LaTeX will be converted by a moodle filter. Below are samples of displayed and inline expressions in LaTeX which should be appear correctly in your browser. Problems here indicate incorrect moodle filter settings, not faults with STACK itself. Stack only uses the single and double dollar notation itself, but some question authors may be relying on the other forms.';
$string['healthcheckplots'] = 'Graph plotting'; $string['healthcheckplots'] = 'Graph plotting';
$string['healthcheckplotsintro'] = 'There should be two different plots. If two identical plots are seen then this is an error in naming the plot files. If no errors are returned, but a plot is not displayed then one of the following may help. (i) check read permissions on the two temporary directories. (ii) change the options used by GNUPlot to create the plot. Currently there is no web interface to these options.'; $string['healthcheckplotsintro'] = 'There should be two different plots. If two identical plots are seen then this is an error in naming the plot files. If no errors are returned, but a plot is not displayed then one of the following may help. (i) check read permissions on the two temporary directories. (ii) change the options used by GNUPlot to create the plot. Currently there is no web interface to these options.';
$string['stackInstall_testsuite_title'] = 'A test suite for STACK Answer tests';
$string['stackInstall_testsuite_title_desc'] = 'The <a href="{$a->link}">answer-tests script</a> verifies that the answer tests are performing correctly. They are also useful to learn by example how each answer-test can be used.';
$string['stackInstall_testsuite_intro'] = 'This page allows you to test that the STACK answer tests are functioning correctly. Note that only answer tests can be checked through the web interface. Other Maxima commands need to be checked from the command line: see unittests.mac.';
$string['stackInstall_testsuite_choose'] = 'Please choose an answer test.';
$string['stackInstall_testsuite_pass'] = 'All tests passed!';
$string['stackInstall_testsuite_fail'] = 'Not all tests passed!';
$string['answertest'] = 'Answer test';
$string['testsuitecolpassed'] = 'Passed?';
$string['studentanswer'] = 'Student response';
$string['teacheranswer'] = 'Teacher answer';
$string['options'] = 'Options';
$string['testsuitecolerror'] = 'CAS errors';
$string['testsuitecolrawmark'] = 'Raw mark';
$string['testsuitecolexpectedscore'] = 'Expected score';
$string['testsuitepass'] = 'Pass';
$string['testsuitefail'] = 'Fail';
$string['feedback'] = 'Feedback';
$string['answernote'] = 'Answer note';
$string['texdisplayedbracket'] = 'Displayed bracket'; $string['texdisplayedbracket'] = 'Displayed bracket';
$string['texinlinebracket'] = 'Inline bracket'; $string['texinlinebracket'] = 'Inline bracket';
$string['texdoubledollar'] = 'Double dollar'; $string['texdoubledollar'] = 'Double dollar';
...@@ -225,11 +245,3 @@ $string['ATSysEquiv_SA_missing_variables'] = 'Your answer is missing one or ...@@ -225,11 +245,3 @@ $string['ATSysEquiv_SA_missing_variables'] = 'Your answer is missing one or
$string['ATSysEquiv_SA_extra_variables'] = 'Your answer includes too many variables!'; $string['ATSysEquiv_SA_extra_variables'] = 'Your answer includes too many variables!';
$string['ATSysEquiv_SA_system_underdetermined'] = 'The equations in your system appear to be correct, but you need others besides.'; $string['ATSysEquiv_SA_system_underdetermined'] = 'The equations in your system appear to be correct, but you need others besides.';
$string['ATSysEquiv_SA_system_overdetermined'] = 'The entries in red below are those that are incorrect. {$a[0]} '; $string['ATSysEquiv_SA_system_overdetermined'] = 'The entries in red below are those that are incorrect. {$a[0]} ';
// Answer testsuite front end strings
$string['stackInstall_testsuite_title'] = 'A test suite for STACK Answer tests';
$string['stackInstall_testsuite_intro'] = 'This page allows you to test that the STACK answer tests are functioning correctly. Note that only answer tests can be checked through the web interface. Other Maxima commands need to be checked from the command line: see unittests.mac.';
$string['stackInstall_testsuite_choose'] = 'Please choose an answer test.';
$string['stackInstall_testsuite_pass'] = 'All tests passed!';
$string['stackInstall_testsuite_fail'] = 'Not all tests passed!';
$string['stackInstall_testsuite_for'] = 'Test suite for {$a[0]}';
...@@ -61,3 +61,8 @@ $settings->add(new admin_setting_heading('chat', ...@@ -61,3 +61,8 @@ $settings->add(new admin_setting_heading('chat',
get_string('chattitle', 'qtype_stack'), get_string('chattitle', 'qtype_stack'),
get_string('chat_desc', 'qtype_stack', get_string('chat_desc', 'qtype_stack',
array('link' => (string) new moodle_url('/question/type/stack/caschat.php'))))); array('link' => (string) new moodle_url('/question/type/stack/caschat.php')))));
$settings->add(new admin_setting_heading('answertests',
get_string('stackInstall_testsuite_title', 'qtype_stack'),
get_string('stackInstall_testsuite_title_desc', 'qtype_stack',
array('link' => (string) new moodle_url('/question/type/stack/answertests.php')))));
This diff is collapsed.
This diff is collapsed.
.path-question-type-stack dt { body.path-question-type-stack dt {
font-weight: bold; font-weight: bold;
} }
.path-question-type-stack dd { body.path-question-type-stack dd {
margin-left: 2em; margin-left: 2em;
} }
#page-question-type-stack-healthcheck textarea { body#page-question-type-stack-healthcheck textarea {
font-family: monospace; font-family: monospace;
font-size: 0.8em; font-size: 0.8em;
width: 100%; width: 100%;
height: 32em; height: 32em;
white-space: pre; white-space: pre;
} }
body.path-question-type-stack table.stacktestsuite .pass td {
background-color: #dfd;
}
body.path-question-type-stack table.stacktestsuite .fail td {
background-color: #fdd;
}
body.path-question-type-stack h2.fail {
color: #f00;
}
body.path-question-type-stack h2.pass {
color: #080;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment