public function testSimpleCaseWithMapResponseValidation() { $interaction = InlineChoiceInteractionBuilder::buildSimple('testIdentifier', ['sydney' => 'Sydney', 'melbourne' => 'Melbourne', 'canberra' => 'Canberra']); $responseDeclaration = ResponseDeclarationBuilder::buildWithMapping('testIdentifier', ['sydney' => ['0.5', false], 'melbourne' => ['1', true]]); $mapper = new InlineChoiceInteractionMapper($interaction, $responseDeclaration, ResponseProcessingTemplate::mapResponse()); $question = $mapper->getQuestionType(); $this->assertNotNull($question); $this->assertEquals('clozedropdown', $question->get_type()); // Should populate possible responses $this->assertCount(1, $question->get_possible_responses()); $this->assertCount(3, $question->get_possible_responses()[0]); $this->assertContains('Sydney', $question->get_possible_responses()[0]); $this->assertContains('Melbourne', $question->get_possible_responses()[0]); $this->assertContains('Canberra', $question->get_possible_responses()[0]); // Should have validation object $validation = $question->get_validation(); $this->assertNotNull($validation); $this->assertInstanceOf('LearnosityQti\\Entities\\QuestionTypes\\clozedropdown_validation', $validation); $this->assertEquals('exactMatch', $validation->get_scoring_type()); // Should set both `valid_response` and `alt_responses` for multiple correct values // Also, the highest value should be put as `valid_response` $validResponse = $validation->get_valid_response(); $this->assertNotNull($validResponse); $this->assertEquals(1, $validResponse->get_score()); $this->assertEquals(["Melbourne"], $validResponse->get_value()); $altResponses = $validation->get_alt_responses(); $this->assertNotNull($altResponses); $this->assertCount(1, $altResponses); $this->assertEquals(0.5, $altResponses[0]->get_score()); $this->assertEquals(["Sydney"], $altResponses[0]->get_value()); }
public function testShouldHandleMapResponseValidationWithMultipleResponses() { $testMatchInteraction = MatchInteractionBuilder::buildMatchInteraction('testMatchInteraction', [['A' => 'Item A', 'B' => 'Item B'], ['C' => 'Item C', 'D' => 'Item D', 'E' => 'Item E']], true); $testMatchInteraction->setMaxAssociations(3); $responseProcessingTemplate = ResponseProcessingTemplate::mapResponse(); $validResponseIdentifier = ['A D' => [1, false], 'B C' => [2, false], 'A E' => [3, false]]; $responseDeclaration = ResponseDeclarationBuilder::buildWithMapping('testIdentifier', $validResponseIdentifier, 'QtiDirectedPair'); $mapper = new MatchInteractionMapper($testMatchInteraction, $responseDeclaration, $responseProcessingTemplate); /** @var choicematrix $choicematrix */ $choicematrix = $mapper->getQuestionType(); $this->assertTrue($choicematrix instanceof choicematrix); $this->assertEquals('choicematrix', $choicematrix->get_type()); $this->assertCount(3, $choicematrix->get_options()); $this->assertContains('Item C', $choicematrix->get_options()); $this->assertContains('Item D', $choicematrix->get_options()); $this->assertContains('Item E', $choicematrix->get_options()); $this->assertCount(2, $choicematrix->get_stems()); $this->assertContains('Item A', $choicematrix->get_stems()); $this->assertContains('Item B', $choicematrix->get_stems()); $validation = $choicematrix->get_validation(); $this->assertTrue($validation instanceof choicematrix_validation); $this->assertEquals('exactMatch', $validation->get_scoring_type()); $validResponse = $validation->get_valid_response(); $this->assertTrue($validResponse instanceof choicematrix_validation_valid_response); $this->assertEquals(6, $validResponse->get_score()); $this->assertEquals([[1, 2], [0]], $validResponse->get_value()); $this->assertTrue($choicematrix->get_multiple_responses()); }
public function testMapResponseValidation() { $bgObject = new Object('http://img.png', 'image/png'); $bgObject->setWidth(100); $bgObject->setHeight(200); $testInteraction = GraphicGapInteractionBuilder::build('testInteraction', $bgObject, ['A' => 'img_A.png', 'B' => 'img_B.png', 'C' => 'img_C.png'], ['G1' => [0, 0, 10, 10], 'G2' => [30, 40, 50, 60]]); $responseProcessingTemplate = ResponseProcessingTemplate::mapResponse(); $validResponseIdentifier = ['A G1' => [1, false], 'B G1' => [2, false], 'C G2' => [3, false]]; $responseDeclaration = ResponseDeclarationBuilder::buildWithMapping('testIdentifier', $validResponseIdentifier, 'QtiDirectedPair'); $mapper = new GraphicGapMatchInteractionMapper($testInteraction, $responseDeclaration, $responseProcessingTemplate); /** @var imageclozeassociation $q */ $q = $mapper->getQuestionType(); $this->assertEquals('imageclozeassociation', $q->get_type()); $this->assertEquals(['<img src="img_A.png"/>', '<img src="img_B.png"/>', '<img src="img_C.png"/>'], $q->get_possible_responses()); $this->assertFalse($q->get_duplicate_responses()); $this->assertEquals([['x' => 0, 'y' => 0], ['x' => 30, 'y' => 20]], $q->get_response_positions()); $img = $q->get_image(); $this->assertInstanceOf('LearnosityQti\\Entities\\QuestionTypes\\imageclozeassociation_image', $img); $this->assertEquals('http://img.png', $img->get_src()); /** @var imageclozeassociation_validation $validation */ $validation = $q->get_validation(); $this->assertInstanceOf('LearnosityQti\\Entities\\QuestionTypes\\imageclozeassociation_validation', $validation); $this->assertEquals('exactMatch', $validation->get_scoring_type()); /** @var imageclozeassociation_validation_valid_response $validResponse */ $validResponse = $validation->get_valid_response(); $this->assertInstanceOf('LearnosityQti\\Entities\\QuestionTypes\\imageclozeassociation_validation_valid_response', $validResponse); $this->assertEquals(5, $validResponse->get_score()); $this->assertEquals(['<img src="img_B.png"/>', '<img src="img_C.png"/>'], $validResponse->get_value()); $altResponses = $validation->get_alt_responses(); $this->assertCount(1, $altResponses); $this->assertEquals(4, $altResponses[0]->get_score()); $this->assertEquals(['<img src="img_A.png"/>', '<img src="img_C.png"/>'], $altResponses[0]->get_value()); }
public function testShouldNotHandleMapResponseValidation() { $testOrderInteraction = OrderInteractionBuilder::buildOrderInteraction('testOrderInteraction', ['A' => 'Order A', 'B' => 'Order B', 'C' => 'Order C'], 'testPrompt'); $responseProcessingTemplate = ResponseProcessingTemplate::mapResponse(); $validResponseIdentifier = ['A' => [1, false], 'B' => [2, false], 'C' => [3, false]]; $responseDeclaration = ResponseDeclarationBuilder::buildWithMapping('testIdentifier', $validResponseIdentifier); $mapper = new OrderInteractionMapper($testOrderInteraction, $responseDeclaration, $responseProcessingTemplate); $mapper->getQuestionType(); $this->assertCount(1, LogService::read()); }
public function testWithMapResponseValidation() { $interaction = $this->buildHottextInteraction('identifierOne'); $interaction->setMaxChoices(2); $responseDeclaration = ResponseDeclarationBuilder::buildWithMapping('identifierOne', ['A' => [4], 'C' => [1]]); $mapper = new HottextInteractionMapper($interaction, $responseDeclaration, ResponseProcessingTemplate::mapResponse()); $question = $mapper->getQuestionType(); $this->assertNotNull($question); $this->assertEquals('tokenhighlight', $question->get_type()); $validation = $question->get_validation(); $this->assertNotNull($validation); $this->assertEquals(5, $validation->get_valid_response()->get_score()); $this->assertEquals([2, 0], $validation->get_valid_response()->get_value()); $altResponses = $validation->get_alt_responses(); $this->assertNotNull($altResponses); $this->assertCount(2, $altResponses); $this->assertEquals([0], $altResponses[0]->get_value()); $this->assertEquals(4, $altResponses[0]->get_score()); $this->assertEquals([2], $altResponses[1]->get_value()); $this->assertEquals(1, $altResponses[1]->get_score()); }
public function testSimpleCaseWithMapResponseValidation() { $interaction = new \qtism\data\content\interactions\TextEntryInteraction('testIdentifier'); $responseDeclaration = ResponseDeclarationBuilder::buildWithMapping('testIdentifier', ['york' => [0.5, false], 'Sydney' => [1, false], 'York' => [2, false], 'Junior' => [1.5, true]]); $mapper = new TextEntryInteractionMapper($interaction, $responseDeclaration, ResponseProcessingTemplate::mapResponse()); $question = $mapper->getQuestionType(); $this->assertNotNull($question); $this->assertEquals($question->get_template(), '{{response}}'); $validation = $question->get_validation(); $this->assertNotNull($validation); // First correct mapping value should be mapped to `valid_response` $validResponse = $validation->get_valid_response(); $this->assertNotNull($validResponse); $this->assertEquals(2, $validResponse->get_score()); $this->assertContains('York', $validResponse->get_value()); // Other correct mapping values should be mapped to `alt_response` $altResponses = $validation->get_alt_responses(); $this->assertNotNull($altResponses); $this->assertCount(3, $altResponses); foreach ($altResponses as $altResponse) { switch ($altResponse->get_value()) { case 'york': $this->assertEquals(0.5, $altResponse->get_score()); break; case 'Sydney': $this->assertEquals(1, $altResponse->get_score()); break; case 'Junior': $this->assertEquals(1.5, $altResponse->get_score()); break; } } // Since one of them has is set to be case sensitive, so everything shall be case sensitive // TODO: Ensure a warning is thrown explaining that as well $this->assertTrue($question->get_case_sensitive()); }
public function testTwoInteractionsWithMapResponseValidation() { $itemBody = $this->buildItemBodyWithTwoInteraction(); $responseDeclarations = new QtiComponentCollection(); $responseDeclarations->attach(ResponseDeclarationBuilder::buildWithMapping('testIdentifierOne', ['Sydney' => [2, false], 'sydney' => [1, false]])); $responseDeclarations->attach(ResponseDeclarationBuilder::buildWithMapping('testIdentifierTwo', ['Keanu Reeves' => [1, true], 'Gloria Foster' => [0.5, false]])); $mapper = new MergedTextEntryInteractionMapper('dummyReference', $itemBody, $responseDeclarations, ResponseProcessingTemplate::mapResponse()); $question = $mapper->getQuestionType(); $this->assertNotNull($question); $this->assertEquals('clozetext', $question->get_type()); $validation = $question->get_validation(); $this->assertNotNull($validation); // First correct mapping value should be mapped to `valid_response` $validResponse = $validation->get_valid_response(); $this->assertNotNull($validResponse); $this->assertEquals(3, $validResponse->get_score()); // The score would be the total `mappedValue` of the combination with highest score $this->assertContains('Sydney', $validResponse->get_value()); $this->assertContains('Keanu Reeves', $validResponse->get_value()); // Other correct mapping values should be mapped to `alt_response` $altResponses = $validation->get_alt_responses(); $this->assertNotNull($altResponses); $this->assertCount(3, $altResponses); $this->assertEquals(2.5, $altResponses[0]->get_score()); $this->assertContains('Sydney', $altResponses[0]->get_value()); $this->assertContains('Gloria Foster', $altResponses[0]->get_value()); $this->assertEquals(2, $altResponses[1]->get_score()); $this->assertContains('sydney', $altResponses[1]->get_value()); $this->assertContains('Keanu Reeves', $altResponses[1]->get_value()); $this->assertEquals(1.5, $altResponses[2]->get_score()); $this->assertContains('sydney', $altResponses[2]->get_value()); $this->assertContains('Gloria Foster', $altResponses[2]->get_value()); // If one of the mapping has case sensitivity as true, then everything become case sensitive $this->assertTrue($question->get_case_sensitive()); }
public function testSingleInteractionWithMapResponseValidation() { $itemBody = $this->buildItemBodyWithSingleInteraction(); $responseDeclarations = new QtiComponentCollection(); $responseDeclarations->attach(ResponseDeclarationBuilder::buildWithMapping('testIdentifierOne', ['canberra' => [0.5, false], 'sydney' => [2, false]])); $mapper = new MergedInlineChoiceInteractionMapper('dummyQuestionReference', $itemBody, $responseDeclarations, ResponseProcessingTemplate::mapResponse()); $question = $mapper->getQuestionType(); // Should map question correctly with `validation` object of `exactMatch` scoring type $this->assertNotNull($question); $this->assertEquals('<p>The Matrix movie is filmed at {{response}}. Boo!</p>', $question->get_template()); $this->assertEquals('clozedropdown', $question->get_type()); // Should set both `valid_response` and `alt_responses` for multiple correct values $validation = $question->get_validation(); $this->assertNotNull($validation); $this->assertEquals('exactMatch', $validation->get_scoring_type()); $validResponse = $validation->get_valid_response(); $this->assertNotNull($validResponse); $this->assertEquals(2, $validResponse->get_score()); $this->assertEquals(["Sydney"], $validResponse->get_value()); $altResponses = $validation->get_alt_responses(); $this->assertNotNull($altResponses); $this->assertCount(1, $altResponses); $this->assertEquals(0.5, $altResponses[0]->get_score()); $this->assertEquals(["Canberra"], $altResponses[0]->get_value()); }
public function testMapResponseWithSwappedValuePair() { $testInteraction = GapMatchInteractionBuilder::buildGapMatchInteraction('testGapMatchInteraction', ['A' => 'Gap A', 'B' => 'Gap B'], ['C' => 'http://img_C', 'D' => 'http://img_D'], ['G1', 'G2']); $responseProcessingTemplate = ResponseProcessingTemplate::mapResponse(); $validResponseIdentifier = ['G1 A' => [1, false], 'G1 B' => [2, false], 'G2 C' => [3, false], 'G2 B' => [4, false], 'D G1' => [5, false]]; $responseDeclaration = ResponseDeclarationBuilder::buildWithMapping('testIdentifier', $validResponseIdentifier, 'QtiDirectedPair'); $mapper = new GapMatchInteractionMapper($testInteraction, $responseDeclaration, $responseProcessingTemplate); /** @var clozeassociation $q */ $q = $mapper->getQuestionType(); $validation = $q->get_validation(); $this->assertInstanceOf('LearnosityQti\\Entities\\QuestionTypes\\clozeassociation_validation', $validation); $this->assertEquals('exactMatch', $validation->get_scoring_type()); $validResponse = $validation->get_valid_response(); $this->assertInstanceOf('LearnosityQti\\Entities\\QuestionTypes\\clozeassociation_validation_valid_response', $validResponse); $this->assertEquals(9, $validResponse->get_score()); $this->assertEquals(['<img src="http://img_D"/>', 'Gap B'], $validResponse->get_value()); $altResponses = $validation->get_alt_responses(); $this->assertCount(5, $altResponses); $this->assertEquals(8, $altResponses[0]->get_score()); $this->assertEquals(['<img src="http://img_D"/>', '<img src="http://img_C"/>'], $altResponses[0]->get_value()); $this->assertEquals(6, $altResponses[1]->get_score()); $this->assertEquals(['Gap B', 'Gap B'], $altResponses[1]->get_value()); $this->assertEquals(5, $altResponses[2]->get_score()); $this->assertEquals(['Gap A', 'Gap B'], $altResponses[2]->get_value()); $this->assertEquals(5, $altResponses[3]->get_score()); $this->assertEquals(['Gap B', '<img src="http://img_C"/>'], $altResponses[3]->get_value()); $this->assertEquals(4, $altResponses[4]->get_score()); $this->assertEquals(['Gap A', '<img src="http://img_C"/>'], $altResponses[4]->get_value()); }
public function testShouldHandleMultipleCardinalityWithMapResponse() { $responseDeclaration = ResponseDeclarationBuilder::buildWithMapping('testIdentifier', ['one' => [1, false], 'two' => [3, false]]); $responseDeclaration->setCardinality(Cardinality::MULTIPLE); $responseProcessingTemplate = ResponseProcessingTemplate::mapResponse(); $optionsMap = ['one' => 'Label One', 'two' => 'Label Two', 'three' => 'Label Three']; $interaction = ChoiceInteractionBuilder::buildSimple('testIdentifier', $optionsMap); $interaction->setMaxChoices(0); $interactionMapper = new ChoiceInteractionMapper($interaction, $responseDeclaration, $responseProcessingTemplate); $mcq = $interactionMapper->getQuestionType(); $this->assertEquals('mcq', $mcq->get_type()); $validation = $mcq->get_validation(); $this->assertNotNull($validation); $this->assertEquals(['two', 'one'], $validation->get_valid_response()->get_value()); $this->assertEquals(4, $validation->get_valid_response()->get_score()); $this->assertEquals(['two'], $validation->get_alt_responses()[0]->get_value()); $this->assertEquals(3, $validation->get_alt_responses()[0]->get_score()); $this->assertEquals(['one'], $validation->get_alt_responses()[1]->get_value()); $this->assertEquals(1, $validation->get_alt_responses()[1]->get_score()); // Verify options are sort of correct $this->assertEquals(count($optionsMap), count($mcq->get_options())); foreach ($mcq->get_options() as $option) { $this->assertArrayHasKey($option['value'], $optionsMap); $this->assertEquals($option['label'], $optionsMap[$option['value']]); } }