-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
EspenTinius
committed
Mar 14, 2026
1 parent
6931e12
commit 497f04e
Showing
2 changed files
with
48 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 48 additions & 3 deletions
51
src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/PlayerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()); | ||
| } | ||
| } |