Files
Tirsvad cb8e5edfbf Implement store strategy, five-minute run loop and command line entry point
StoreItem and choose_upgrade, get_store_items, buy_upgrade, get_cps,
run_bot with a Clock port, main and python -m cookie_clicker_bot. 74
offline tests. Reviewed in RC-012.

Task: MIL-003#1
Task: MIL-003#2
Task: MIL-003#3
Task: MIL-003#4
Task: MIL-003#5
Task: MIL-003#6
Closes #13
Closes #14
Closes #15
Closes #16
Closes #17
Closes #18
2026-10-28 16:37:21 +08:00

73 lines
1.8 KiB
Python

"""@file
@brief Tests of parse_game_number.
"""
from decimal import Decimal
import pytest
from cookie_clicker_bot.domain.errors import UnreadableNumberError
from cookie_clicker_bot.domain.number_parsing import (
parse_game_decimal,
parse_game_number,
)
@pytest.mark.parametrize(
("text", "expected"),
[
("0", 0),
("1 cookie", 1),
("15 cookies", 15),
("12,345 cookies", 12345),
("1,234,567", 1234567),
],
)
def test_parse_plain_amounts(text: str, expected: int) -> None:
assert parse_game_number(text) == expected
@pytest.mark.parametrize(
("text", "expected"),
[
("1.234 million", 1_234_000),
("2 billion", 2_000_000_000),
("1.500 Thousand", 1500),
("3 decillion", 3 * 10**33),
],
)
def test_parse_amounts_with_number_word(text: str, expected: int) -> None:
assert parse_game_number(text) == expected
def test_parse_ignores_unknown_word_after_the_number() -> None:
assert parse_game_number("42 bakers") == 42
def test_parse_rounds_decimals() -> None:
assert parse_game_number("7.6 cookies") == 8
@pytest.mark.parametrize(
("text", "expected"),
[
("0.1", Decimal("0.1")),
("1,234.5", Decimal("1234.5")),
("1.234 million", Decimal("1234000")),
("7", Decimal(7)),
],
)
def test_parse_decimal_keeps_the_decimals(text: str, expected: Decimal) -> None:
assert parse_game_decimal(text) == expected
def test_parse_decimal_rejects_text_without_a_number() -> None:
with pytest.raises(UnreadableNumberError):
parse_game_decimal("none")
@pytest.mark.parametrize("text", ["", "cookies", "-5", "per second: 3"])
def test_parse_rejects_text_without_a_leading_number(text: str) -> None:
with pytest.raises(UnreadableNumberError):
parse_game_number(text)