Skip to content

Commit 50914ce

Browse files
committed
add half-life test
1 parent 427c8ad commit 50914ce

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/test/java/net/discordjug/javabot/systems/help/HelpExperienceSubtractionTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package net.discordjug.javabot.systems.help;
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertFalse;
5+
import static org.junit.jupiter.api.Assertions.assertTrue;
46

57
import java.io.IOException;
68
import java.sql.SQLException;
@@ -89,6 +91,21 @@ void testFraction() {
8991
assertEquals(81, repo.getByUserId(1).get().getExperience());
9092
}
9193

94+
@Test
95+
void testXPHalfLife() {
96+
int startXP = 1_000;
97+
int half = startXP/2;
98+
repo.insert(new HelpAccount(1, startXP));
99+
for (int i = 0; i < 55; i++) {
100+
repo.removeExperienceFromAllAccounts(1.25, 0, 1_000);
101+
double actualXP = repo.getByUserId(1).get().getExperience();
102+
assertTrue(actualXP > half, "In iteration "+i+", XP have decayed by more than 50%, user has "+actualXP+"XP after iteration");
103+
}
104+
repo.removeExperienceFromAllAccounts(1.25, 0, 1_000);
105+
double actualXP = repo.getByUserId(1).get().getExperience();
106+
assertFalse(actualXP > half, "After all iterations, XP have not decayed by more than 50%, user has "+actualXP+"XP at the end");
107+
}
108+
92109
@Test
93110
void testMultipleUsers() {
94111
repo.insert(new HelpAccount(79, 79));//below min

0 commit comments

Comments
 (0)