-
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 a103b34
Showing
1 changed file
with
55 additions
and
3 deletions.
There are no files selected for viewing
58 changes: 55 additions & 3 deletions
58
src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/SaleCalculatorTest.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,55 @@ | ||
| public class SaleCalculatorTest { | ||
|
|
||
| } | ||
| 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 SaleCalculatorTest { | ||
|
|
||
| @Test | ||
| void calculateGrossReturnsSalesPriceTimesQuantity() { | ||
| Stock stock = new Stock("AAPL", "Apple", new BigDecimal("150")); | ||
| Share share = new Share(stock, new BigDecimal("2"), new BigDecimal("100")); | ||
| SaleCalculator calculator = new SaleCalculator(share); | ||
|
|
||
| assertEquals(new BigDecimal("300"), calculator.calculateGross()); | ||
| } | ||
|
|
||
| @Test | ||
| void calculateCommissionReturnsOnePercentOfGross() { | ||
| Stock stock = new Stock("AAPL", "Apple", new BigDecimal("150")); | ||
| Share share = new Share(stock, new BigDecimal("2"), new BigDecimal("100")); | ||
| SaleCalculator calculator = new SaleCalculator(share); | ||
|
|
||
| assertEquals(new BigDecimal("3.00"), calculator.calculateCommission()); | ||
| } | ||
|
|
||
| @Test | ||
| void calculateTaxReturnsThirtyPercentOfProfitWhenProfitIsPositive() { | ||
| Stock stock = new Stock("AAPL", "Apple", new BigDecimal("150")); | ||
| Share share = new Share(stock, new BigDecimal("2"), new BigDecimal("100")); | ||
| SaleCalculator calculator = new SaleCalculator(share); | ||
|
|
||
| assertEquals(new BigDecimal("29.1000"), calculator.calculateTax()); | ||
| } | ||
|
|
||
| @Test | ||
| void calculateTaxReturnsZeroWhenProfitIsZeroOrNegative() { | ||
| Stock stock = new Stock("AAPL", "Apple", new BigDecimal("90")); | ||
| Share share = new Share(stock, new BigDecimal("2"), new BigDecimal("100")); | ||
| SaleCalculator calculator = new SaleCalculator(share); | ||
|
|
||
| assertEquals(BigDecimal.ZERO, calculator.calculateTax()); | ||
| } | ||
|
|
||
| @Test | ||
| void calculateTotalReturnsGrossMinusCommissionMinusTax() { | ||
| Stock stock = new Stock("AAPL", "Apple", new BigDecimal("150")); | ||
| Share share = new Share(stock, new BigDecimal("2"), new BigDecimal("100")); | ||
| SaleCalculator calculator = new SaleCalculator(share); | ||
|
|
||
| assertEquals(new BigDecimal("267.9000"), calculator.calculateTotal()); | ||
| } | ||
| } |