Skip to content
Snippets Groups Projects
Commit 305fe3ca authored by uhensler's avatar uhensler
Browse files

OO-4554: Value 10 is treated as 1 in some survey reports

parent 5192e595
No related branches found
No related tags found
No related merge requests found
......@@ -67,12 +67,22 @@ public class CalculatedLong {
}
private static String trimZerosFromEnd(String value) {
int len = value.length();
int st = 0;
while ((st < len) && (value.charAt(len - 1) == '0' || value.charAt(len - 1) == '.')) {
len--;
if (value.contains(".")) {
int len = value.length();
int st = 0;
while (st < len) {
if (value.charAt(len - 1) == '0') {
len--;
} else if (value.charAt(len - 1) == '.') {
len--;
break; // stop at decimal point
}
}
System.out.println("trimmed: "+value.substring(0, len));
return value.substring(0, len);
}
return value.substring(0, len);
System.out.println("untrimmed: " + value);
return value;
}
}
......@@ -203,9 +203,11 @@ public class EvaluationFormReportDAOTest extends OlatTestCase {
EvaluationFormSession session1 = evaTestHelper.createSession();
EvaluationFormSession session2 = evaTestHelper.createSession();
EvaluationFormSession session3 = evaTestHelper.createSession();
EvaluationFormSession session4 = evaTestHelper.createSession();
EvaluationFormSession otherSession = evaTestHelper.createSession();
BigDecimal numberThreeTimes = BigDecimal.valueOf(1);
BigDecimal numberOnce = BigDecimal.valueOf(2);
BigDecimal ten = BigDecimal.valueOf(10);
evaluationFormManager.createNumericalResponse(responseIdentifier1, otherSession, numberThreeTimes);
evaluationFormManager.createNoResponse(responseIdentifier1, session1);
......@@ -216,23 +218,28 @@ public class EvaluationFormReportDAOTest extends OlatTestCase {
evaluationFormManager.finishSession(session1);
evaluationFormManager.createNumericalResponse(responseIdentifier1, session2, numberThreeTimes);
evaluationFormManager.finishSession(session2);
// unfinished session counts as well
evaluationFormManager.createNumericalResponse(responseIdentifier1, session4, ten);
evaluationFormManager.finishSession(session4);
// unfinished session counts as well (use filter if not wanted)
evaluationFormManager.createNumericalResponse(responseIdentifier1, session3, numberThreeTimes);
dbInstance.commit();
List<String> responseIdentifiers = Arrays.asList(responseIdentifier1, responseIdentifier2);
List<EvaluationFormSession> sessions = Arrays.asList(session1, session2, session3);
List<EvaluationFormSession> sessions = Arrays.asList(session1, session2, session3, session4);
SessionFilter filter = SessionFilterFactory.create(sessions);
List<CalculatedLong> counts = sut.getCountByIdentifiersAndNumerical(responseIdentifiers, filter);
assertThat(counts).hasSize(3);
assertThat(counts).hasSize(4);
assertThat(getValue(counts, responseIdentifier1, numberThreeTimes.toPlainString())).isEqualTo(3);
assertThat(getValue(counts, responseIdentifier1, numberOnce.toPlainString())).isEqualTo(1);
assertThat(getValue(counts, responseIdentifier1, ten.toPlainString())).isEqualTo(1);
assertThat(getValue(counts, responseIdentifier2, numberOnce.toPlainString())).isEqualTo(1);
}
private Long getValue(List<CalculatedLong> calculatedLongs, String identifier, String subidentifier) {
System.out.println("Wanted: " + identifier + "/" + subidentifier);
for (CalculatedLong calculatedLong: calculatedLongs) {
System.out.println("has: " + calculatedLong.getIdentifier() + "/" + calculatedLong.getSubIdentifier() + " = " + calculatedLong.getValue());
if (calculatedLong.getIdentifier().equals(identifier) && calculatedLong.getSubIdentifier().equals(subidentifier)) {
return calculatedLong.getValue();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment