From 1b0c689a6dcf3e9d8d0fe430fb2614df57ef0188 Mon Sep 17 00:00:00 2001 From: = Date: Mon, 11 May 2026 12:56:20 +0200 Subject: [PATCH] Revert "Feat: Updated playerstatuscontroller and tests" This reverts commit fe6f10b64fca82ad6a6b7f8c0a5a5145ed24a213. --- .../controller/PlayerStatusController.java | 38 +++++++++++---- .../g40/mappe/model/PlayerStatusTest.java | 46 ++++--------------- 2 files changed, 38 insertions(+), 46 deletions(-) diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/controller/PlayerStatusController.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/controller/PlayerStatusController.java index b69af32..aa45ab6 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/controller/PlayerStatusController.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/controller/PlayerStatusController.java @@ -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. * @@ -18,22 +20,38 @@ private PlayerStatusController() { * *

Calculates what status the player should get * based on players' net worth compared to starting - * money.

+ * money, and current week.

* * @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; } } diff --git a/src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/model/PlayerStatusTest.java b/src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/model/PlayerStatusTest.java index 1765d46..a9a44f5 100644 --- a/src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/model/PlayerStatusTest.java +++ b/src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/model/PlayerStatusTest.java @@ -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); } } \ No newline at end of file