Last active
December 10, 2015 01:38
-
-
Save prystupa/4361266 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OrderBookSteps extends ShouldMatchers { | |
val orderTypes = OrderType.all() | |
val buyBook: OrderBook = new OrderBook(Buy, orderTypes) | |
val sellBook: OrderBook = new OrderBook(Sell, orderTypes) | |
@Given("^the following orders are added to the \"([^\"]*)\" book:$") | |
def the_following_orders_are_added_to_the_book(sideString: String, orderTable: DataTable) { | |
val (side, book) = getBook(sideString) | |
val orders = orderTable.asList[OrderRow](classOf[OrderRow]).toList.map( | |
r => LimitOrder(r.broker, side, r.qty, r.price.toDouble)) | |
orders.foreach(book.add) | |
} | |
@Then("^the \"([^\"]*)\" order book looks like:$") | |
def the_order_book_looks_like(sideString: String, bookTable: DataTable) { | |
val (_, book) = getBook(sideString) | |
val expectedBook = bookTable.asList[BookRow](classOf[BookRow]).toList | |
val actualBook = book.orders().map(o => BookRow(o.broker, o.qty, orderTypes(o).bookDisplay)) | |
actualBook should equal(expectedBook) | |
} | |
def getBook(side: String) = side match { | |
case "Buy" => (Buy, buyBook) | |
case "Sell" => (Sell, sellBook) | |
} | |
case class OrderRow(broker: String, qty: Double, price: String) | |
case class BookRow(broker: String, qty: Double, price: String) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment