-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
44 lines (37 loc) · 1.43 KB
/
test.py
File metadata and controls
44 lines (37 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import unittest
from lib import BUY, SELL, Exchange
class TestStringMethods(unittest.TestCase):
# def testRegister(self):
# e = Exchange()
# self.assertEqual(e.register("some"), {})
# def testTradeOneself(self):
# e = Exchange()
# e.register("a")
# e.put_order("A", BUY, 1.05, 1.0, "a")
# e.put_order("A", SELL, 0.95, 1.0, "a")
# book = e.books_summary()["A"]
# self.assertEqual(book["buy"], [])
# self.assertEqual(book["sell"], [])
# self.assertEqual(e.trade_history["A"][0][1:], (1.05, 1.0))
# def testNoTradeOneself(self):
# e = Exchange()
# e.register("a")
# e.put_order("A", BUY, 0.95, 1.0, "a")
# e.put_order("A", SELL, 1.05, 1.0, "a")
# self.assertEqual(e.trade_history, {"A": [], "B": [], "C": []})
def testTradeTwo(self):
e = Exchange()
e.register("a")
e.register("b")
e.put_order("A", BUY, 1.05, 1.0, "a")
e.put_order("A", SELL, 0.95, 1.0, "b")
book = e.books_summary()["A"]
account_a = e.account_summary("a")
account_b = e.account_summary("b")
self.assertEqual(book["buy"], [])
self.assertEqual(book["sell"], [])
self.assertEqual(e.trade_history["A"][0][1:], (1.05, 1.0))
self.assertEqual(account_a["A"], 101.0)
self.assertEqual(account_b["A"], 99.0)
if __name__ == "__main__":
unittest.main()