From 24707a7c3f267047838c97f07e5ff52284f7be6a Mon Sep 17 00:00:00 2001 From: Joe Ferrer Date: Wed, 1 Mar 2023 00:10:28 +1100 Subject: [PATCH 1/3] Rename client and server files --- client.py => client3.py | 0 server.py => server3.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename client.py => client3.py (100%) rename server.py => server3.py (100%) diff --git a/client.py b/client3.py similarity index 100% rename from client.py rename to client3.py diff --git a/server.py b/server3.py similarity index 100% rename from server.py rename to server3.py From 879221fec2b863d37d5b493f02a530a8098ef6ef Mon Sep 17 00:00:00 2001 From: Joe Ferrer Date: Wed, 1 Mar 2023 00:11:51 +1100 Subject: [PATCH 2/3] Re-add sample unit test --- client_test.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 client_test.py diff --git a/client_test.py b/client_test.py new file mode 100644 index 00000000000..af2bf26b3cc --- /dev/null +++ b/client_test.py @@ -0,0 +1,25 @@ +import unittest +from client3 import getDataPoint + +class ClientTest(unittest.TestCase): + def test_getDataPoint_calculatePrice(self): + quotes = [ + {'top_ask': {'price': 121.2, 'size': 36}, 'timestamp': '2019-02-11 22:06:30.572453', 'top_bid': {'price': 120.48, 'size': 109}, 'id': '0.109974697771', 'stock': 'ABC'}, + {'top_ask': {'price': 121.68, 'size': 4}, 'timestamp': '2019-02-11 22:06:30.572453', 'top_bid': {'price': 117.87, 'size': 81}, 'id': '0.109974697771', 'stock': 'DEF'} + ] + """ ------------ Add the assertion below ------------ """ + + def test_getDataPoint_calculatePriceBidGreaterThanAsk(self): + quotes = [ + {'top_ask': {'price': 119.2, 'size': 36}, 'timestamp': '2019-02-11 22:06:30.572453', 'top_bid': {'price': 120.48, 'size': 109}, 'id': '0.109974697771', 'stock': 'ABC'}, + {'top_ask': {'price': 121.68, 'size': 4}, 'timestamp': '2019-02-11 22:06:30.572453', 'top_bid': {'price': 117.87, 'size': 81}, 'id': '0.109974697771', 'stock': 'DEF'} + ] + """ ------------ Add the assertion below ------------ """ + + + """ ------------ Add more unit tests ------------ """ + + + +if __name__ == '__main__': + unittest.main() From 42c0fbfd19d4df6626e02c599b3c52ac5e4ce2a7 Mon Sep 17 00:00:00 2001 From: Lakshya Kumar Singh <64345392+Lakshya-249@users.noreply.github.com> Date: Tue, 2 Jul 2024 20:21:31 +0530 Subject: [PATCH 3/3] commit --- 0001-Re-add-sample-unit-test.patch | 44 ++++++++++++++++++++++++++++ __pycache__/client3.cpython-311.pyc | Bin 0 -> 1955 bytes client3.py | 10 +++++-- client_test.py | 4 +++ 4 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 0001-Re-add-sample-unit-test.patch create mode 100644 __pycache__/client3.cpython-311.pyc diff --git a/0001-Re-add-sample-unit-test.patch b/0001-Re-add-sample-unit-test.patch new file mode 100644 index 00000000000..f682207a26d --- /dev/null +++ b/0001-Re-add-sample-unit-test.patch @@ -0,0 +1,44 @@ +From 879221fec2b863d37d5b493f02a530a8098ef6ef Mon Sep 17 00:00:00 2001 +From: Joe Ferrer +Date: Wed, 1 Mar 2023 00:11:51 +1100 +Subject: [PATCH] Re-add sample unit test + +--- + client_test.py | 25 +++++++++++++++++++++++++ + 1 file changed, 25 insertions(+) + create mode 100644 client_test.py + +diff --git a/client_test.py b/client_test.py +new file mode 100644 +index 0000000..af2bf26 +--- /dev/null ++++ b/client_test.py +@@ -0,0 +1,25 @@ ++import unittest ++from client3 import getDataPoint ++ ++class ClientTest(unittest.TestCase): ++ def test_getDataPoint_calculatePrice(self): ++ quotes = [ ++ {'top_ask': {'price': 121.2, 'size': 36}, 'timestamp': '2019-02-11 22:06:30.572453', 'top_bid': {'price': 120.48, 'size': 109}, 'id': '0.109974697771', 'stock': 'ABC'}, ++ {'top_ask': {'price': 121.68, 'size': 4}, 'timestamp': '2019-02-11 22:06:30.572453', 'top_bid': {'price': 117.87, 'size': 81}, 'id': '0.109974697771', 'stock': 'DEF'} ++ ] ++ """ ------------ Add the assertion below ------------ """ ++ ++ def test_getDataPoint_calculatePriceBidGreaterThanAsk(self): ++ quotes = [ ++ {'top_ask': {'price': 119.2, 'size': 36}, 'timestamp': '2019-02-11 22:06:30.572453', 'top_bid': {'price': 120.48, 'size': 109}, 'id': '0.109974697771', 'stock': 'ABC'}, ++ {'top_ask': {'price': 121.68, 'size': 4}, 'timestamp': '2019-02-11 22:06:30.572453', 'top_bid': {'price': 117.87, 'size': 81}, 'id': '0.109974697771', 'stock': 'DEF'} ++ ] ++ """ ------------ Add the assertion below ------------ """ ++ ++ ++ """ ------------ Add more unit tests ------------ """ ++ ++ ++ ++if __name__ == '__main__': ++ unittest.main() +-- +2.43.0.windows.1 + diff --git a/__pycache__/client3.cpython-311.pyc b/__pycache__/client3.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a79d0f0a61f3f0ae02e4defe9c5258d7209f7520 GIT binary patch literal 1955 zcmaJ>O>7fK6rS<^cpckG9FjnYTP;XwF(rQ>N*aZt5IYr>NE0ZCtX!;(cam&kd(G|| zgzHFF#lc7%TnPzFrBV)6O2q|LRpCe_PCa>%RjiRJMe2#0C3@o2H|sb~kjl=?+xKSP zeDnThehvmZ5PXMxca|L=LjN$K^#ymBH-BM-9v}^AIE9qvA1m0EJqo9J6kg*LLF4Zr zMbreKULtAYx`*vI|MVc@gV8~REx>sUqxtQZqUf8aiXZgQTA-ytxV4rIXtT35yZ2A{ z&91$2iw7LM);{miQq$8z=gusJQOUfp(CCK>a`Z_G4glZ_M2h0O}<@T5w?3 zLXbM!(iX)1u^W4)kQdQA9s|Z9rXD3HTQ$|uvts0g+IWaad zHhLpR%-iR5?d-Q3`o9p*8|Imty{mJZ~CWE=goHm6GjMB4-HEh$i1u zQ#oSEwjr;O3^7$3G-OS+)vTdsY?%s{Z6w#J*EX_=C0(OJ*3^@vDXZ4{YZmATrowW{ zQ0<67g&R4;CMJsw^}&WjQ{M-=P1b~jAWHxuv+wQInaTJSi_x*|Q8RJXvWR7+NyZ+JFB_)1LWb9}>Ey6=iwxUJbZ`Jxoo$j$(_gL}5 z|4i3|{gnYHcyx2x2@Dlub$@p`QdxW?RQ0NPmA@di3|Y_(*;tm{*dxnEGkL%loeEoRALYqD&z zSA$9rfJ+R?>;>^S4C@0RP3OIxN z3HBRl+L<#`DSc_gByg=Pn~F`D3JX_amli3WbF<`H%S_0qX_81#UWam`0${8ViW5|T zLenhjZJ~Gp#mEvk25KU$+LSkms!`FcLyL-Tj4YEq^KMm|5Nl+zH`c90x1gawLTrM0 z?*{L!G?j+yk|Lj*pTHcu$5sYtgToj%jw2i>`dO=^V9{-L)K_iwhKPJ8iURxusfZh* z7mqa1F6kBUU<2)v9>fPq`Ip>4l^fU&hDu+Thsr}0{Qa@}$L?OgcfEl+gc;nVC0q{; zmV56XuFO81dlf$UGJNvM>8De_PCXAk7heSb=z7uRoSLtlns>qrweZ5L@YR>$t4{b@ zEqu)hE!IMdC2?DtsfP|g#{0kq&Zhw~qor7V{OptPGvbU#YvWNTFj9(@Kdb1E`s(2$ zrP=c7yBFcQlwzgWvm9&Bb=Im2%1)1~)n@NmastU(AX#<$wiGN0rM1dLWny#o(dnNq oKKb<7&~Im*!RgxIw9`55Nat(P`KsF+1BgEiF=+5@huwVq2b|gHkpKVy literal 0 HcmV?d00001 diff --git a/client3.py b/client3.py index 3fc09b75f16..b4a4b2ca945 100644 --- a/client3.py +++ b/client3.py @@ -35,14 +35,16 @@ def getDataPoint(quote): stock = quote['stock'] bid_price = float(quote['top_bid']['price']) ask_price = float(quote['top_ask']['price']) - price = bid_price + price = (bid_price + ask_price)/2 return stock, bid_price, ask_price, price def getRatio(price_a, price_b): """ Get ratio of price_a and price_b """ """ ------------- Update this function ------------- """ - return 1 + if(price_b == 0): + return + return price_a/price_b # Main @@ -52,8 +54,10 @@ def getRatio(price_a, price_b): quotes = json.loads(urllib.request.urlopen(QUERY.format(random.random())).read()) """ ----------- Update to get the ratio --------------- """ + prices = {} for quote in quotes: stock, bid_price, ask_price, price = getDataPoint(quote) + prices[stock] = price print("Quoted %s at (bid:%s, ask:%s, price:%s)" % (stock, bid_price, ask_price, price)) - print("Ratio %s" % getRatio(price, price)) + print("Ratio %s" % getRatio(prices['ABC'], prices['DEF'])) diff --git a/client_test.py b/client_test.py index af2bf26b3cc..e93ec5eeedb 100644 --- a/client_test.py +++ b/client_test.py @@ -8,6 +8,8 @@ def test_getDataPoint_calculatePrice(self): {'top_ask': {'price': 121.68, 'size': 4}, 'timestamp': '2019-02-11 22:06:30.572453', 'top_bid': {'price': 117.87, 'size': 81}, 'id': '0.109974697771', 'stock': 'DEF'} ] """ ------------ Add the assertion below ------------ """ + for quote in quotes: + self.assertEqual(getDataPoint(quote),(quote['stock'],quote['top_bid']['price'],quote['top_ask']['price'],(quote['top_bid']['price']+quote['top_ask']['price'])/2)) def test_getDataPoint_calculatePriceBidGreaterThanAsk(self): quotes = [ @@ -15,6 +17,8 @@ def test_getDataPoint_calculatePriceBidGreaterThanAsk(self): {'top_ask': {'price': 121.68, 'size': 4}, 'timestamp': '2019-02-11 22:06:30.572453', 'top_bid': {'price': 117.87, 'size': 81}, 'id': '0.109974697771', 'stock': 'DEF'} ] """ ------------ Add the assertion below ------------ """ + for quote in quotes: + self.assertEqual(getDataPoint(quote),(quote['stock'],quote['top_bid']['price'],quote['top_ask']['price'],(quote['top_bid']['price']+quote['top_ask']['price'])/2)) """ ------------ Add more unit tests ------------ """