From 216bc91d1aba4888e12a4d9a932612bf856811b2 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 26 May 2026 19:21:28 -0400 Subject: [PATCH] Add new, update existing and remove unneeded tests --- tests/lottery_predictor/test_analyze.py | 81 +++++++++++++++++-------- tests/lottery_predictor/test_collect.py | 24 ++++---- tests/util/test_util.py | 8 +-- 3 files changed, 70 insertions(+), 43 deletions(-) diff --git a/tests/lottery_predictor/test_analyze.py b/tests/lottery_predictor/test_analyze.py index 1b1a1c6..1d0177e 100755 --- a/tests/lottery_predictor/test_analyze.py +++ b/tests/lottery_predictor/test_analyze.py @@ -1,19 +1,52 @@ from datetime import datetime import pytest +import numpy as np + import lottery_predictor.analyze as analyze -def test_load_dataframe() -> None: +def test_load_dataframe_by_date() -> None: pb_start = datetime(2015, 10, 4) mm_start = datetime(2025, 4, 5) date_end = datetime(2026, 3, 8) - assert int(analyze.load_dataframe( - table_name='PowerballDraw', start_date=pb_start, end_date=date_end).count()['draw_date']) >= 1324 - assert int(analyze.load_dataframe( - table_name='MegaMillionsDraw', start_date=mm_start, end_date=date_end).count()['draw_date']) >= 96 + assert int(analyze.load_dataframe_by_dates( + game='Powerball', start_date=pb_start, end_date=date_end).count()['draw_date']) >= 1324 + assert int(analyze.load_dataframe_by_dates( + game='MegaMillions', start_date=mm_start, end_date=date_end).count()['draw_date']) >= 96 + with pytest.raises(KeyError): + analyze.load_dataframe_by_dates(game='SomeNonExistentGameName') + + +def test_load_dataframe_most_recent() -> None: + assert len(analyze.load_dataframe_most_recent(game='Powerball')) == 10 + assert len(analyze.load_dataframe_most_recent(game='MegaMillions')) == 10 + assert len(analyze.load_dataframe_most_recent(game='Powerball', limit=105)) == 105 + assert len(analyze.load_dataframe_most_recent(game='MegaMillions', limit=45)) == 45 with pytest.raises(ValueError): - analyze.load_dataframe(table_name='SomNonExistentTableName') + analyze.load_dataframe_most_recent(game='Powerball', limit=-1) + analyze.load_dataframe_most_recent(game='DoesntExist') + + +def test_prepare_split_data() -> None: + mm_start = datetime(2025, 4, 5) + date_end = datetime(2026, 3, 8) + mega = analyze.load_dataframe_by_dates(game='MegaMillions', start_date=mm_start, end_date=date_end) + + x, y1, y2 = analyze.prepare_split_data(data=mega.values, window_size=len(mega) - 1) + assert isinstance(x, np.ndarray) + assert isinstance(y1, np.ndarray) + assert isinstance(y2, np.ndarray) + + +def test_make_prediction() -> None: + pb_start = datetime(2015, 10, 4) + date_end = datetime(2026, 3, 8) + power = analyze.load_dataframe_by_dates(game='Powerball', start_date=pb_start, end_date=date_end) + + main, game = analyze.make_prediction(data_frame=power, window_size=10) + assert isinstance(main, np.ndarray) + assert isinstance(game, np.int64) def test_least_and_most_common_number() -> None: @@ -21,20 +54,20 @@ def test_least_and_most_common_number() -> None: mm_start = datetime(2025, 4, 5) date_end = datetime(2026, 3, 8) - pb_df = analyze.load_dataframe( - table_name='PowerballDraw', start_date=pb_start, end_date=date_end) - mm_df = analyze.load_dataframe( - table_name='MegaMillionsDraw', start_date=mm_start, end_date=date_end) + pb_df = analyze.load_dataframe_by_dates( + game='Powerball', start_date=pb_start, end_date=date_end) + mm_df = analyze.load_dataframe_by_dates( + game='MegaMillions', start_date=mm_start, end_date=date_end) - assert analyze.get_most_common_number(pb_df, top=5) == [61, 21, 28, 23, 33] - assert analyze.get_least_common_number(pb_df, bottom=5) == [13, 49, 46, 26, 34] - assert analyze.get_most_common_number(mm_df, top=5) == [42, 40, 18, 10, 49] - assert analyze.get_least_common_number(mm_df, bottom=5) == [35, 51, 3, 1, 20] + assert analyze.get_most_common_number(pb_df, top=5) == [61, 21, 23, 28, 33] + assert analyze.get_least_common_number(pb_df, bottom=5) == [13, 49, 26, 46, 34] + assert analyze.get_most_common_number(mm_df, top=5) == [42, 18, 40, 49, 10] + assert analyze.get_least_common_number(mm_df, bottom=5) == [35, 51, 61, 1, 20] assert analyze.get_most_common_number(pb_df, columns=['powerball'], top=1) == [4] assert analyze.get_least_common_number(pb_df, columns=['powerball'], bottom=1) == [16] - assert analyze.get_most_common_number(mm_df, columns=['mega_ball'], top=1) == [1] - assert analyze.get_least_common_number(mm_df, columns=['mega_ball'], bottom=1) == [3] + assert analyze.get_most_common_number(mm_df, columns=['mega_ball'], top=1) == [24] + assert analyze.get_least_common_number(mm_df, columns=['mega_ball'], bottom=1) == [20] def test_calculate_probabilities() -> None: @@ -43,12 +76,12 @@ def test_calculate_probabilities() -> None: mm_start = datetime(2025, 4, 5) date_end = datetime(2026, 3, 8) - pb_df = analyze.load_dataframe( - table_name='PowerballDraw', start_date=pb_start, end_date=date_end) + pb_df = analyze.load_dataframe_by_dates( + game='Powerball', start_date=pb_start, end_date=date_end) pb_probabilities = analyze.calculate_probabilities(data_frame=pb_df, max_number=69) - mm_df = analyze.load_dataframe( - table_name='MegaMillionsDraw', start_date=mm_start, end_date=date_end) + mm_df = analyze.load_dataframe_by_dates( + game='MegaMillions', start_date=mm_start, end_date=date_end) mm_probabilities = analyze.calculate_probabilities(data_frame=mm_df, max_number=70) assert pb_probabilities[1] == 0.3142857142857143 @@ -61,11 +94,11 @@ def test_hot_cold_numbers() -> None: mm_start = datetime(2025, 4, 5) date_end = datetime(2026, 3, 8) - pb_df = analyze.load_dataframe( - table_name='PowerballDraw', start_date=pb_start, end_date=date_end) + pb_df = analyze.load_dataframe_by_dates( + game='Powerball', start_date=pb_start, end_date=date_end) pb_probs = analyze.calculate_probabilities(data_frame=pb_df, max_number=69) - mm_df = analyze.load_dataframe( - table_name='MegaMillionsDraw', start_date=mm_start, end_date=date_end) + mm_df = analyze.load_dataframe_by_dates( + game='MegaMillions', start_date=mm_start, end_date=date_end) mm_probs = analyze.calculate_probabilities(data_frame=mm_df, max_number=70) assert (analyze.get_hot_numbers(probabilities=pb_probs) == diff --git a/tests/lottery_predictor/test_collect.py b/tests/lottery_predictor/test_collect.py index 32cf098..c5c2afe 100644 --- a/tests/lottery_predictor/test_collect.py +++ b/tests/lottery_predictor/test_collect.py @@ -5,21 +5,21 @@ import lottery_predictor.collect as collect def test_get_record_count() -> None: - assert isinstance(collect.get_record_count(table_name='PowerballDraw'), int) - assert isinstance(collect.get_record_count(table_name='MegaMillionsDraw'), int) - with pytest.raises(ValueError): - collect.get_record_count(table_name='SomeNonExistentTable') + assert isinstance(collect.get_record_count(game='Powerball'), int) + assert isinstance(collect.get_record_count(game='MegaMillions'), int) + with pytest.raises(KeyError): + collect.get_record_count(game='SomeNonExistentTable') def test_get_recent_draw_date() -> None: - assert isinstance(collect.get_recent_draw_date(table_name='PowerballDraw'), datetime.date) - assert isinstance(collect.get_recent_draw_date(table_name='MegaMillionsDraw'), datetime.date) - with pytest.raises(ValueError): - collect.get_recent_draw_date(table_name='SomeNonExistentTable') + assert isinstance(collect.get_recent_draw_date(game='Powerball'), datetime.date) + assert isinstance(collect.get_recent_draw_date(game='MegaMillions'), datetime.date) + with pytest.raises(KeyError): + collect.get_recent_draw_date(game='SomeNonExistentTable') def test_get_missing_records() -> None: - assert isinstance(collect.get_missing_records(table_name='PowerballDraw'), int) - assert isinstance(collect.get_missing_records(table_name='MegaMillionsDraw'), int) - with pytest.raises(ValueError): - collect.get_missing_records(table_name='SomeNonExistentTable') + assert isinstance(collect.get_missing_records(game='Powerball'), int) + assert isinstance(collect.get_missing_records(game='MegaMillions'), int) + with pytest.raises(KeyError): + collect.get_missing_records(game='SomeNonExistentTable') diff --git a/tests/util/test_util.py b/tests/util/test_util.py index 9947be9..30945f4 100755 --- a/tests/util/test_util.py +++ b/tests/util/test_util.py @@ -12,12 +12,6 @@ import util.odds as uo from data.database import PowerballDraw, MegaMillionsDraw -def test_check_table_name() -> None: - assert isinstance(ud.check_table_name('PowerballDraw'), dict) - assert isinstance(ud.check_table_name('MegaMillionsDraw'), dict) - assert ud.check_table_name('SomeNonExistentTableName') is None - - def test_convert_string_to_integer() -> None: """Test string value conversion to integer.""" assert uc.convert_string_to_integer("0") == 0 @@ -144,4 +138,4 @@ def test_load_environment_variables() -> None: """test loading environment variables for script use""" env_vars = ue.load_environment_variables() assert type(env_vars) == dict - assert len(env_vars) == 25 + assert isinstance(len(env_vars), int)