-
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.
add test for profit value/pct calculation; pct adjustments
- Loading branch information
1 parent
4c8845c
commit 5513481
Showing
2 changed files
with
50 additions
and
4 deletions.
There are no files selected for viewing
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
44 changes: 44 additions & 0 deletions
44
hawk/src/test/java/io/irw/hawk/scraper/service/extractors/PriceExtractorTest.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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.irw.hawk.scraper.service.extractors; | ||
|
||
import static io.irw.hawk.scraper.service.extractors.PriceExtractor.calculateExpectedProfitPct; | ||
import static io.irw.hawk.scraper.service.extractors.PriceExtractor.calculateExpectedProfitUsd; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.math.BigDecimal; | ||
import org.assertj.core.data.Offset; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class PriceExtractorTest { | ||
|
||
public static final int LISTING_PRICE_PER_PIECE_USD = 5; | ||
public static final int SHIPPING_PRICE_PER_PIECE_USD = 1; | ||
public static final int MEEST_SH_OVERHEAD = 10; | ||
public static final int NUMBER_OF_PIECES = 8; | ||
public static final int USUAL_PRICE_PER_PIECE_USD = 9; | ||
public static final double DELTA = 0.01; | ||
|
||
@Test | ||
void shouldCalculateExpectedProfitUsd() { | ||
BigDecimal calculatedProfitUsd = calculateExpectedProfitUsd( | ||
BigDecimal.valueOf(LISTING_PRICE_PER_PIECE_USD + SHIPPING_PRICE_PER_PIECE_USD), | ||
BigDecimal.valueOf(USUAL_PRICE_PER_PIECE_USD), NUMBER_OF_PIECES, BigDecimal.valueOf(MEEST_SH_OVERHEAD)); | ||
double expectedProfitUsdValue = (USUAL_PRICE_PER_PIECE_USD * NUMBER_OF_PIECES | ||
- (LISTING_PRICE_PER_PIECE_USD + SHIPPING_PRICE_PER_PIECE_USD) * NUMBER_OF_PIECES) - MEEST_SH_OVERHEAD; | ||
assertThat(calculatedProfitUsd.doubleValue()).isEqualTo(expectedProfitUsdValue, Offset.offset(DELTA)); | ||
} | ||
|
||
@Test | ||
void shouldCalculateExpectedProfitPct() { | ||
double expectedProfitUsd = USUAL_PRICE_PER_PIECE_USD * NUMBER_OF_PIECES | ||
- (LISTING_PRICE_PER_PIECE_USD + SHIPPING_PRICE_PER_PIECE_USD) * NUMBER_OF_PIECES - MEEST_SH_OVERHEAD; | ||
BigDecimal calculatedProfitPct = calculateExpectedProfitPct(BigDecimal.valueOf(expectedProfitUsd), | ||
BigDecimal.valueOf(LISTING_PRICE_PER_PIECE_USD * NUMBER_OF_PIECES), | ||
BigDecimal.valueOf(SHIPPING_PRICE_PER_PIECE_USD * NUMBER_OF_PIECES), BigDecimal.valueOf(MEEST_SH_OVERHEAD)); | ||
|
||
double expectedProfitPercentValue = (expectedProfitUsd / | ||
((LISTING_PRICE_PER_PIECE_USD + SHIPPING_PRICE_PER_PIECE_USD) * NUMBER_OF_PIECES + MEEST_SH_OVERHEAD)) | ||
* 100; | ||
assertThat(calculatedProfitPct).matches(bigDecimal -> bigDecimal.compareTo(BigDecimal.ZERO) > 0); | ||
assertThat(calculatedProfitPct.doubleValue()).isEqualTo(expectedProfitPercentValue, Offset.offset(DELTA)); | ||
} | ||
} |