From 3003934b508438a46d0e54b3966b61d5d9fc4635 Mon Sep 17 00:00:00 2001 From: EspenTinius Date: Fri, 13 Mar 2026 21:39:03 +0100 Subject: [PATCH 1/3] =?UTF-8?q?dette=20b=C3=B8r=20fikse=20problemet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/edu/ntnu/idi/idatt2003/g40/mappe/Exchange.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Exchange.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Exchange.java index 2083d6a..6276925 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Exchange.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Exchange.java @@ -55,12 +55,14 @@ public Transaction buy(String symbol, BigDecimal quantity, Player player) { Stock stock = stockMap.get(symbol); Share share = new Share(stock, quantity, stock.getSalesPrice()); TransactionCalculator calculator = new PurchaseCalculator(share); - return new Purchase(share, week, calculator, player); + player.withdrawMoney(calculator.calculateTotal()); + return new Purchase(share, week, calculator); } public Transaction sell(Share share, Player player) { TransactionCalculator calculator = new SaleCalculator(share); - return new Sale(share, week, calculator, player); + player.addMoney(calculator.calculateTotal()); + return new Sale(share, week, calculator); } public void advance() { From 4b40322d9e44bfbbd808232553f69e74601a8c40 Mon Sep 17 00:00:00 2001 From: EspenTinius Date: Sat, 14 Mar 2026 06:35:06 +0100 Subject: [PATCH 2/3] unit test --- .../ntnu/idi/idatt2003/g40/mappe/Player.java | 1 - .../idi/idatt2003/g40/mappe/ShareTest.java | 51 +++++++++++++++++-- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Player.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Player.java index 0114bbf..0d5939d 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Player.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Player.java @@ -1,7 +1,6 @@ package edu.ntnu.idi.idatt2003.g40.mappe; import java.math.BigDecimal; -import java.util.Objects; public class Player { diff --git a/src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/ShareTest.java b/src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/ShareTest.java index 2e94fdf..0a5deb1 100644 --- a/src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/ShareTest.java +++ b/src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/ShareTest.java @@ -1,3 +1,48 @@ -public class ShareTest { - -} +package edu.ntnu.idi.idatt2003.g40.mappe; + +import org.junit.jupiter.api.Test; + +import java.math.BigDecimal; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; + +class ShareTest { + + @Test + void constructorStoresAllValuesCorrectly() { + Stock stock = new Stock("AAPL", "Apple Inc.", new BigDecimal("150.00")); + BigDecimal quantity = new BigDecimal("10"); + BigDecimal purchasePrice = new BigDecimal("145.50"); + + Share share = new Share(stock, quantity, purchasePrice); + + assertSame(stock, share.getStock()); + assertEquals(quantity, share.getQuantity()); + assertEquals(purchasePrice, share.getPurchasePrice()); + } + + @Test + void shareSupportsDecimalValues() { + Stock stock = new Stock("TSLA", "Tesla Inc.", new BigDecimal("200.00")); + + Share share = new Share( + stock, + new BigDecimal("2.5"), + new BigDecimal("198.75") + ); + + assertEquals(new BigDecimal("2.5"), share.getQuantity()); + assertEquals(new BigDecimal("198.75"), share.getPurchasePrice()); + } + + @Test + void getStockReturnsCorrectStockObject() { + Stock stock = new Stock("NVDA", "NVIDIA Corporation", new BigDecimal("875.40")); + Share share = new Share(stock, new BigDecimal("4"), new BigDecimal("850.00")); + + assertSame(stock, share.getStock()); + assertEquals("NVDA", share.getStock().getSymbol()); + assertEquals("NVIDIA Corporation", share.getStock().getCompany()); + } +} \ No newline at end of file From dfcddb252bf9bb2e349da78c7dfbc5285d7f598a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Espen=20Tinius=20Roli=20S=C3=B8rensen?= Date: Sat, 14 Mar 2026 06:41:38 +0100 Subject: [PATCH 3/3] Update ShareTest.java --- .../idi/idatt2003/g40/mappe/ShareTest.java | 47 +------------------ 1 file changed, 1 insertion(+), 46 deletions(-) diff --git a/src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/ShareTest.java b/src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/ShareTest.java index 0a5deb1..92414c2 100644 --- a/src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/ShareTest.java +++ b/src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/ShareTest.java @@ -1,48 +1,3 @@ -package edu.ntnu.idi.idatt2003.g40.mappe; - -import org.junit.jupiter.api.Test; - -import java.math.BigDecimal; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertSame; - class ShareTest { - @Test - void constructorStoresAllValuesCorrectly() { - Stock stock = new Stock("AAPL", "Apple Inc.", new BigDecimal("150.00")); - BigDecimal quantity = new BigDecimal("10"); - BigDecimal purchasePrice = new BigDecimal("145.50"); - - Share share = new Share(stock, quantity, purchasePrice); - - assertSame(stock, share.getStock()); - assertEquals(quantity, share.getQuantity()); - assertEquals(purchasePrice, share.getPurchasePrice()); - } - - @Test - void shareSupportsDecimalValues() { - Stock stock = new Stock("TSLA", "Tesla Inc.", new BigDecimal("200.00")); - - Share share = new Share( - stock, - new BigDecimal("2.5"), - new BigDecimal("198.75") - ); - - assertEquals(new BigDecimal("2.5"), share.getQuantity()); - assertEquals(new BigDecimal("198.75"), share.getPurchasePrice()); - } - - @Test - void getStockReturnsCorrectStockObject() { - Stock stock = new Stock("NVDA", "NVIDIA Corporation", new BigDecimal("875.40")); - Share share = new Share(stock, new BigDecimal("4"), new BigDecimal("850.00")); - - assertSame(stock, share.getStock()); - assertEquals("NVDA", share.getStock().getSymbol()); - assertEquals("NVIDIA Corporation", share.getStock().getCompany()); - } -} \ No newline at end of file +}