Skip to content

Commit 9f0d46b

Browse files
committed
Unit test for test_build_full_ai_prompt
1 parent 8b7123c commit 9f0d46b

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

tests/question_test.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,14 @@ final class question_test extends \advanced_testcase {
4444
* Instance of the question type class
4545
* @var qtype_aitext
4646
*/
47-
public qtype_aitext $question;
48-
47+
public $qtype_aitext;
4948
/**
5049
* There is a live connection to the External AI system
5150
* When run locally it will make a connection. Otherwise the
5251
* tests will be skipped
5352
* @var bool
5453
*/
55-
protected bool $islive = false;
54+
protected int $islive;
5655

5756
/**
5857
* Config.php should include the apikey and orgid in the form
@@ -62,7 +61,7 @@ final class question_test extends \advanced_testcase {
6261
* @return void
6362
*/
6463
protected function setUp(): void {
65-
$this->question = new \qtype_aitext();
64+
$this->qtype_aitext = new \qtype_aitext();
6665
if (defined('TEST_LLM_APIKEY') && defined('TEST_LLM_ORGID')) {
6766
set_config('apikey', TEST_LLM_APIKEY, 'aiprovider_openai');
6867
set_config('orgid', TEST_LLM_ORGID, 'aiprovider_openai');
@@ -87,7 +86,23 @@ public function test_perform_request(): void {
8786
$response = $aitext->perform_request('What is 2 * 4 only return a single number');
8887
$this->assertEquals('8', $response);
8988
}
89+
/**
90+
* Chek the student response gets interprolated into the prompt ready to send
91+
* off to the LLM
92+
*/
9093

94+
public function test_build_full_ai_prompt() {
95+
$this->resetAfterTest(true);
96+
$question = qtype_aitext_test_helper::make_aitext_question([]);
97+
$question->questiontext = 'What is 2 * 4?';
98+
$aiprompt = "Is the a correct response to the question 'What is 2 * 4?";
99+
$defaultmark = 1;
100+
$markscheme = 'Give one mark if the response is 8';
101+
$studentresponse = 'It is 8';
102+
$result = (string) $question->build_full_ai_prompt($studentresponse, $aiprompt, $defaultmark, $markscheme);
103+
$pattern = '/\[\[' . $studentresponse . '\]\]/';
104+
$this->assertEquals(1,preg_match($pattern, $result));
105+
}
91106

92107
/**
93108
* Tests the call to the quesitonbase summary code

0 commit comments

Comments
 (0)