### Question:
LinearBorrowingCostModel implements CostModel { public Num calculate(Num price, Num amount) { return price.numOf(0); } LinearBorrowingCostModel(double feePerPeriod); Num calculate(Num price, Num amount); Num calculate(Trade trade); Num calculate(Trade trade, int currentIndex); boolean equals(CostModel otherModel);  }### Answer:
@Test public void calculateZeroTest() { Num price = DoubleNum.valueOf(100); Num amount = DoubleNum.valueOf(2); Num cost = borrowingModel.calculate(price, amount); assertNumEquals(DoubleNum.valueOf(0), cost); }
@Test public void calculateBuyTrade() { int holdingPeriod = 2; Order entry = Order.buyAt(0, DoubleNum.valueOf(100), DoubleNum.valueOf(1)); Order exit = Order.sellAt(holdingPeriod, DoubleNum.valueOf(110), DoubleNum.valueOf(1)); Trade trade = new Trade(entry, exit, new ZeroCostModel(), borrowingModel); Num costsFromTrade = trade.getHoldingCost(); Num costsFromModel = borrowingModel.calculate(trade, holdingPeriod); assertNumEquals(costsFromModel, costsFromTrade); assertNumEquals(costsFromModel, DoubleNum.valueOf(0)); }
@Test public void calculateSellTrade() { int holdingPeriod = 2; Order entry = Order.sellAt(0, DoubleNum.valueOf(100), DoubleNum.valueOf(1)); Order exit = Order.buyAt(holdingPeriod, DoubleNum.valueOf(110), DoubleNum.valueOf(1)); Trade trade = new Trade(entry, exit, new ZeroCostModel(), borrowingModel); Num costsFromTrade = trade.getHoldingCost(); Num costsFromModel = borrowingModel.calculate(trade, holdingPeriod); assertNumEquals(costsFromModel, costsFromTrade); assertNumEquals(costsFromModel, DoubleNum.valueOf(2)); }
@Test public void calculateOpenSellTrade() { int currentIndex = 4; Trade trade = new Trade(Order.OrderType.SELL, new ZeroCostModel(), borrowingModel); trade.operate(0, DoubleNum.valueOf(100), DoubleNum.valueOf(1)); Num costsFromTrade = trade.getHoldingCost(currentIndex); Num costsFromModel = borrowingModel.calculate(trade, currentIndex); assertNumEquals(costsFromModel, costsFromTrade); assertNumEquals(costsFromModel, DoubleNum.valueOf(4)); }