Skip to content

Commit

Permalink
Merge pull request #52 from IDATT2003-gruppe06/test-development
Browse files Browse the repository at this point in the history
Test development
  • Loading branch information
nolydvo authored May 25, 2026
2 parents 69f7abe + 2ef6cb7 commit 4dfeb51
Show file tree
Hide file tree
Showing 20 changed files with 81 additions and 84 deletions.

This file was deleted.

16 changes: 9 additions & 7 deletions src/main/java/millions/model/Share.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ public class Share {

/**
* @param stock Which stock the share is for.
* @param quantity How many stocks
* @param purchasePrice Purchase price of the share
* @throws IllegalArgumentException
* @param quantity How many stocks.
* @param purchasePrice Purchase price of the share.
* @throws IllegalArgumentException if stock is null.
* @throws IllegalArgumentException if quantity is null.
* @throws IllegalArgumentException if purchasePrice is null.
*/
public Share(Stock stock, BigDecimal quantity, BigDecimal purchasePrice) {
this.stock = stock;
Expand All @@ -30,27 +32,27 @@ public Share(Stock stock, BigDecimal quantity, BigDecimal purchasePrice) {
}
}

/** Share() with int quantity */
/** Share() with int quantity. */
public Share(Stock stock, int quantity, BigDecimal purchasePrice) {
this(stock, BigDecimal.valueOf(quantity), purchasePrice);
}

/**
* @return
* @return Stock object.
*/
public Stock getStock() {
return this.stock;
}

/**
* @return
* @return BigDecimal: quantity.
*/
public BigDecimal getQuantity() {
return this.quantity;
}

/**
* @return
* @return BigDecimal PurchasePrice.
*/
public BigDecimal getPurchasePrice() {
return this.purchasePrice;
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/millions/model/Stock.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,48 +38,49 @@ public Stock(String symbol, String company, List<BigDecimal> prices, List<BigDec
}
}

/** Stock() with single price instead of list */

/** Stock() with single price instead of list. */
public Stock(String symbol, String company, BigDecimal initialPrice, List<BigDecimal> volatilityFunctions) {
this(symbol, company, new ArrayList<>(List.of(initialPrice)), volatilityFunctions);
}

/**
* @return
* @return String: symbol.
*/
public String getSymbol() {
return this.symbol;
}

/**
* @return
* @return String: company.
*/
public String getCompany() {
return this.company;
}

/**
* @return
* @return BigDecimal: price.
*/
public BigDecimal getSalesPrice() {
return this.prices.getLast();
}

/**
* @param price Sales price
* @param price Sales price.
*/
public void addNewSalesPrice(BigDecimal price) {
this.prices.add(price);
}

/**
* @return
* @return BigDecimal list of prices.
*/
public List<BigDecimal> getHistoricalPrices() {
return this.prices;
}

/**
* @return
* @return BigDecimal highest recorded price.
*/
public BigDecimal getHighestPrice() {
BigDecimal highestPrice = this.prices.get(0);
Expand All @@ -92,7 +93,7 @@ public BigDecimal getHighestPrice() {
}

/**
* @return
* @return BigDecimal lowest recorded price.
*/
public BigDecimal getLowestPrice() {
BigDecimal lowestPrice = this.prices.get(0);
Expand All @@ -105,7 +106,7 @@ public BigDecimal getLowestPrice() {
}

/**
* @return
* @return BigDecimal price difference from last week
*/
public BigDecimal getLatestPriceChange() {
if (this.prices.size() < 2) {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/millions/model/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,30 @@ protected Transaction(Share share, int week, TransactionCalculator transactionCa
this.committed = false;
}

/**
* @return Share object
*/
public Share getShare() {
return this.share;
}

/**
* @return int: week
*/
public int getWeek() {
return this.week;
}

/**
* @return TransactionCalculator object
*/
public TransactionCalculator getCalculator() {
return this.transactionCalculator;
}

/**
* @return Boolean: status
*/
public boolean isCommitted() {
return this.committed;
}
Expand Down
27 changes: 26 additions & 1 deletion src/main/java/millions/model/TransactionArchive.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ public TransactionArchive() {
this.transactions = new ArrayList<>();
}

/**
* Adds a transaction to the archive
* @param transaction transaction object
* @return Boolean for success
*/
public boolean add(Transaction transaction) {
if (transactions.contains(transaction)) {
return false;
Expand All @@ -21,25 +26,45 @@ public boolean add(Transaction transaction) {
return true;
}

/**
* @return Boolean
*/
public boolean isEmpty() {
return transactions.isEmpty();
}

/**
* @return List of transaction objects
*/
public List<Transaction> getTransactions() {
return new ArrayList<>(transactions);
}

/**
* returns transaction processed in a given week
* @param week int
* @return List of transaction objects
*/
public List<Transaction> getTransactions(int week) {
return transactions.stream().filter(x -> x.getWeek() == week).collect(Collectors.toList());
}

/**
* Returns all purchase transactions in a given week
* @param week int
* @return List of transaction objects
*/
public List<Purchase> getPurchases(int week) {
return transactions.stream()
.filter(t -> t.getWeek() == week && t instanceof Purchase)
.map(t -> (Purchase) t)
.collect(Collectors.toList());
}

/**
* Returns all sale transactions in a given week
* @param week int
* @return List of transaction objects
*/
public List<Sale> getSales(int week) {
return transactions.stream()
.filter(t -> t.getWeek() == week && t instanceof Sale)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package millions;
package millions.controller.fileIO.CSV;

import millions.controller.fileIO.CSV.CSVStockFileParser;
import millions.controller.fileIO.InvalidFormatException;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;


import java.util.ArrayList;
import java.util.List;


Expand All @@ -18,8 +17,8 @@ public class CSVStockFileParserTest {
static String exampleString;
final CSVStockFileParser parser = new CSVStockFileParser();

@BeforeAll
public static void setUpTestString() {
@BeforeEach
public void setUpTestString() {
exampleString = "# Top 500 US Stocks by Market Cap\n";
exampleString += "# Ticker,Name,Price\n";
exampleString += "\n";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package millions;
package millions.controller.fileIO.CSV;

import millions.controller.fileIO.StockFileReader;
import org.junit.jupiter.api.BeforeAll;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
package millions;
package millions.model;

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

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import millions.model.Exchange;
import millions.model.ExchangeListener;
import millions.model.Player;
import millions.model.Purchase;
import millions.model.Sale;
import millions.model.Share;
import millions.model.Stock;
import millions.model.Transaction;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package millions;
package millions.model;

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

import java.math.BigDecimal;
import java.util.List;
import java.util.stream.IntStream;
import millions.model.*;

import org.junit.jupiter.api.Test;

class ExchangeTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package millions;
package millions.model;

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

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import millions.model.*;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package millions;
package millions.model;

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

import java.math.BigDecimal;
import millions.model.Player;

import org.junit.jupiter.api.Test;

class PlayerTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package millions;
package millions.model;

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

import java.math.BigDecimal;
import millions.model.Portfolio;
import millions.model.Share;
import millions.model.Stock;

import org.junit.jupiter.api.Test;

class PortfolioTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package millions;
package millions.model;

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

import java.math.BigDecimal;

import millions.model.Player;
import millions.model.Purchase;
import millions.model.Share;
import millions.model.Stock;
import org.junit.jupiter.api.Test;

class PurchaseTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package millions;
package millions.model;

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

import java.math.BigDecimal;

import millions.model.Player;
import millions.model.Sale;
import millions.model.Share;
import millions.model.Stock;
import org.junit.jupiter.api.Test;

class SaleTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package millions;
package millions.model;

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

import java.math.BigDecimal;

import millions.model.Share;
import millions.model.Stock;
import org.junit.jupiter.api.Test;

class ShareTest {
Expand Down
Loading

0 comments on commit 4dfeb51

Please sign in to comment.