From 2df1b1319025b208f8fda98669b63a43f1a8fe26 Mon Sep 17 00:00:00 2001 From: srosse <stephane.rosse@frentix.com> Date: Fri, 15 Feb 2019 18:02:58 +0100 Subject: [PATCH] OO-3880: trim FIB for archive and statistics like QtiWorks --- .../TextEntryInteractionStatistics.java | 6 +- .../FIBAssessmentItemBuilder.java | 7 +- .../TextEntryInteractionStatisticsTest.java | 106 ++++++++++++++++++ .../java/org/olat/test/AllTestsJunit4.java | 2 + 4 files changed, 117 insertions(+), 4 deletions(-) create mode 100644 src/test/java/org/olat/ims/qti21/statistics/TextEntryInteractionStatisticsTest.java diff --git a/src/main/java/org/olat/ims/qti21/model/statistics/TextEntryInteractionStatistics.java b/src/main/java/org/olat/ims/qti21/model/statistics/TextEntryInteractionStatistics.java index c5a70d39229..148768d4620 100644 --- a/src/main/java/org/olat/ims/qti21/model/statistics/TextEntryInteractionStatistics.java +++ b/src/main/java/org/olat/ims/qti21/model/statistics/TextEntryInteractionStatistics.java @@ -65,10 +65,12 @@ public class TextEntryInteractionStatistics extends AbstractTextEntryInteraction if((value1 != null && value1.isEmpty()) && (value2 == null || value2.isEmpty())) return true; if(caseSensitive) { - if(value1.equals(value2)) { + if(value1.equals(value2) + || (value2 != null && value1.trim().equals(value2.trim()))) { return true; } - } else if(value1.equalsIgnoreCase(value2)) { + } else if(value1.equalsIgnoreCase(value2) + || (value2 != null && value1.trim().equalsIgnoreCase(value2.trim()))) { return true; } return false; diff --git a/src/main/java/org/olat/ims/qti21/model/xml/interactions/FIBAssessmentItemBuilder.java b/src/main/java/org/olat/ims/qti21/model/xml/interactions/FIBAssessmentItemBuilder.java index 0a37fc34810..59d41453b5d 100644 --- a/src/main/java/org/olat/ims/qti21/model/xml/interactions/FIBAssessmentItemBuilder.java +++ b/src/main/java/org/olat/ims/qti21/model/xml/interactions/FIBAssessmentItemBuilder.java @@ -1098,6 +1098,7 @@ public class FIBAssessmentItemBuilder extends AssessmentItemBuilder { * @param response * @return */ + @Override public boolean match(String response) { if(match(response, solution)) { return true; @@ -1113,10 +1114,12 @@ public class FIBAssessmentItemBuilder extends AssessmentItemBuilder { private boolean match(String response, String alternative) { if(caseSensitive) { - if(alternative.equals(response)) { + if(alternative.equals(response) + || (response != null && alternative.trim().equals(response.trim()))) { return true; } - } else if(alternative.equalsIgnoreCase(response)) { + } else if(alternative.equalsIgnoreCase(response) + || (response != null && alternative.trim().equalsIgnoreCase(response.trim()))) { return true; } return false; diff --git a/src/test/java/org/olat/ims/qti21/statistics/TextEntryInteractionStatisticsTest.java b/src/test/java/org/olat/ims/qti21/statistics/TextEntryInteractionStatisticsTest.java new file mode 100644 index 00000000000..91cbefb555a --- /dev/null +++ b/src/test/java/org/olat/ims/qti21/statistics/TextEntryInteractionStatisticsTest.java @@ -0,0 +1,106 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ +package org.olat.ims.qti21.statistics; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; +import org.olat.ims.qti21.model.statistics.TextEntryInteractionStatistics; +import org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.TextEntry; +import org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.TextEntryAlternative; + +import uk.ac.ed.ph.jqtiplus.types.Identifier; + +/** + * Test the OpenOLAT implementation of match() / or Mapping (in QtiWorks) + * for textEntryInteraction. + * + * Initial date: 15 févr. 2019<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +@RunWith(Parameterized.class) +public class TextEntryInteractionStatisticsTest { + + @Parameters + public static Collection<Object[]> data() { + return Arrays.asList(new Object[][] { + { true, "+bremsen()", Collections.singletonList("+ bremsen()"), "+bremsen()", true }, + { true, "+bremsen()", Collections.singletonList("+ bremsen()"), " +bremsen()", true }, + { true, "+bremsen()", Collections.singletonList("+ bremsen()"), " +bremsen ()", false }, + { false, "+bremsen()", Collections.singletonList("+ bremsen()"), " +Bremsen ()", false }, + { false, "+bremsen()", Collections.singletonList("+ bremsen()"), " +breMSen()", true }, + { false, "+bremsen()", Collections.singletonList("+ bremsen()"), " +BREMSEN() ", true }, + { false, "+bremsen()", Collections.singletonList("+ bremsen()"), " + BREMSEN() ", true }, + { false, "+bremsen()", Collections.singletonList("+ bremsen()"), "bremsen", false }, + { false, "+bremsen()", Collections.singletonList("+ bremsen()"), "bremsen()", false }, + { false, "+bremsen()", Collections.singletonList("+ bremsen()"), "-bremsen()", false } + }); + } + + private boolean caseSensitive; + private String correctResponse; + private List<String> alternatives; + private String response; + private boolean match; + + public TextEntryInteractionStatisticsTest(boolean caseSensitive, String correctResponse, List<String> alternatives, String response, boolean match) { + this.caseSensitive = caseSensitive; + this.correctResponse = correctResponse; + this.alternatives = alternatives; + this.response = response; + this.match = match; + } + + @Test + public void matchStatistics() { + TextEntryInteractionStatistics textEntryStats = new TextEntryInteractionStatistics(null, + caseSensitive, correctResponse, alternatives, 1.0d); + boolean hasMatched = textEntryStats.matchResponse(response); + Assert.assertEquals(match, hasMatched); + } + + @Test + public void matchBuilder() { + TextEntry textEntry = new TextEntry(Identifier.assumedLegal("textentry")); + textEntry.setSolution(correctResponse); + + List<TextEntryAlternative> textEntryAlternatives = new ArrayList<>(); + for(String alt:alternatives) { + TextEntryAlternative alternative = new TextEntryAlternative(); + alternative.setAlternative(alt); + textEntryAlternatives.add(alternative); + } + + textEntry.setAlternatives(textEntryAlternatives); + textEntry.setCaseSensitive(caseSensitive); + boolean hasMatched = textEntry.match(response); + Assert.assertEquals(match, hasMatched); + } + +} diff --git a/src/test/java/org/olat/test/AllTestsJunit4.java b/src/test/java/org/olat/test/AllTestsJunit4.java index af0400ec34c..d4f2e000aa2 100644 --- a/src/test/java/org/olat/test/AllTestsJunit4.java +++ b/src/test/java/org/olat/test/AllTestsJunit4.java @@ -250,10 +250,12 @@ import org.junit.runners.Suite; org.olat.ims.qti21.model.xml.AssessmentHtmlBuilderTest.class, org.olat.ims.qti21.model.xml.AssessmentItemPackageTest.class, org.olat.ims.qti21.model.xml.ManifestPackageTest.class, + org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilderTextEntryTest.class, org.olat.ims.qti21.pool.QTI12To21ConverterTest.class, org.olat.ims.qti21.pool.QTI12To21HtmlHandlerTest.class, org.olat.ims.qti21.pool.QTI21QPoolServiceProviderTest.class, org.olat.ims.qti21.repository.handlers.QTI21AssessmentTestHandlerTest.class, + org.olat.ims.qti21.statistics.TextEntryInteractionStatisticsTest.class, org.olat.ims.qti21.model.xml.Onyx38ToQtiWorksAssessementItemsTest.class, org.olat.ims.qti21.model.xml.OnyxToQtiWorksAssessementItemsTest.class, org.olat.ims.qti21.model.xml.OnyxToQtiWorksAssessementTestsTest.class, -- GitLab