Skip to content

Commit

Permalink
Revert "Feat: Updated playerstatuscontroller and tests"
Browse files Browse the repository at this point in the history
This reverts commit fe6f10b.
  • Loading branch information
tommyah committed May 11, 2026
1 parent fe6f10b commit 1b0c689
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import edu.ntnu.idi.idatt2003.g40.mappe.model.Player;
import edu.ntnu.idi.idatt2003.g40.mappe.model.PlayerStatus;

import java.math.BigDecimal;

/**
* Controls and calculates the players' status.
*
Expand All @@ -18,22 +20,38 @@ private PlayerStatusController() {
*
* <p>Calculates what status the player should get
* based on players' net worth compared to starting
* money.</p>
* money, and current week.</p>
*
* @param player the player to give a status to.
*
* @return a PlayerStatus
* */
public static PlayerStatus getStatus(final Player player) {
float differenceInPercent = ((player.getNetWorth().floatValue()
/ player.getStartingMoney().floatValue()) - 1) * 100;
Integer startingMoneyInt = player.getStartingMoney().intValue();

BigDecimal difference =
player.getNetWorth().subtract(player.getStartingMoney());

return switch ((Integer) difference.intValue()) {
case Integer val when val >= percentAmount(startingMoneyInt, 900) -> PlayerStatus.OMNIPOTENT;
case Integer val when val >= percentAmount(startingMoneyInt, 400) -> PlayerStatus.SEER;
case Integer val when val >= percentAmount(startingMoneyInt, 200) -> PlayerStatus.PRO;
case Integer val when val >= percentAmount(startingMoneyInt, 100) -> PlayerStatus.TRYHARD;
case Integer val when val >= percentAmount(startingMoneyInt, 50) -> PlayerStatus.GOOD;
case Integer val when val >= percentAmount(startingMoneyInt, 20) -> PlayerStatus.NOVICE;
default -> PlayerStatus.NOOB;
};
}

for (int i = PlayerStatus.values().length; i > 0; i--) {
PlayerStatus curStatus = PlayerStatus.values()[i - 1];
if (differenceInPercent >= curStatus.getPercentIncreaseNeeded()) {
return curStatus;
}
}
return PlayerStatus.NOOB;
/**
* Helper method for increasing a value by x percent.
*
* @param value the value to calculate from
* @param x the percent amount
*
* @return the increased value.
* */
private static Integer percentAmount(final Integer value, final Integer x) {
return (value * x) / 100;
}
}
Original file line number Diff line number Diff line change
@@ -1,49 +1,23 @@
package edu.ntnu.idi.idatt2003.g40.mappe.model;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.math.BigDecimal;
import org.junit.jupiter.api.BeforeEach;
import edu.ntnu.idi.idatt2003.g40.mappe.controller.PlayerStatusController;
import org.junit.jupiter.api.Test;

class PlayerStatusTest {
import java.math.BigDecimal;

/**
* Player object used for testing.
* */
private Player testPlayer;
import static org.junit.jupiter.api.Assertions.*;

@BeforeEach
void setUp() {
testPlayer = new Player("Player", new BigDecimal(1000));
}
class PlayerStatusTest {

@Test
void getStatusAtStartReturnsWorstStatus() {
assertEquals(PlayerStatus.NOOB, testPlayer.getStatus());
}
void getStatusReturnsProperStatuses() {
Player testPlayer = new Player("Player", new BigDecimal(1000));
PlayerStatus gottenStatus = PlayerStatusController.getStatus(testPlayer);
assertEquals(PlayerStatus.NOOB, gottenStatus);

@Test
void getStatusAfterDoubleIncreaseReturnsBetterStatus() {
testPlayer.addMoney(new BigDecimal(1000));
assertEquals(PlayerStatus.TRYHARD, testPlayer.getStatus());
}

@Test
void gettingStatusWhenNegativeDifferenceReturnsWorstStatus() {
testPlayer.addMoney(new BigDecimal(-1000));
assertEquals(PlayerStatus.NOOB, testPlayer.getStatus());
}

@Test
void multipleChangesInValueCauseCorrectStatus() {
testPlayer.addMoney(new BigDecimal(2000));
assertEquals(PlayerStatus.PRO, testPlayer.getStatus());

testPlayer.addMoney(new BigDecimal(-1000));
assertEquals(PlayerStatus.TRYHARD, testPlayer.getStatus());
PlayerStatus gottenStatus2 = PlayerStatusController.getStatus(testPlayer);

testPlayer.addMoney(new BigDecimal(-500));
assertEquals(PlayerStatus.GOOD, testPlayer.getStatus());
assertEquals(PlayerStatus.TRYHARD, gottenStatus2);
}
}

0 comments on commit 1b0c689

Please sign in to comment.