### Question:
RewardRiskRatioCriterion extends AbstractAnalysisCriterion { @Override public Num calculate(BarSeries series, TradingRecord tradingRecord) { return totalProfit.calculate(series, tradingRecord).dividedBy(maxDrawdown.calculate(series, tradingRecord)); }  @Override Num calculate(BarSeries series, TradingRecord tradingRecord); @Override boolean betterThan(Num criterionValue1, Num criterionValue2); @Override Num calculate(BarSeries series, Trade trade);  }### Answer:
@Test public void rewardRiskRatioCriterion() { MockBarSeries series = new MockBarSeries(numFunction, 100, 105, 95, 100, 90, 95, 80, 120); TradingRecord tradingRecord = new BaseTradingRecord(Order.buyAt(0, series), Order.sellAt(1, series), Order.buyAt(2, series), Order.sellAt(4, series), Order.buyAt(5, series), Order.sellAt(7, series)); double totalProfit = (105d / 100) * (90d / 95d) * (120d / 95); double peak = (105d / 100) * (100d / 95); double low = (105d / 100) * (90d / 95) * (80d / 95); assertNumEquals(totalProfit / ((peak - low) / peak), rrc.calculate(series, tradingRecord)); }
@Test public void rewardRiskRatioCriterionOnlyWithGain() { MockBarSeries series = new MockBarSeries(numFunction, 1, 2, 3, 6, 8, 20, 3); TradingRecord tradingRecord = new BaseTradingRecord(Order.buyAt(0, series), Order.sellAt(1, series), Order.buyAt(2, series), Order.sellAt(5, series)); assertTrue(rrc.calculate(series, tradingRecord).isNaN()); }
@Test public void rewardRiskRatioCriterionWithNoTrades() { MockBarSeries series = new MockBarSeries(numFunction, 1, 2, 3, 6, 8, 20, 3); assertTrue(rrc.calculate(series, new BaseTradingRecord()).isNaN()); }
@Test public void withOneTrade() { MockBarSeries series = new MockBarSeries(numFunction, 100, 95, 95, 100, 90, 95, 80, 120); Trade trade = new Trade(Order.buyAt(0, series), Order.sellAt(1, series)); AnalysisCriterion ratioCriterion = getCriterion(); assertNumEquals((95d / 100) / ((1d - 0.95d)), ratioCriterion.calculate(series, trade)); }