Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
moodle-qtype_stack
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elc
moodle-qtype_stack
Commits
386a651d
Commit
386a651d
authored
5 years ago
by
Chris Sangwin
Browse files
Options
Downloads
Patches
Plain Diff
Create a fresh question each time a test is done. Issue #552.
parent
a8ad6272
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
questiontestrun.php
+4
-13
4 additions, 13 deletions
questiontestrun.php
stack/bulktester.class.php
+9
-8
9 additions, 8 deletions
stack/bulktester.class.php
stack/questiontest.php
+11
-3
11 additions, 3 deletions
stack/questiontest.php
with
24 additions
and
24 deletions
questiontestrun.php
+
4
−
13
View file @
386a651d
...
...
@@ -181,16 +181,16 @@ if (empty($question->deployedseeds)) {
new
pix_icon
(
't/delete'
,
stack_string
(
'undeploy'
)));
}
$qn
=
question_bank
::
load_question
(
$questionid
);
$bulktestresults
=
array
(
false
,
''
);
if
(
optional_param
(
'testall'
,
null
,
PARAM_INT
))
{
// Bulk test all variants.
$bulktester
=
new
stack_bulk_tester
();
$bulktestresults
=
$bulktester
->
qtype_stack_test_question
(
$qn
,
$testscases
,
'web'
,
$deployedseed
,
true
);
$bulktestresults
=
$bulktester
->
qtype_stack_test_question
(
$context
,
$questionid
,
$testscases
,
'web'
,
$deployedseed
,
true
);
}
// Print out question notes of all deployed variants.
$qn
=
question_bank
::
load_question
(
$questionid
);
$qn
->
seed
=
(
int
)
$deployedseed
;
$cn
=
$qn
->
get_context
();
$qunote
=
question_engine
::
make_questions_usage_by_activity
(
'qtype_stack'
,
$cn
);
...
...
@@ -297,16 +297,7 @@ echo $OUTPUT->heading(stack_string('questiontestsfor', $seed), 2);
$testresults
=
array
();
$allpassed
=
true
;
foreach
(
$testscases
as
$key
=>
$testcase
)
{
// Create a completely clean version of the question usage we will use.
// Evaluated state is stored in question variables etc.
$question
=
question_bank
::
load_question
(
$questionid
);
$question
->
seed
=
$seed
;
$quba
=
question_engine
::
make_questions_usage_by_activity
(
'qtype_stack'
,
$context
);
$quba
->
set_preferred_behaviour
(
'adaptive'
);
$slot
=
$quba
->
add_question
(
$question
,
$question
->
defaultmark
);
$quba
->
start_question
(
$slot
);
$testresults
[
$key
]
=
$testcase
->
test_question
(
$quba
,
$question
,
$seed
);
$testresults
[
$key
]
=
$testcase
->
test_question
(
$questionid
,
$seed
,
$context
);
if
(
!
$testresults
[
$key
]
->
passed
())
{
$allpassed
=
false
;
}
...
...
This diff is collapsed.
Click to expand it.
stack/bulktester.class.php
+
9
−
8
View file @
386a651d
...
...
@@ -180,7 +180,7 @@ class stack_bulk_tester {
}
// Make sure the bulk tester is able to continue.
try
{
list
(
$ok
,
$message
)
=
$this
->
qtype_stack_test_question
(
$question
,
$tests
,
$outputmode
);
list
(
$ok
,
$message
)
=
$this
->
qtype_stack_test_question
(
$context
,
$question
id
,
$tests
,
$outputmode
);
}
catch
(
stack_exception
$e
)
{
$ok
=
false
;
$message
=
stack_string
(
'errors'
)
.
' : '
.
$e
;
...
...
@@ -214,7 +214,8 @@ class stack_bulk_tester {
}
// Make sure the bulk tester is able to continue.
try
{
list
(
$ok
,
$message
)
=
$this
->
qtype_stack_test_question
(
$question
,
$tests
,
$outputmode
,
$seed
);
list
(
$ok
,
$message
)
=
$this
->
qtype_stack_test_question
(
$context
,
$questionid
,
$tests
,
$outputmode
,
$seed
);
}
catch
(
stack_exception
$e
)
{
$ok
=
false
;
$message
=
stack_string
(
'errors'
)
.
' : '
.
$e
;
...
...
@@ -246,17 +247,17 @@ class stack_bulk_tester {
* bool true if the tests passed, else false.
* sring message summarising the number of passes and fails.
*/
public
function
qtype_stack_test_question
(
$
question
,
$tests
,
$outputmode
,
$seed
=
null
,
$quiet
=
false
)
{
public
function
qtype_stack_test_question
(
$
context
,
$qid
,
$tests
,
$outputmode
,
$seed
=
null
,
$quiet
=
false
)
{
flush
();
// Force output to prevent timeouts and to make progress clear.
core_php_time_limit
::
raise
(
60
);
// Prevent PHP timeouts.
gc_collect_cycles
();
// Because PHP's default memory management is rubbish.
// Prepare the question and a usage.
$question
=
clone
(
$question
);
$question
=
question_bank
::
load_question
(
$qid
);
if
(
!
is_null
(
$seed
))
{
$question
->
seed
=
(
int
)
$seed
;
}
$quba
=
question_engine
::
make_questions_usage_by_activity
(
'qtype_stack'
,
context_system
::
instance
());
$quba
=
question_engine
::
make_questions_usage_by_activity
(
'qtype_stack'
,
$context
);
$quba
->
set_preferred_behaviour
(
'adaptive'
);
// Execute the tests.
...
...
@@ -264,7 +265,7 @@ class stack_bulk_tester {
$fails
=
0
;
foreach
(
$tests
as
$key
=>
$testcase
)
{
$testresults
[
$key
]
=
$testcase
->
test_question
(
$q
uba
,
$question
,
$seed
);
$testresults
[
$key
]
=
$testcase
->
test_question
(
$q
id
,
$seed
,
$context
);
if
(
$testresults
[
$key
]
->
passed
())
{
$passes
+=
1
;
}
else
{
...
...
@@ -306,7 +307,7 @@ class stack_bulk_tester {
}
/**
* Instantia
l
the question to seed the cache.
* Instantia
te
the question to seed the cache.
*
* @param qtype_stack_question $question the question to test.
* @param int|null $seed if we want to force a particular version.
...
...
This diff is collapsed.
Click to expand it.
stack/questiontest.php
+
11
−
3
View file @
386a651d
...
...
@@ -62,13 +62,21 @@ class stack_question_test {
/**
* Run this test against a particular question.
* @param question_usage_by_activity $quba the useage to use when running the test.
* @param qtype_stack_question $question the question to test.
* @param int $questionid The database id of the question to test.
* @param int $seed the random seed to use.
* @param context_course $context The course in which this question takes place.
* @return stack_question_test_result the test results.
*/
public
function
test_question
(
question
_usage_by_activity
$quba
,
qtype_stack_question
$question
,
$seed
)
{
public
function
test_question
(
$
question
id
,
$seed
,
$context
)
{
// Create a completely clean version of the question usage we will use.
// Evaluated state is stored in question variables etc.
$question
=
question_bank
::
load_question
(
$questionid
);
if
(
!
is_null
(
$seed
))
{
$question
->
seed
=
(
int
)
$seed
;
}
$quba
=
question_engine
::
make_questions_usage_by_activity
(
'qtype_stack'
,
$context
);
$quba
->
set_preferred_behaviour
(
'adaptive'
);
$slot
=
$quba
->
add_question
(
$question
,
$question
->
defaultmark
);
$quba
->
start_question
(
$slot
,
$seed
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment