public function testCartesianResponse() { $res = ArrayUtil::cartesianProductForResponses([[new ValidResponse(1, ['a', 'b']), new ValidResponse(2, ['c', 'd'])], [new ValidResponse(3, ['a', 'e'])]]); $this->assertCount(2, $res); $this->assertEquals(['a', 'b', 'a', 'e'], $res[0]->getValue()); $this->assertEquals(4, $res[0]->getScore()); $this->assertEquals(['c', 'd', 'a', 'e'], $res[1]->getValue()); $this->assertEquals(5, $res[1]->getScore()); }
protected function getMapResponseTemplateValidation() { $interactionResponses = []; /** @var ResponseDeclaration $responseDeclaration */ foreach ($this->responseDeclarations as $responseIdentifier => $responseDeclaration) { $responses = []; foreach ($responseDeclaration->getMapping()->getMapEntries()->getArrayCopy(true) as $mapEntry) { /** @var MapEntry $mapEntry */ $responses[] = new ValidResponse($mapEntry->getMappedValue(), [$this->possibleResponses[$responseIdentifier][$mapEntry->getMapKey()]]); // Find out if one of them is case sensitive if (!$mapEntry->isCaseSensitive()) { LogService::log('Could not support `caseSensitive` attribute for this interaction type. This question validation is always case sensitive'); } } $interactionResponses[] = $responses; } $responses = ArrayUtil::cartesianProductForResponses($interactionResponses); return ValidationBuilder::build('clozedropdown', 'exactMatch', $responses); }
protected function getMapResponseTemplateValidation() { $interactionResponses = []; /** @var ResponseDeclaration $responseDeclaration */ foreach ($this->responseDeclarations as $responseIdentifier => $responseDeclaration) { $responses = []; foreach ($responseDeclaration->getMapping()->getMapEntries()->getArrayCopy(true) as $mapEntry) { /** @var MapEntry $mapEntry */ $responses[] = new ValidResponse($mapEntry->getMappedValue(), [$mapEntry->getMapKey()]); // Find out if one of them is case sensitive if ($mapEntry->isCaseSensitive()) { $this->isCaseSensitive = true; } } $interactionResponses[] = $responses; } $responses = ArrayUtil::cartesianProductForResponses($interactionResponses); return ValidationBuilder::build('clozetext', 'exactMatch', $responses); }
protected function getMapResponseTemplateValidation() { $gapIdentifiersIndexMap = array_flip($this->gapIdentifiers); $responseIndexSet = []; $responses = []; foreach ($this->responseDeclaration->getMapping()->getMapEntries() as $mapEntry) { /** @var MapEntry $mapEntry */ /** @var QtiDirectedPair $mapKey */ $mapKey = $mapEntry->getMapKey(); // Map response value and index based from the `mapKey`, try to guess which one is which since they // apparently can swap :( if (isset($this->possibleResponses[$mapKey->getFirst()]) && isset($gapIdentifiersIndexMap[$mapKey->getSecond()])) { $responseValue = $this->possibleResponses[$mapKey->getFirst()]; $responseIndex = $gapIdentifiersIndexMap[$mapKey->getSecond()]; } else { if (isset($this->possibleResponses[$mapKey->getSecond()]) && isset($gapIdentifiersIndexMap[$mapKey->getFirst()])) { $responseValue = $this->possibleResponses[$mapKey->getSecond()]; $responseIndex = $gapIdentifiersIndexMap[$mapKey->getFirst()]; } else { throw new MappingException('Fail to match identifiers on `mapKey` attribute from `mapping`'); } } // Check for duplicated response if (!$this->isDuplicatedResponse) { if (!isset($responseIndexSet[$responseValue])) { $responseIndexSet[$responseValue] = true; } else { $this->isDuplicatedResponse = true; } } // Wrap the identifier => score into an array as the identifier can be duplicated (Duplicated Response) // Build ValidResponse object array in the correct order matching the `gap` elements $responses[$responseIndex][] = new ValidResponse($mapEntry->getMappedValue(), [$responseValue]); } $this->assertEachGapHasCorrespondingValidResponses($responses); $responses = ArrayUtil::cartesianProductForResponses($responses); return ValidationBuilder\ValidationBuilder::build($this->questionTypeName, 'exactMatch', $responses); }