-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f08d3bd
commit 56017ad
Showing
2 changed files
with
63 additions
and
48 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# -*- coding: utf-8 -*- | ||
# Author: Timur Gilmullin | ||
|
||
|
||
import pytest | ||
from tksbrokerapi import TradeRoutines | ||
|
||
|
||
class TestTKSBrokerAPIMethods: | ||
|
||
@pytest.fixture(scope="function", autouse=True) | ||
def init(self): | ||
pass | ||
|
||
def test_NanoToFloatCheckType(self): | ||
assert isinstance(TradeRoutines.NanoToFloat("123", 456789000), float), "Not float type returned!" | ||
assert isinstance(TradeRoutines.NanoToFloat("0", 0), float), "Not float type returned!" | ||
assert isinstance(TradeRoutines.NanoToFloat("-1", -1), float), "Not float type returned!" | ||
|
||
def test_NanoToFloatPositive(self): | ||
testData = [ | ||
("2", 500000000, 2.5), ("0", 50000000, 0.05), ("0", 0, 0.), | ||
("0", 100000000, 0.1), ("0", 1, 0.000000001), ("0", -100000000, -0.1), ("0", -1, -0.000000001), | ||
("-10", -100000000, -10.1), ("-10", -1, -10.000000001), ("1", 1, 1.000000001), ("-1", -9, -1.000000009), | ||
("-100", -10000000, -100.01), ("-100", -10, -100.00000001), ("10", 2, 10.000000002), ("-10", -8, -10.000000008), | ||
("-1000", -1000000, -1000.001), ("-1000", -100, -1000.0000001), ("100", 3, 100.000000003), ("-100", -7, -100.000000007), | ||
("-10000", -100000, -10000.0001), ("-10000", -1000, -10000.000001), ("1000", 4, 1000.000000004), ("-1000", -6, -1000.000000006), | ||
("-100000", -10000, -100000.00001), ("-100000", -10000, -100000.00001), ("10000", 5, 10000.000000005), ("-10000", -5, -10000.000000005), | ||
("-1000000", -1000, -1000000.000001), ("-1000000", -100000, -1000000.0001), ("100000", 6, 100000.000000006), ("-100000", -4, -100000.000000004), | ||
("-10000000", -100, -10000000.0000001), ("-10000000", -1000000, -10000000.001), ("1000000", 7, 1000000.000000007), ("-1000000", -3, -1000000.000000003), | ||
("-100000000", -10, -100000000.00000001), ("-100000000", -10000000, -100000000.01), ("10000000", 8, 10000000.000000008), ("-10000000", -2, -10000000.000000002), | ||
("-1000000000", -1, -1000000000.000000001), ("-1000000000", -100000000, -1000000000.1), ("100000000", 9, 100000000.000000009), ("-100000000", -1, -100000000.000000001), | ||
] | ||
|
||
for test in testData: | ||
result = TradeRoutines.NanoToFloat(units=test[0], nano=test[1]) | ||
assert result == test[2], 'Expected `NanoToFloat(units="{}", nano={}) == {}`, but `result == {}`'.format(test[0], test[1], test[2], result) | ||
|
||
def test_FloatToNanoCheckType(self): | ||
assert isinstance(TradeRoutines.FloatToNano(123.456789), dict), "Not dict type returned!" | ||
assert isinstance(TradeRoutines.FloatToNano(0.000000001), dict), "Not dict type returned!" | ||
assert isinstance(TradeRoutines.FloatToNano(-1.1), dict), "Not dict type returned!" | ||
|
||
def test_FloatToNanoPositive(self): | ||
testData = [ | ||
(2.5, {"units": "2", "nano": 500000000}), (0.05, {"units": "0", "nano": 50000000}), (0, {"units": "0", "nano": 0}), | ||
(1.9, {"units": "1", "nano": 900000000}), (1.000000009, {"units": "1", "nano": 9}), | ||
(-1.9, {"units": "-1", "nano": -900000000}), (-1.000000009, {"units": "-1", "nano": -9}), | ||
(0.1, {"units": "0", "nano": 100000000}), (-0.1, {"units": "0", "nano": -100000000}), | ||
(1.01, {"units": "1", "nano": 10000000}), (-1.01, {"units": "-1", "nano": -10000000}), | ||
(10.001, {"units": "10", "nano": 1000000}), (-10.001, {"units": "-10", "nano": -1000000}), | ||
(100.0001, {"units": "100", "nano": 100000}), (-100.0001, {"units": "-100", "nano": -100000}), | ||
(1000.00001, {"units": "1000", "nano": 10000}), (-1000.00001, {"units": "-1000", "nano": -10000}), | ||
(10000.000001, {"units": "10000", "nano": 1000}), (-10000.000001, {"units": "-10000", "nano": -1000}), | ||
(100000.0000001, {"units": "100000", "nano": 100}), (-100000.0000001, {"units": "-100000", "nano": -100}), | ||
(1000000.00000001, {"units": "1000000", "nano": 10}), (-1000000.00000001, {"units": "-1000000", "nano": -10}), | ||
(1.000000001, {"units": "1", "nano": 1}), (-1.000000001, {"units": "-1", "nano": -1}), | ||
(1.0000000001, {"units": "1", "nano": 0}), (-1.0000000001, {"units": "-1", "nano": 0}), | ||
] | ||
|
||
for test in testData: | ||
result = TradeRoutines.FloatToNano(number=test[0]) | ||
assert result == test[1], 'Expected `FloatToNano(number="{}") == {}`, but `result == {}`'.format(test[0], test[1], result) |