Skip to content

Commit ffe3cfd

Browse files
committed
#145 Add unit tests for BayesianAggregation in TradeRoutines
Introduced tests to validate correct functionality of BayesianAggregation, ensuring type correctness and expected outputs. Includes both positive cases with expected results and negative cases to handle invalid inputs gracefully.
1 parent 4f8dcf2 commit ffe3cfd

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/test_TradeRoutines.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,3 +1369,38 @@ def test_ZScoreNegative(self):
13691369

13701370
except Exception:
13711371
pass # Acceptable fallback on bad input
1372+
1373+
def test_BayesianAggregationCheckType(self):
1374+
result = TradeRoutines.BayesianAggregation(0.6, 0.7)
1375+
1376+
assert isinstance(result, float), "BayesianAggregation must return a float!"
1377+
1378+
def test_BayesianAggregationPositive(self):
1379+
testCases = [
1380+
(0.5, 0.5, 0.5),
1381+
(0.8, 0.9, (0.8 * 0.9) / (0.8 * 0.9 + 0.2 * 0.1)),
1382+
(0.0, 0.0, 0.0),
1383+
(1.0, 1.0, 1.0),
1384+
]
1385+
1386+
for p1, p2, expected in testCases:
1387+
result = TradeRoutines.BayesianAggregation(p1, p2)
1388+
1389+
assert abs(result - expected) < 1e-10, f"Incorrect result for {p1}, {p2}: {result}, expected: {expected}"
1390+
1391+
def test_BayesianAggregationNegative(self):
1392+
testCases = [
1393+
(1.2, 0.5),
1394+
(0.5, -0.1),
1395+
("bad", 0.5),
1396+
(None, 0.7),
1397+
]
1398+
1399+
for p1, p2 in testCases:
1400+
try:
1401+
result = TradeRoutines.BayesianAggregation(p1, p2)
1402+
1403+
assert 0.0 <= result <= 1.0, f"Result out of bounds: {result}"
1404+
1405+
except Exception:
1406+
pass # Acceptable on bad input

0 commit comments

Comments
 (0)