-
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.
nå er det faktisk portfoliotesten som ligger med og ikke bare en kopi av den andre testen
- Loading branch information
EspenTinius
committed
Mar 14, 2026
1 parent
44e2aa3
commit 2079d38
Showing
1 changed file
with
80 additions
and
3 deletions.
There are no files selected for viewing
83 changes: 80 additions & 3 deletions
83
src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/PortfolioTest.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,80 @@ | ||
| public class PortfolioTest { | ||
|
|
||
| } | ||
| package edu.ntnu.idi.idatt2003.g40.mappe; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.util.List; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| class PortfolioTest { | ||
|
|
||
| @Test | ||
| void addShareAddsShareToPortfolio() { | ||
| Portfolio portfolio = new Portfolio(); | ||
| Stock stock = new Stock("AAPL", "Apple", new BigDecimal("150")); | ||
| Share share = new Share(stock, new BigDecimal("2"), new BigDecimal("100")); | ||
|
|
||
| boolean result = portfolio.addShare(share); | ||
|
|
||
| assertTrue(result); | ||
| assertTrue(portfolio.contains(share)); | ||
| } | ||
|
|
||
| @Test | ||
| void removeShareRemovesShareFromPortfolio() { | ||
| Portfolio portfolio = new Portfolio(); | ||
| Stock stock = new Stock("TSLA", "Tesla", new BigDecimal("200")); | ||
| Share share = new Share(stock, new BigDecimal("1"), new BigDecimal("200")); | ||
|
|
||
| portfolio.addShare(share); | ||
| boolean result = portfolio.removeShare(share); | ||
|
|
||
| assertTrue(result); | ||
| assertFalse(portfolio.contains(share)); | ||
| } | ||
|
|
||
| @Test | ||
| void getSharesReturnsAllShares() { | ||
| Portfolio portfolio = new Portfolio(); | ||
|
|
||
| Stock stock = new Stock("AAPL", "Apple", new BigDecimal("150")); | ||
| Share share = new Share(stock, new BigDecimal("3"), new BigDecimal("150")); | ||
|
|
||
| portfolio.addShare(share); | ||
|
|
||
| List<Share> shares = portfolio.getShares(); | ||
|
|
||
| assertEquals(1, shares.size()); | ||
| assertTrue(shares.contains(share)); | ||
| } | ||
|
|
||
| @Test | ||
| void getSharesWithSymbolReturnsMatchingShares() { | ||
| Portfolio portfolio = new Portfolio(); | ||
|
|
||
| Stock apple = new Stock("AAPL", "Apple", new BigDecimal("150")); | ||
| Stock tesla = new Stock("TSLA", "Tesla", new BigDecimal("200")); | ||
|
|
||
| Share appleShare = new Share(apple, new BigDecimal("1"), new BigDecimal("150")); | ||
| Share teslaShare = new Share(tesla, new BigDecimal("1"), new BigDecimal("200")); | ||
|
|
||
| portfolio.addShare(appleShare); | ||
| portfolio.addShare(teslaShare); | ||
|
|
||
| List<Share> result = portfolio.getShares("AAPL"); | ||
|
|
||
| assertEquals(1, result.size()); | ||
| assertTrue(result.contains(appleShare)); | ||
| } | ||
|
|
||
| @Test | ||
| void containsReturnsFalseWhenShareNotPresent() { | ||
| Portfolio portfolio = new Portfolio(); | ||
|
|
||
| Stock stock = new Stock("NVDA", "Nvidia", new BigDecimal("800")); | ||
| Share share = new Share(stock, new BigDecimal("1"), new BigDecimal("800")); | ||
|
|
||
| assertFalse(portfolio.contains(share)); | ||
| } | ||
| } |