### Question:
PriceMatchEmulator implements OrderFillEmulator { @Override public void fillOrder(Order order, Candle candle) { if (order.getType() == LIMIT) { if ((order.getSide() == BUY && order.getPrice() >= candle.low) || (order.getSide() == SELL && order.getPrice() <= candle.high)) { order.setStatus(Order.Status.FILLED); order.setExecutedQuantity(order.getQuantity()); double orderPrice = order.getPrice(); if (order.isBuy() && candle.high < orderPrice) { order.setAveragePrice(candle.high); } else if (order.isSell() && candle.low > orderPrice) { order.setAveragePrice(candle.low); } else { order.setAveragePrice(order.getPrice()); } order.setPartialFillDetails(order.getQuantity(), order.getAveragePrice()); } } else if (order.getType() == MARKET) { order.setStatus(Order.Status.FILLED); order.setExecutedQuantity(order.getQuantity()); if (order.getSide() == BUY) { order.setAveragePrice((candle.open + candle.close + candle.high) / 3.0); } else if (order.getSide() == SELL) { order.setAveragePrice((candle.open + candle.close + candle.low) / 3.0); } order.setPrice(order.getAveragePrice()); order.setPartialFillDetails(order.getQuantity(), order.getAveragePrice()); } }  @Override void fillOrder(Order order, Candle candle);  }### Answer:
@Test public void fillLimitSellOrders() { Order sell = newOrder(LIMIT, SELL, 1.0, 1.0); e.fillOrder(sell, new Candle(1, 1, 0.9, 0.9, 0.9, 0.9, 1.0)); assertEquals(NEW, sell.getStatus()); e.fillOrder(sell, new Candle(1, 1, 1.1, 1.1, 1.1, 1.1, 1.0)); assertEquals(FILLED, sell.getStatus()); assertEquals(1.1, sell.getAveragePrice(), 0.000001); }
@Test public void fillLimitBuyOrders(){ Order buy = newOrder(LIMIT, BUY, 1.0, 1.0); e.fillOrder(buy, new Candle(1, 1, 1.1, 1.1, 1.1, 1.1, 1.0)); assertEquals(NEW, buy.getStatus()); e.fillOrder(buy, new Candle(1, 1, 0.9, 0.9, 0.9, 0.9, 1.0)); assertEquals(FILLED, buy.getStatus()); assertEquals(0.9, buy.getAveragePrice(), 0.000001); }
@Test public void fillMarketSellOrders() { Order sell = newOrder(MARKET, SELL, 1.0, 1.0); e.fillOrder(sell, new Candle(1, 1, 0.9, 0.9, 0.9, 0.9, 1.0)); assertEquals(FILLED, sell.getStatus()); assertEquals(0.9, sell.getAveragePrice(), 0.000001); }
@Test public void fillMarketBuyOrders(){ Order buy = newOrder(MARKET, BUY, 1.0, 1.0); e.fillOrder(buy, new Candle(1, 1, 1.1, 1.1, 1.1, 1.1, 1.0)); assertEquals(FILLED, buy.getStatus()); assertEquals(1.1, buy.getAveragePrice(), 0.000001); }