### Question:
LinearTransactionCostModel implements CostModel { public Num calculate(Trade trade, int currentIndex) { return this.calculate(trade); } LinearTransactionCostModel(double feePerTrade); Num calculate(Trade trade, int currentIndex); Num calculate(Trade trade); Num calculate(Num price, Num amount); boolean equals(CostModel otherModel);  }### Answer:
@Test public void calculateSingleOrderCost() { Num price = DoubleNum.valueOf(100); Num amount = DoubleNum.valueOf(2); Num cost = transactionModel.calculate(price, amount); assertNumEquals(DoubleNum.valueOf(2), cost); }
@Test public void calculateBuyTrade() { int holdingPeriod = 2; Order entry = Order.buyAt(0, DoubleNum.valueOf(100), DoubleNum.valueOf(1), transactionModel); Order exit = Order.sellAt(holdingPeriod, DoubleNum.valueOf(110), DoubleNum.valueOf(1), transactionModel); Trade trade = new Trade(entry, exit, transactionModel, new ZeroCostModel()); Num costFromBuy = entry.getCost(); Num costFromSell = exit.getCost(); Num costsFromModel = transactionModel.calculate(trade, holdingPeriod); assertNumEquals(costsFromModel, costFromBuy.plus(costFromSell)); assertNumEquals(costsFromModel, DoubleNum.valueOf(2.1)); assertNumEquals(costFromBuy, DoubleNum.valueOf(1)); }
@Test public void calculateSellTrade() { int holdingPeriod = 2; Order entry = Order.sellAt(0, DoubleNum.valueOf(100), DoubleNum.valueOf(1), transactionModel); Order exit = Order.buyAt(holdingPeriod, DoubleNum.valueOf(110), DoubleNum.valueOf(1), transactionModel); Trade trade = new Trade(entry, exit, transactionModel, new ZeroCostModel()); Num costFromBuy = entry.getCost(); Num costFromSell = exit.getCost(); Num costsFromModel = transactionModel.calculate(trade, holdingPeriod); assertNumEquals(costsFromModel, costFromBuy.plus(costFromSell)); assertNumEquals(costsFromModel, DoubleNum.valueOf(2.1)); assertNumEquals(costFromBuy, DoubleNum.valueOf(1)); }
@Test public void calculateOpenSellTrade() { int currentIndex = 4; Trade trade = new Trade(Order.OrderType.BUY, transactionModel, new ZeroCostModel()); trade.operate(0, DoubleNum.valueOf(100), DoubleNum.valueOf(1)); Num costsFromModel = transactionModel.calculate(trade, currentIndex); assertNumEquals(costsFromModel, DoubleNum.valueOf(1)); }