### Question:
BuyAndHoldCriterion extends AbstractAnalysisCriterion { @Override public double calculate(TimeSeries series, TradingRecord tradingRecord) { return series.getTick(series.getEnd()).getClosePrice().dividedBy(series.getTick(series.getBegin()).getClosePrice()).toDouble(); }  @Override double calculate(TimeSeries series, TradingRecord tradingRecord); @Override double calculate(TimeSeries series, Trade trade); @Override boolean betterThan(double criterionValue1, double criterionValue2);  }### Answer:
@Test public void calculateOnlyWithGainTrades() { MockTimeSeries series = new MockTimeSeries(100, 105, 110, 100, 95, 105); TradingRecord tradingRecord = new TradingRecord( Order.buyAt(0), Order.sellAt(2), Order.buyAt(3), Order.sellAt(5)); AnalysisCriterion buyAndHold = new BuyAndHoldCriterion(); assertEquals(1.05, buyAndHold.calculate(series, tradingRecord), TATestsUtils.TA_OFFSET); }
@Test public void calculateOnlyWithLossTrades() { MockTimeSeries series = new MockTimeSeries(100, 95, 100, 80, 85, 70); TradingRecord tradingRecord = new TradingRecord( Order.buyAt(0), Order.sellAt(1), Order.buyAt(2), Order.sellAt(5)); AnalysisCriterion buyAndHold = new BuyAndHoldCriterion(); assertEquals(0.7, buyAndHold.calculate(series, tradingRecord), TATestsUtils.TA_OFFSET); }
@Test public void calculateWithNoTrades() { MockTimeSeries series = new MockTimeSeries(100, 95, 100, 80, 85, 70); AnalysisCriterion buyAndHold = new BuyAndHoldCriterion(); assertEquals(0.7, buyAndHold.calculate(series, new TradingRecord()), TATestsUtils.TA_OFFSET); }
@Test public void calculateWithOneTrade() { MockTimeSeries series = new MockTimeSeries(100, 105); Trade trade = new Trade(Order.buyAt(0), Order.sellAt(1)); AnalysisCriterion buyAndHold = new BuyAndHoldCriterion(); assertEquals(105d/100, buyAndHold.calculate(series, trade), TATestsUtils.TA_OFFSET); }