85 lines
3.7 KiB
Python
85 lines
3.7 KiB
Python
"""Tests for the `util` module."""
|
|
from dotenv import load_dotenv
|
|
import os
|
|
|
|
import pytest
|
|
import util.convert as uc
|
|
import util.drawing as ud
|
|
import util.scrape as sc
|
|
import util.odds as uo
|
|
|
|
load_dotenv()
|
|
|
|
|
|
def test_convert_string_to_integer() -> None:
|
|
"""Test string value conversion to integer."""
|
|
assert uc.convert_string_to_integer("0") == 0
|
|
assert uc.convert_string_to_integer("3.14") == 3
|
|
with pytest.raises(uc.InvalidStringException) as exc:
|
|
uc.convert_string_to_integer("a")
|
|
|
|
|
|
def test_get_next_draw_date_none() -> None:
|
|
"""Test when a game is not provided."""
|
|
assert not ud.get_next_draw_date(game=None)
|
|
|
|
|
|
def test_get_next_draw_date_minimum() -> None:
|
|
"""Test the next draw date returned for each game and when an invalid name is presented (None)"""
|
|
assert ud.get_next_draw_date(game="mega-millions")
|
|
assert ud.get_next_draw_date(game="powerball")
|
|
assert not ud.get_next_draw_date(game="something")
|
|
with pytest.raises(TypeError) as exc:
|
|
ud.get_next_draw_date()
|
|
|
|
|
|
def test_get_next_draw_date_specified_from_date() -> None:
|
|
"""Test drawing dates returned for each possible day of the week."""
|
|
assert ud.get_next_draw_date(game="mega-millions", from_date='02/15/2026') == '02/17/2026'
|
|
assert ud.get_next_draw_date(game="mega-millions", from_date='02/16/2026') == '02/17/2026'
|
|
assert ud.get_next_draw_date(game="mega-millions", from_date='02/17/2026') == '02/17/2026'
|
|
assert ud.get_next_draw_date(game="mega-millions", from_date='02/18/2026') == '02/20/2026'
|
|
assert ud.get_next_draw_date(game="mega-millions", from_date='02/19/2026') == '02/20/2026'
|
|
|
|
assert ud.get_next_draw_date(game='powerball', from_date='02/15/2026') == '02/16/2026'
|
|
assert ud.get_next_draw_date(game='powerball', from_date='02/16/2026') == '02/16/2026'
|
|
assert ud.get_next_draw_date(game='powerball', from_date='02/17/2026') == '02/18/2026'
|
|
assert ud.get_next_draw_date(game='powerball', from_date='02/18/2026') == '02/18/2026'
|
|
assert ud.get_next_draw_date(game='powerball', from_date='02/19/2026') == '02/21/2026'
|
|
assert ud.get_next_draw_date(game='powerball', from_date='02/20/2026') == '02/21/2026'
|
|
|
|
|
|
@pytest.mark.parametrize("game", ['powerball', 'mega-millions'])
|
|
def test_scrape_game_history(game) -> None:
|
|
"""Test scraping the powerball result page for 1996, 2020, and current year."""
|
|
scrape_data = sc.scrape_game_history(game, year=1996)
|
|
assert len(scrape_data) in [17, 104]
|
|
scrape_data = sc.scrape_game_history(game, year=2020)
|
|
assert len(scrape_data) in [104, 105]
|
|
scrape_data = sc.scrape_game_history(game)
|
|
assert len(scrape_data) in range(0, 105)
|
|
|
|
|
|
def test_calculate_odds() -> None:
|
|
"""The the odds calculation for a number of draws within a specific pool size"""
|
|
assert uo.calculate_odds(pool_size=49, draw_count=5) == 1906884
|
|
assert uo.calculate_odds(pool_size=18, draw_count=1) == 18
|
|
with pytest.raises(TypeError):
|
|
uo.calculate_odds()
|
|
with pytest.raises(ValueError) as exc:
|
|
uo.calculate_odds(pool_size=1, draw_count=2)
|
|
|
|
|
|
def test_get_odds_of_winning() -> None:
|
|
assert uo.get_odds_of_winning(
|
|
main_ball_draw_pool=49, main_ball_draw_count=5, game_ball_draw_pool=18, game_ball_draw_count=1
|
|
) == 'The odds of winning are 1 in 34,323,912'
|
|
with pytest.raises(TypeError) as exc:
|
|
uo.get_odds_of_winning()
|
|
with pytest.raises(ValueError) as exc:
|
|
uo.get_odds_of_winning(
|
|
main_ball_draw_pool=49, main_ball_draw_count= 50, game_ball_draw_pool=18, game_ball_draw_count=1)
|
|
assert uo.get_odds_of_winning(
|
|
main_ball_draw_pool=69, main_ball_draw_count=5, game_ball_draw_pool=26, game_ball_draw_count=1
|
|
) == 'The odds of winning are 1 in 292,201,338'
|