Skip to content

Commit

Permalink
test: 포트폴리오 종목의 파이 차트 원소 계산 테스트 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
yonghwankim-dev committed Oct 18, 2024
1 parent 1bb6b84 commit 24c0988
Showing 1 changed file with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ void calTotalInvestment_givenPurchaseHistories_whenCalTotalInvestment_thenReturn

@DisplayName("종목과 매입이력들이 주어졌을때 연간 예상되는 배당금 합계를 계산한다")
@Test
void calAnnualExpectedDividend_givenStockAndPurchaseHistories_whenCalAnnualExpectedDividend_thenReturnSumOfDividend() {
void calAnnualExpectedDividend_givenStockAndPurchaseHistories_whenCalAnnualExpectedDividend_thenReturnSum() {
Portfolio portfolio = createPortfolio(createMember());
Stock stock = createSamsungStock();
long currentPrice = 50_000L;
Expand Down Expand Up @@ -1303,4 +1303,33 @@ void calMonthlyDividendMap() {
assertThat(actualArray[i]).isEqualByComparingTo(expectedArray[i]);
}
}

@DisplayName("포트폴리오 종목과 총 자산이 주어졌을때 하나의 파이 차트 요소를 계산한다")
@Test
void calPortfolioPieChartItemBy() {
// given
Portfolio portfolio = createPortfolio(createMember());
Stock stock = createSamsungStock();
long currentPrice = 50_000L;
currentPriceRepository.savePrice(stock, currentPrice);
createStockDividendWith(stock).forEach(stock::addStockDividend);
PortfolioHolding holding = createPortfolioHolding(portfolio, stock);
LocalDateTime purchaseDate = LocalDateTime.of(2023, 9, 26, 9, 30, 0);
PurchaseHistory history = createPurchaseHistory(null, purchaseDate, Count.from(3), Money.won(40000L),
"메모", holding);
holding.addPurchaseHistory(history);
portfolio.addHolding(holding);

Expression totalAsset = calculator.calTotalAssetBy(portfolio);
// when
PortfolioPieChartItem actual = calculator.calPortfolioPieChartItemBy(holding, totalAsset);
// then
PortfolioPieChartItem expected = PortfolioPieChartItem.stock(
stock.getCompanyName(),
Money.won(150_000),
RateDivision.of(Money.won(150_000), Money.won(1_030_000)).toPercentage(Bank.getInstance(), Currency.KRW),
Money.won(30_000),
RateDivision.of(Money.won(30_000), Money.won(120_000)).toPercentage(Bank.getInstance(), Currency.KRW));
assertThat(actual).isEqualTo(expected);
}
}

0 comments on commit 24c0988

Please sign in to comment.