Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Commit

Permalink
test optomization
Browse files Browse the repository at this point in the history
  • Loading branch information
fou3fou3 committed Dec 29, 2023
1 parent 47ae014 commit 1959925
Showing 1 changed file with 21 additions and 40 deletions.
61 changes: 21 additions & 40 deletions test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ def test_utils(self):
#Test if bollinger_bands returns TypeError if given a non-numpy list type
self.assertRaises(TypeError, utils.algorithm_output, 'bollinger_bands', [1, 2, 3], backtest=True)

#Test backtest_module.py
#Test backtest_module.py, using backtest plot data is because theres no much diffirence (optomization)
def test_backtest(self):
prices, timestamps, _ = price.get_prices()
backtest_data = backtest_module.backtest('bollinger_bands', prices, timestamps)
backtest_plot_data = backtest_module.backtest('bollinger_bands', prices, timestamps, plot=True)
#Test back test data keys are correct and backtest data exsits
backtest_dict = {
'transactions': [],
Expand All @@ -43,10 +43,14 @@ def test_backtest(self):
'profit': 1,
'profit_percentage %': 1
}
self.assertIsNotNone(backtest_data)
self.assertCountEqual(backtest_dict.keys(), backtest_data.keys())

self.assertIsNotNone(backtest_plot_data)
self.assertCountEqual(backtest_dict.keys(), backtest_plot_data.keys())
#Test transactions keys are correct and and transactions exsits

backtest_plot = backtest_module.plot(backtest_plot_data)
self.assertIsNotNone(backtest_plot)

transactions_dict = {
'price': price,
'signal': 'signal',
Expand All @@ -56,52 +60,29 @@ def test_backtest(self):
'timestamp': 1
}

transactions = backtest_data['transactions'][0] #take the first transaction of transactions list
transactions = backtest_plot_data['transactions'][0] #take the first transaction of transactions list
self.assertIsNotNone(transactions_dict)
self.assertCountEqual(transactions_dict.keys(), transactions.keys())
#Test if algorithm is correct (using bollinger bands change whenever needed) and algorithm variable exsits
self.assertIsNotNone(backtest_data['algorithm'])
self.assertEqual('bollinger_bands', backtest_data['algorithm'])
self.assertIsNotNone(backtest_plot_data['algorithm'])
self.assertEqual('bollinger_bands', backtest_plot_data['algorithm'])
#Test if start_balance is greater than 0 and exsits
self.assertIsNotNone(backtest_data['start_balance'])
self.assertGreater(backtest_data['start_balance'], 0)
self.assertIsNotNone(backtest_plot_data['start_balance'])
self.assertGreater(backtest_plot_data['start_balance'], 0)
#Test if strength_to_usd is greater than 0 and exsits
self.assertIsNotNone(backtest_data['strength_to_usd'])
self.assertGreater(backtest_data['strength_to_usd'], 0)
self.assertIsNotNone(backtest_plot_data['strength_to_usd'])
self.assertGreater(backtest_plot_data['strength_to_usd'], 0)
#Test if all of these keys are inegers and exsits (raises error if nan)
self.assertTrue(type(backtest_data['balance']), int)
self.assertTrue(type(backtest_data['final_total']), int)
self.assertTrue(type(backtest_data['shares']), int)
self.assertTrue(type(backtest_data['profit']), int)
self.assertTrue(type(backtest_data['profit_percentage %']), int)

#Test backtest_plot function
def test_backtest_plot(self):
prices, timestamps, _ = price.get_prices()
backtest_plot_data = backtest_module.backtest('bollinger_bands', prices, timestamps, plot=True)
#Test back test data keys are correct and backtest data exsits
backtest_dict = {
'transactions': [],
'algorithm': 'bollinger_bands',
'balance': 1,
'start_balance': 1,
'final_total': 1,
'strength_to_usd': 1,
'shares': 1,
'profit': 1,
'profit_percentage %': 1
}
self.assertIsNotNone(backtest_plot_data)
self.assertCountEqual(backtest_dict.keys(), backtest_plot_data.keys())
#Test if backtest plot exsits and not raising any errors
backtest_plot = backtest_module.plot(backtest_plot_data)
self.assertIsNotNone(backtest_plot)
self.assertTrue(type(backtest_plot_data['balance']), int)
self.assertTrue(type(backtest_plot_data['final_total']), int)
self.assertTrue(type(backtest_plot_data['shares']), int)
self.assertTrue(type(backtest_plot_data['profit']), int)
self.assertTrue(type(backtest_plot_data['profit_percentage %']), int)

#Test app views
def test_views(self):
application = app.get_app()
app_client = application.test_client()
intervals = price.supported_intervals
intervals = price.cached_intervals
algorithms = utils.get_algorithms()
#Test backtest && backtest plot && plot views
for algorithm in algorithms:
Expand Down

0 comments on commit 1959925

Please sign in to comment.