Skip to content

Commit 6cd3abe

Browse files
committed
api-nrw - Add unit tests. Fix response summary on existing tests.
1 parent c5e156d commit 6cd3abe

2 files changed

Lines changed: 516 additions & 5 deletions

File tree

tests/api_controller_test.php

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,70 @@ public function test_grade(): void {
246246
$this->assertEquals('<p>[[feedback:prt1]]</p>', $this->output->specificfeedback);
247247
$this->assertStringContainsString('correct', $this->output->prts->prt1);
248248
$this->assertEquals(0, count((array)$this->output->gradingassets));
249-
$this->assertEquals('Seed: 86; ans1: matrix([35,30],[28,24]) [valid]; prt1: !', $this->output->responsesummary);
249+
$this->assertEquals('Seed: 86; ans1: matrix([35,30],[28,24]) [score]; prt1: # = 1 | | 1-0-T', $this->output->responsesummary);
250+
$this->assertEquals(0, count($this->output->iframes));
251+
}
252+
253+
public function test_grade_multipleprts(): void {
254+
$this->requestdata['questionDefinition'] = stack_api_test_data::get_question_string('multipleprts');
255+
$this->requestdata['answers'] = (array) json_decode(stack_api_test_data::get_answer_string('multipleprts_correct'));
256+
$gc = new GradingController();
257+
$gc->__invoke($this->request, $this->response, []);
258+
$this->assertEquals(true, $this->output->isgradable);
259+
$this->assertEquals(1, $this->output->score);
260+
$this->assertEquals(1, $this->output->scores->even);
261+
$this->assertEquals(1, $this->output->scores->odd);
262+
$this->assertEquals(1, $this->output->scores->oddeven);
263+
$this->assertEquals(1, $this->output->scores->poly);
264+
$this->assertEquals(1, $this->output->scores->unique);
265+
$this->assertEquals(1, $this->output->scores->total);
266+
$this->assertEqualsWithDelta(0.2, $this->output->scoreweights->even, 0.0001);
267+
$this->assertEqualsWithDelta(0.2, $this->output->scoreweights->odd, 0.0001);
268+
$this->assertEqualsWithDelta(0.4, $this->output->scoreweights->oddeven, 0.0001);
269+
$this->assertEquals(null, $this->output->scoreweights->poly ?? null);
270+
$this->assertEqualsWithDelta(0.2, $this->output->scoreweights->unique, 0.0001);
271+
$this->assertEquals(5, $this->output->scoreweights->total);
272+
$this->assertEquals('', $this->output->specificfeedback);
273+
$this->assertEquals(
274+
'<p>Perhaps you could think of some non-polynomial examples as well?</p>',
275+
$this->output->prts->poly
276+
);
277+
$this->assertEquals(0, count((array)$this->output->gradingassets));
278+
$this->assertEquals(
279+
'Seed: -1; ans1: x^3 [score]; ans2: x^2 [score]; ans3: 0 [score]; ans4: true [score]; ' .
280+
'even: # = 1 | even-0-T; odd: # = 1 | odd-0-T; oddeven: # = 1 | ODD | EVEN; ' .
281+
'poly: # = 1 [formative] | ATLogic_True. | poly-1-T; unique: # = 1 | ATLogic_True. | unique-0-T',
282+
$this->output->responsesummary
283+
);
284+
$this->assertEquals(0, count($this->output->iframes));
285+
}
286+
287+
public function test_grade_some_answers_multipleprt(): void {
288+
$this->requestdata['questionDefinition'] = stack_api_test_data::get_question_string('multipleprts');
289+
// Including unsupplied and invalid answers.
290+
$this->requestdata['answers'] = (array) json_decode(stack_api_test_data::get_answer_string('multipleprts_some'));
291+
$gc = new GradingController();
292+
$gc->__invoke($this->request, $this->response, []);
293+
$this->assertEquals(true, $this->output->isgradable);
294+
$this->assertEqualsWithDelta(0.4, $this->output->score, 0.0001);
295+
$this->assertEquals(null, $this->output->scores->even);
296+
$this->assertEquals(1, $this->output->scores->odd);
297+
$this->assertEquals(null, $this->output->scores->oddeven);
298+
$this->assertEquals(null, $this->output->scores->poly);
299+
$this->assertEquals(1, $this->output->scores->unique);
300+
$this->assertEqualsWithDelta(0.4, $this->output->scores->total, 0.0001);
301+
$this->assertEquals('', $this->output->specificfeedback);
302+
$this->assertStringContainsString('Correct answer', $this->output->prts->odd);
303+
$this->assertStringContainsString('Correct answer', $this->output->prts->unique);
304+
$this->assertEquals(null, $this->output->prts->even ?? null);
305+
$this->assertEquals(null, $this->output->prts->poly ?? null);
306+
$this->assertEquals(null, $this->output->prts->oddeven ?? null);
307+
$this->assertEquals(0, count((array)$this->output->gradingassets));
308+
$this->assertEquals(
309+
'Seed: -1; ans1: x^3 [score]; ans2: * [invalid]; ans4: true [score]; even: !; ' .
310+
'odd: # = 1 | odd-0-T; oddeven: !; poly: !; unique: # = 1 | ATLogic_True. | unique-0-T',
311+
$this->output->responsesummary
312+
);
250313
$this->assertEquals(0, count($this->output->iframes));
251314
}
252315

@@ -272,6 +335,10 @@ public function test_default(): void {
272335
$this->assertEquals(1, $this->output->scoreweights->total);
273336
$this->assertEquals('<p>[[feedback:prt1]]</p>', $this->output->specificfeedback);
274337
$this->assertStringContainsString('correct', $this->output->prts->prt1);
338+
$this->assertEquals(
339+
'Seed: -1; ans1: 1 [score]; prt1: # = 1 | prt1-1-T',
340+
$this->output->responsesummary
341+
);
275342
}
276343

277344
public function test_grade_scores(): void {
@@ -293,7 +360,12 @@ public function test_grade_scores(): void {
293360
$this->assertEqualsWithDelta(0.1, $this->output->scoreweights->prt3, 0.0001);
294361
$this->assertEqualsWithDelta(0.1, $this->output->scoreweights->prt4, 0.0001);
295362
$this->assertEquals(10, $this->output->scoreweights->total);
296-
}
363+
$this->assertEquals(
364+
'Seed: -1; ans1: c [score]; ans2: 1 [score]; ans3: 0 [score]; ans4: 0 [score]; prt1: # = 1 | prt1-1-T; ' .
365+
'prt2: # = 1 | prt2-1-T; prt3: # = 0 | prt3-1-F; prt4: # = 1 | prt4-1-T',
366+
$this->output->responsesummary
367+
);
368+
}
297369

298370
public function test_download(): void {
299371

0 commit comments

Comments
 (0)