### Question:
AverageProfitableTradesCriterion extends AbstractAnalysisCriterion { @Override public Num calculate(BarSeries series, Trade trade) { return isProfitableTrade(series, trade) ? series.numOf(1) : series.numOf(0); }  @Override Num calculate(BarSeries series, Trade trade); @Override Num calculate(BarSeries series, TradingRecord tradingRecord); @Override boolean betterThan(Num criterionValue1, Num criterionValue2);  }### Answer:
@Test public void calculate() { BarSeries series = new MockBarSeries(numFunction, 100d, 95d, 102d, 105d, 97d, 113d); TradingRecord tradingRecord = new BaseTradingRecord(Order.buyAt(0, series), Order.sellAt(1, series), Order.buyAt(2, series), Order.sellAt(3, series), Order.buyAt(4, series), Order.sellAt(5, series)); AnalysisCriterion average = getCriterion(); assertNumEquals(2d / 3, average.calculate(series, tradingRecord)); }
@Test public void calculateWithOneTrade() { BarSeries series = new MockBarSeries(numFunction, 100d, 95d, 102d, 105d, 97d, 113d); Trade trade = new Trade(Order.buyAt(0, series), Order.sellAt(1, series)); AnalysisCriterion average = getCriterion(); assertNumEquals(numOf(0), average.calculate(series, trade)); trade = new Trade(Order.buyAt(1, series), Order.sellAt(2, series)); assertNumEquals(1, average.calculate(series, trade)); }