Skip to content

Commit

Permalink
add unit tests for Player and improved tests for Exchange and Portfolio
Browse files Browse the repository at this point in the history
  • Loading branch information
einaskoi committed Feb 25, 2026
1 parent b76cad4 commit 1fff7e8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
import org.junit.jupiter.api.Test;

public class ExchangeTest {

private Exchange exchange;

@BeforeEach
public void setUp() {
void setUp() {
Stock stock = new Stock("AAPL", "Apple Inc.", new BigDecimal("100"));
exchange = new Exchange("NYSE", List.of(stock));
}
Expand Down
29 changes: 29 additions & 0 deletions src/test/java/edu/ntnu/idi/idatt2003/gruppe42/PlayerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package edu.ntnu.idi.idatt2003.gruppe42;

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

import edu.ntnu.idi.idatt2003.gruppe42.Model.Player;
import java.math.BigDecimal;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class PlayerTest {
private Player player;

@BeforeEach
void setUp() {
player = new Player("John Doe", new BigDecimal("10000"));
}

@Test
void addMoneyTest() {
player.addMoney(new BigDecimal("5000"));
assertEquals(new BigDecimal("15000"), player.getMoney());
}

@Test
void withdrawMoneyTest() {
player.withdrawMoney(new BigDecimal("5000"));
assertEquals(new BigDecimal("5000"), player.getMoney());
}
}
32 changes: 17 additions & 15 deletions src/test/java/edu/ntnu/idi/idatt2003/gruppe42/PortfolioTest.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
package edu.ntnu.idi.idatt2003.gruppe42;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import edu.ntnu.idi.idatt2003.gruppe42.Model.Portfolio;
import edu.ntnu.idi.idatt2003.gruppe42.Model.Share;
import edu.ntnu.idi.idatt2003.gruppe42.Model.Stock;
import org.junit.jupiter.api.Test;

import java.math.BigDecimal;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class PortfolioTest {
private Portfolio portfolio;
private Stock stock;
private Share share;

@BeforeEach
void setUp() {
portfolio = new Portfolio();
stock = new Stock("AAPL", "Apple Inc.", new BigDecimal("10000"));
share = new Share(stock, new BigDecimal("10"), new BigDecimal("15000"));
}

@Test
public void addShareTest() {
Portfolio portfolio = new Portfolio();
Stock stock = new Stock("AAPL", "Apple", new BigDecimal("10000"));
Share share = new Share(stock, new BigDecimal("10"), new BigDecimal("15000"));

void addShareTest() {
boolean result = portfolio.addShare(share);
assertTrue(portfolio.contains(share));
}

@Test
public void removeShareTest() {
Portfolio portfolio = new Portfolio();
Stock stock = new Stock("AAPL", "Apple", new BigDecimal("10000"));
Share share = new Share(stock, new BigDecimal("10"), new BigDecimal("15000"));

void removeShareTest() {
portfolio.addShare(share);
boolean result = portfolio.removeShare(share);
assertFalse(portfolio.contains(share));
Expand Down

0 comments on commit 1fff7e8

Please sign in to comment.