Skip to content
Snippets Groups Projects
Commit 8fb72607 authored by srosse's avatar srosse
Browse files

OO-4483: remove debugging code, add unit test for special case

parent a7283276
No related branches found
No related tags found
No related merge requests found
...@@ -75,13 +75,11 @@ public class HighScoreManager { ...@@ -75,13 +75,11 @@ public class HighScoreManager {
float buffer = -1; float buffer = -1;
int index = 0; int index = 0;
// int rank = 1;
double[] allScores = new double[allMembers.size()]; double[] allScores = new double[allMembers.size()];
for (int j = 0; j < allMembers.size(); j++) { for (int j = 0; j < allMembers.size(); j++) {
HighScoreTableEntry member = allMembers.get(j); HighScoreTableEntry member = allMembers.get(j);
if (member.getScore() < buffer){ if (member.getScore() < buffer){
index++; index++;
// rank = j + 1;
} }
//first three position are put in separate lists, exclude zero scorers //first three position are put in separate lists, exclude zero scorers
if (index < 3 && member.getScore() > 0) { if (index < 3 && member.getScore() > 0) {
...@@ -103,7 +101,7 @@ public class HighScoreManager { ...@@ -103,7 +101,7 @@ public class HighScoreManager {
.filter(a -> a.getIdentity().equals(ownIdentity)) .filter(a -> a.getIdentity().equals(ownIdentity))
.collect(Collectors.toList())); .collect(Collectors.toList()));
if (ownIdMembers.size() > 0) { if (!ownIdMembers.isEmpty()) {
log.info(Tracing.M_AUDIT, "2nd Highscore Table established"); log.info(Tracing.M_AUDIT, "2nd Highscore Table established");
} }
...@@ -122,7 +120,7 @@ public class HighScoreManager { ...@@ -122,7 +120,7 @@ public class HighScoreManager {
double min = Math.floor(Arrays.stream(scores).min().getAsDouble()); double min = Math.floor(Arrays.stream(scores).min().getAsDouble());
double range = max - min; double range = max - min;
// use original scores if range is too small else convert results to fit histogram // use original scores if range is too small else convert results to fit histogram
if (range <= 20 && range <0) { if (range <= 20) {
classwidth = 1; classwidth = 1;
return new HighScoreRankingResults(scores, classwidth, min); return new HighScoreRankingResults(scores, classwidth, min);
} else { } else {
...@@ -168,7 +166,7 @@ public class HighScoreManager { ...@@ -168,7 +166,7 @@ public class HighScoreManager {
// allow one extension if no borders are defined // allow one extension if no borders are defined
primeRange = upperBorder - lowerBorder > 0; primeRange = upperBorder - lowerBorder > 0;
} }
// steps can only be natural numbers // steps can only be natural numbers
classwidth = Math.round(range / numberofclasses); classwidth = Math.round(range / numberofclasses);
// modified scores are calculated and saved // modified scores are calculated and saved
double[] allScores = new double[scores.length]; double[] allScores = new double[scores.length];
...@@ -189,7 +187,7 @@ public class HighScoreManager { ...@@ -189,7 +187,7 @@ public class HighScoreManager {
/** /**
* Calculate histogram cutvalue using results from the method (processHistogramData(double[])) * Calculate histogram cut value using results from the method (processHistogramData(double[]))
* *
* @param score the score * @param score the score
* @return the double * @return the double
...@@ -199,11 +197,9 @@ public class HighScoreManager { ...@@ -199,11 +197,9 @@ public class HighScoreManager {
// determine n-th class to fit the current score result // determine n-th class to fit the current score result
double n = Math.ceil((score - min) / classwidth); double n = Math.ceil((score - min) / classwidth);
// calculate higher score to fit the class width // calculate higher score to fit the class width
double cutvalue = min + (n * classwidth); return min + (n * classwidth);
return cutvalue; }
} else { return score;
return score;
}
} }
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
* <p> * <p>
*/ */
package org.olat.course.highscore; package org.olat.course.highscore;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
...@@ -39,6 +40,7 @@ import java.util.ArrayList; ...@@ -39,6 +40,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.olat.core.commons.persistence.DB; import org.olat.core.commons.persistence.DB;
import org.olat.core.id.Identity; import org.olat.core.id.Identity;
...@@ -101,4 +103,46 @@ public class HighScoreManagerTest extends OlatTestCase { ...@@ -101,4 +103,46 @@ public class HighScoreManagerTest extends OlatTestCase {
long classwidth = highScoreManager.processHistogramData(allScores, 0F, 30F).getClasswidth(); long classwidth = highScoreManager.processHistogramData(allScores, 0F, 30F).getClasswidth();
assertEquals(2L, classwidth); assertEquals(2L, classwidth);
} }
@Test
public void highscoreTest_sameResults() {
List<AssessmentEntry> assessEntries = new ArrayList<>();
//Create entries, add to List
for (int i = 0; i < 10; i++) {
Identity assessedIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("as-node-2");
RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
String subIdent = UUID.randomUUID().toString();
AssessmentEntry nodeAssessment = courseNodeAssessmentDao
.createAssessmentEntry(assessedIdentity, subIdent, entry, subIdent, entry);
nodeAssessment.setScore(new BigDecimal(8.0));
dbInstance.commitAndCloseSession();
AssessmentEntry reloadedAssessment = courseNodeAssessmentDao.loadAssessmentEntryById(nodeAssessment.getKey());
assessEntries.add(reloadedAssessment);
}
List<Integer> ownIdIndices = new ArrayList<>();
List<HighScoreTableEntry> allMembers = new ArrayList<>();
List<HighScoreTableEntry> ownIdMembers = new ArrayList<>();
List<List<HighScoreTableEntry>> allPodium = new ArrayList<>();
allPodium.add(new ArrayList<>());
allPodium.add(new ArrayList<>());
allPodium.add(new ArrayList<>());
double[] allScores = highScoreManager.sortRankByScore(assessEntries, allMembers, ownIdMembers, allPodium,
ownIdIndices, 5, JunitTestHelper.createAndPersistIdentityAsRndUser("as-node-2"))
.getScores();
for(int i=allScores.length; i-->0; ) {
Assert.assertEquals(8.0d, allScores[i], 0.00001d);
}
double[] histogramData = highScoreManager.processHistogramData(allScores, 0F, 30F).getModifiedScores();
assertNotNull(histogramData);
for(int i=allScores.length; i-->0; ) {
Assert.assertEquals(8.0d, allScores[i], 0.00001d);
}
long classwidth = highScoreManager.processHistogramData(allScores, 0F, 30F).getClasswidth();
assertEquals(1l, classwidth);
}
} }
\ No newline at end of file
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