Skip to content

Commit

Permalink
unit test Player class
Browse files Browse the repository at this point in the history
  • Loading branch information
EspenTinius committed Mar 14, 2026
1 parent 6931e12 commit 497f04e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Player.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package edu.ntnu.idi.idatt2003.g40.mappe;

import java.math.BigDecimal;
import java.util.Objects;

public class Player {

Expand Down
51 changes: 48 additions & 3 deletions src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/PlayerTest.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,48 @@
public class PlayerTest {

}
package edu.ntnu.idi.idatt2003.g40.mappe;

import org.junit.jupiter.api.Test;

import java.math.BigDecimal;

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

class PlayerTest {

@Test
void constructorSetsNameMoneyPortfolioAndArchive() {
Player player = new Player("Alice", new BigDecimal("1000"));

assertEquals("Alice", player.getName());
assertEquals(new BigDecimal("1000"), player.getMoney());
assertNotNull(player.getPortfolio());
assertNotNull(player.getTransactionArchive());
}

@Test
void addMoneyIncreasesBalance() {
Player player = new Player("Bob", new BigDecimal("500"));

player.addMoney(new BigDecimal("200"));

assertEquals(new BigDecimal("700"), player.getMoney());
}

@Test
void withdrawMoneyDecreasesBalance() {
Player player = new Player("Charlie", new BigDecimal("500"));

player.withdrawMoney(new BigDecimal("150"));

assertEquals(new BigDecimal("350"), player.getMoney());
}

@Test
void addAndWithdrawMoneyUpdateBalanceCorrectly() {
Player player = new Player("Dana", new BigDecimal("1000"));

player.addMoney(new BigDecimal("250"));
player.withdrawMoney(new BigDecimal("300"));

assertEquals(new BigDecimal("950"), player.getMoney());
}
}

0 comments on commit 497f04e

Please sign in to comment.