-
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.
merge
- Loading branch information
Showing
2 changed files
with
81 additions
and
4 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)); | ||
| } | ||
| } |
2 changes: 1 addition & 1 deletion
2
src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/PurchaseCalculatorTest.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,3 @@ | ||
| public class PurchaseCalculatorTest { | ||
|
|
||
| } |