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

Imported first answer test, with its unit test.

parent 28c30808
No related branches found
No related tags found
No related merge requests found
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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.
//
// Moodle 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Answer test base class.
*
* @copyright 2012 University of Birmingham
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class STACK_AnsTest {
// Attributes
/**
* @var string
*/
protected $sAnsKey;
/**
* @var string
*/
protected $tAnsKey;
/**
* @var array
*/
protected $preCalculated;
/**
* @var int
*/
protected $seed;
/**
* @var CasString
*/
protected $ATOption = NULL;
/**
* @var string
*/
protected $casFunction = NULL;
/**
* @var bool
*/
protected $ATResult = NULL;
/**
* @var float
*/
protected $ATMark;
/**
* @var string
*/
protected $ATError;
/**
* @var bool
*/
protected $ATValid;
/**
* @var string
*/
protected $ATAnsNote;
/**
* @var string
*/
protected $ATFeedback;
/**
* Should the test ops be processed in the CAS. By default no.
*
* @var bool
* @access protected
*/
protected $CASProcessTestOps = false;
// Operations
/**
* Constructor
*
* @param string $sAnsKey
* @param string $tAnsKey
* @param array $preCalculated
* @param int $seed
* @param CasString $casOption
*/
public function __construct($sAnsKey, $tAnsKey, $STACK_CAS_Maxima_Preferences, $casOption = NULL) {
$this->sAnsKey = $sAnsKey;
$this->tAnsKey = $tAnsKey;
$this->ATOption = $casOption;
$this->STACK_CAS_Maxima_Preferences = $STACK_CAS_Maxima_Preferences;
$this->CASProcessTestOps = false;
}
/**
* Acutally perform the test.
*
* @return bool
*/
public function doAnsTest() {
return NULL;
}
/**
*
*
* @return string
*/
public function getATErrors() {
return $this->ATError;
}
/**
*
*
* @return float
*/
public function getATMark() {
return $this->ATMark;
}
/**
*
*
* @return bool
*/
public function getATValid() {
return $this->ATValid;
}
/**
*
*
* @return string
*/
public function getATAnsNote() {
return $this->ATAnsNote;
}
/**
*
*
* @return string
*/
public function getATFeedback() {
//AT feedback needs to be run through the translator
if (!empty($this->ATFeedback)) {
$translated = STACK_Translator::translate("$this->ATFeedback");
} else {
$translated = '';
}
return $translated;
}
/**
* Returns whether the testops should be processed by the CAS for this AnswerTest
* Returns true if the Testops should be processed.
*
* @return bool
*/
public function processTestOps() {
return $this->CASProcessTestOps;
}
}
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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.
//
// Moodle 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* String answer test
*
* @copyright 2012 University of Birmingham
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class STACK_AnsTest_ATString extends STACK_AnsTest {
public function doAnsTest() {
if (trim($this->sAnsKey) == trim($this->tAnsKey)) {
$this->ATMark = 1;
return true;
} else {
$this->ATMark = 0;
return false;
}
}
}
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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.
//
// Moodle 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Unit tests for STACK_AnsTest_ATString.
*
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(__FILE__) . '/../../anstest.class.php');
require_once(dirname(__FILE__) . '/../atstring.class.php');
/**
* Unit tests for STACK_AnsTest_ATString.
*
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class STACK_AnsTest_ATString_test extends UnitTestCase {
public function test_is_true_for_equal_strings() {
$at = new STACK_AnsTest_ATString('string1', 'string1', array());
$this->assertTrue($at->doAnsTest());
$this->assertEqual(1, $at->getATMark());
}
public function test_is_false_for_unequal_strings() {
$at = new STACK_AnsTest_ATString('string1', 'string2', array());
$this->assertFalse($at->doAnsTest());
$this->assertEqual(0, $at->getATMark());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment