-
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.
- Loading branch information
EspenTinius
committed
Mar 14, 2026
1 parent
6931e12
commit e260cfa
Showing
1 changed file
with
45 additions
and
3 deletions.
There are no files selected for viewing
48 changes: 45 additions & 3 deletions
48
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,45 @@ | ||
| public class PurchaseCalculatorTest { | ||
|
|
||
| } | ||
| 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; | ||
|
|
||
| class PurchaseCalculatorTest { | ||
|
|
||
| @Test | ||
| void calculateGrossReturnsPurchasePriceTimesQuantity() { | ||
| Stock stock = new Stock("AAPL", "Apple", new BigDecimal("150")); | ||
| Share share = new Share(stock, new BigDecimal("2"), new BigDecimal("100")); | ||
| PurchaseCalculator calculator = new PurchaseCalculator(share); | ||
|
|
||
| assertEquals(new BigDecimal("200"), calculator.calculateGross()); | ||
| } | ||
|
|
||
| @Test | ||
| void calculateCommissionReturnsHalfPercentOfGross() { | ||
| Stock stock = new Stock("AAPL", "Apple", new BigDecimal("150")); | ||
| Share share = new Share(stock, new BigDecimal("2"), new BigDecimal("100")); | ||
| PurchaseCalculator calculator = new PurchaseCalculator(share); | ||
|
|
||
| assertEquals(new BigDecimal("1.000"), calculator.calculateCommission()); | ||
| } | ||
|
|
||
| @Test | ||
| void calculateTaxReturnsZero() { | ||
| Stock stock = new Stock("AAPL", "Apple", new BigDecimal("150")); | ||
| Share share = new Share(stock, new BigDecimal("2"), new BigDecimal("100")); | ||
| PurchaseCalculator calculator = new PurchaseCalculator(share); | ||
|
|
||
| assertEquals(BigDecimal.ZERO, calculator.calculateTax()); | ||
| } | ||
|
|
||
| @Test | ||
| void calculateTotalReturnsGrossPlusCommission() { | ||
| Stock stock = new Stock("AAPL", "Apple", new BigDecimal("150")); | ||
| Share share = new Share(stock, new BigDecimal("2"), new BigDecimal("100")); | ||
| PurchaseCalculator calculator = new PurchaseCalculator(share); | ||
|
|
||
| assertEquals(new BigDecimal("201.000"), calculator.calculateTotal()); | ||
| } | ||
| } |