Skip to content

Commit

Permalink
test cases to check previous commits
Browse files Browse the repository at this point in the history
  • Loading branch information
Kautenja committed Feb 16, 2020
1 parent 5e573f9 commit f4bb67a
Showing 1 changed file with 140 additions and 15 deletions.
155 changes: 140 additions & 15 deletions limit_order_book/test/test_limit_order_book.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ def test(self):
self.assertEqual(0, book.size_buy())
self.assertEqual(0, book.size())

#
# MARK: limit
#

class ShouldPlaceSellLimitOrder(TestCase):
def test(self):
Expand All @@ -42,27 +45,23 @@ def test(self):
self.assertEqual(1, book.size())


class ShouldCancelSellLimitOrder(TestCase):
class ShouldPlaceSellLimitOrderByValue(TestCase):
def test(self):
book = limit_order_book.LimitOrderBook()
book.limit_sell(1, 100, 50)
self.assertTrue(book.has(1))
book.cancel(1)
self.assertFalse(book.has(1))
self.assertEqual(0, book.best_sell())
book.limit(False, 1, 100, 50)
self.assertEqual(50, book.best_sell())
self.assertEqual(0, book.best_buy())
self.assertEqual(0, book.best(False))
self.assertEqual(50, book.best(False))
self.assertEqual(0, book.best(True))
self.assertEqual(0, book.volume_sell())
self.assertEqual(0, book.volume_sell(100))
self.assertEqual(100, book.volume_sell())
self.assertEqual(100, book.volume_sell(50))
self.assertEqual(0, book.volume_buy())
self.assertEqual(0, book.volume_buy(100))
self.assertEqual(0, book.volume())
self.assertEqual(0, book.volume(100))
self.assertEqual(0, book.size_at(100))
self.assertEqual(0, book.size_sell())
self.assertEqual(100, book.volume())
self.assertEqual(100, book.volume(50))
self.assertEqual(1, book.size_at(50))
self.assertEqual(1, book.size_sell())
self.assertEqual(0, book.size_buy())
self.assertEqual(0, book.size())
self.assertEqual(1, book.size())


class ShouldPlaceBuyLimitOrder(TestCase):
Expand All @@ -85,6 +84,97 @@ def test(self):
self.assertEqual(1, book.size())


class ShouldPlaceBuyLimitOrderByValue(TestCase):
def test(self):
book = limit_order_book.LimitOrderBook()
book.limit(True, 1, 100, 50)
self.assertEqual(0, book.best_sell())
self.assertEqual(50, book.best_buy())
self.assertEqual(0, book.best(False))
self.assertEqual(50, book.best(True))
self.assertEqual(0, book.volume_sell())
self.assertEqual(0, book.volume_sell(50))
self.assertEqual(100, book.volume_buy())
self.assertEqual(100, book.volume_buy(50))
self.assertEqual(100, book.volume())
self.assertEqual(100, book.volume(50))
self.assertEqual(1, book.size_at(50))
self.assertEqual(0, book.size_sell())
self.assertEqual(1, book.size_buy())
self.assertEqual(1, book.size())

#
# MARK: limit match
#

class ShouldMatchSellLimitOrderWithIncomingBuy(TestCase):
def test(self):
book = limit_order_book.LimitOrderBook()
book.limit_sell(1, 100, 50)
book.limit_buy(2, 100, 50)
self.assertEqual(0, book.best_sell())
self.assertEqual(0, book.best_buy())
self.assertEqual(0, book.best(False))
self.assertEqual(0, book.best(True))
self.assertEqual(0, book.volume_sell())
self.assertEqual(0, book.volume_sell(50))
self.assertEqual(0, book.volume_buy())
self.assertEqual(0, book.volume_buy(50))
self.assertEqual(0, book.volume())
self.assertEqual(0, book.volume(50))
self.assertEqual(0, book.size_at(50))
self.assertEqual(0, book.size_sell())
self.assertEqual(0, book.size_buy())
self.assertEqual(0, book.size())


class ShouldMatchBuyLimitOrderWithIncomingSell(TestCase):
def test(self):
book = limit_order_book.LimitOrderBook()
book.limit_buy(1, 100, 50)
book.limit_sell(2, 100, 50)
self.assertEqual(0, book.best_sell())
self.assertEqual(0, book.best_buy())
self.assertEqual(0, book.best(False))
self.assertEqual(0, book.best(True))
self.assertEqual(0, book.volume_sell())
self.assertEqual(0, book.volume_sell(50))
self.assertEqual(0, book.volume_buy())
self.assertEqual(0, book.volume_buy(50))
self.assertEqual(0, book.volume())
self.assertEqual(0, book.volume(50))
self.assertEqual(0, book.size_at(50))
self.assertEqual(0, book.size_sell())
self.assertEqual(0, book.size_buy())
self.assertEqual(0, book.size())

#
# MARK: cancel
#

class ShouldCancelSellLimitOrder(TestCase):
def test(self):
book = limit_order_book.LimitOrderBook()
book.limit_sell(1, 100, 50)
self.assertTrue(book.has(1))
book.cancel(1)
self.assertFalse(book.has(1))
self.assertEqual(0, book.best_sell())
self.assertEqual(0, book.best_buy())
self.assertEqual(0, book.best(False))
self.assertEqual(0, book.best(True))
self.assertEqual(0, book.volume_sell())
self.assertEqual(0, book.volume_sell(100))
self.assertEqual(0, book.volume_buy())
self.assertEqual(0, book.volume_buy(100))
self.assertEqual(0, book.volume())
self.assertEqual(0, book.volume(100))
self.assertEqual(0, book.size_at(100))
self.assertEqual(0, book.size_sell())
self.assertEqual(0, book.size_buy())
self.assertEqual(0, book.size())


class ShouldCancelBuyLimitOrder(TestCase):
def test(self):
book = limit_order_book.LimitOrderBook()
Expand All @@ -107,6 +197,9 @@ def test(self):
self.assertEqual(0, book.size_buy())
self.assertEqual(0, book.size())

#
# MARK: market
#

class ShouldPlaceSellMarketOrderEmptyBook(TestCase):
def test(self):
Expand Down Expand Up @@ -189,6 +282,9 @@ def test(self):
self.assertEqual(0, book.size_buy())
self.assertEqual(1, book.size())

#
# MARK: clear
#

class ShouldClearSellLimitOrders(TestCase):
def test(self):
Expand Down Expand Up @@ -217,3 +313,32 @@ def test(self):
self.assertEqual(0, book.size_sell())
self.assertEqual(0, book.size_buy())
self.assertEqual(0, book.size())


class ShouldClearBuyLimitOrders(TestCase):
def test(self):
book = limit_order_book.LimitOrderBook()
book.limit_sell(1, 100, 50)
book.limit_sell(2, 100, 50)
book.limit_sell(3, 100, 50)
self.assertTrue(book.has(1))
self.assertTrue(book.has(2))
self.assertTrue(book.has(3))
book.clear()
self.assertFalse(book.has(1))
self.assertFalse(book.has(2))
self.assertFalse(book.has(3))
self.assertEqual(0, book.best_sell())
self.assertEqual(0, book.best_buy())
self.assertEqual(0, book.best(False))
self.assertEqual(0, book.best(True))
self.assertEqual(0, book.volume_sell())
self.assertEqual(0, book.volume_sell(100))
self.assertEqual(0, book.volume_buy())
self.assertEqual(0, book.volume_buy(100))
self.assertEqual(0, book.volume())
self.assertEqual(0, book.volume(100))
self.assertEqual(0, book.size_at(100))
self.assertEqual(0, book.size_sell())
self.assertEqual(0, book.size_buy())
self.assertEqual(0, book.size())

0 comments on commit f4bb67a

Please sign in to comment.