mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-24 20:46:28 +01:00
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
earned_time pre-commit / pre-commit (push) Waiting to run
earned_time tests / test (push) Waiting to run
file length / file-length (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
palette drift / palette (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
shared gate tests / gate unit tests (push) Waiting to run
From LADDER_FROM (2026-10-10) shutdown is read down from sleep: ceiling = WAKE_MINUTES (07:00) - 8h = 23:00, floor = ceiling - every earner's rung (workout 110, LeetCode 50, reading 30, Anki 25, Automation 25) = 19:00. A second workout earns nothing more. Earlier days resolve exactly as in 0.3.0 (frozen 23:00 ceiling); gaming is unchanged for every input. WORKOUT gets a signed ledger (~/.local/share/workout_locker/ledger.json, written by screen-locker) and workout_match; a rest_day row counts only if declared before its day began. New API: first_credit_at, credit_units, day_window, shutdown_minutes_for, extra_shutdown_minutes_for, shutdown_ceiling_for, on_ladder, LADDER/Rung, LADDER_FROM, WAKE_MINUTES. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QrjUTo1yhgAsUUasdw4bpG
98 lines
3.2 KiB
Python
98 lines
3.2 KiB
Python
# Copyright (c) 2026 Krzysztof Rudnicki
|
|
"""The one sum: base, terms, ceilings, and failing closed."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import UTC, date, datetime
|
|
import logging
|
|
|
|
import pytest
|
|
|
|
from earned_time import Earner, base_for, resolve
|
|
|
|
BEFORE_CUT = date(2026, 9, 30)
|
|
AFTER_CUT = date(2026, 10, 4)
|
|
|
|
|
|
def test_base_before_and_after_the_reading_cut() -> None:
|
|
assert base_for(BEFORE_CUT).gaming_minutes == 300
|
|
assert base_for(BEFORE_CUT).shutdown_minutes == 20 * 60
|
|
assert base_for(AFTER_CUT).gaming_minutes == 240
|
|
assert base_for(AFTER_CUT).shutdown_minutes == 19 * 60
|
|
|
|
|
|
def test_base_defaults_to_today() -> None:
|
|
today = datetime.now(tz=UTC).astimezone().date()
|
|
assert base_for() == base_for(today)
|
|
|
|
|
|
def test_nothing_earned_is_the_base() -> None:
|
|
day = resolve({"workout": 0, "leetcode": False, "reading": False}, AFTER_CUT)
|
|
assert (day.gaming_minutes, day.shutdown_minutes) == (240, 19 * 60)
|
|
|
|
|
|
def test_terms_add_up() -> None:
|
|
day = resolve({"workout": 1, "leetcode": True, "reading": False}, AFTER_CUT)
|
|
assert day.gaming_minutes == 240 + 120 + 60
|
|
assert day.shutdown_minutes == 19 * 60 + 120 + 60
|
|
assert day.term("reading").answer == 0
|
|
|
|
|
|
def test_ceilings_hold() -> None:
|
|
day = resolve({"workout": 5, "leetcode": True, "reading": True}, AFTER_CUT)
|
|
assert (day.gaming_minutes, day.shutdown_minutes) == (8 * 60, 23 * 60)
|
|
|
|
|
|
def test_unknown_answer_earns_nothing_but_is_kept() -> None:
|
|
day = resolve({"workout": None, "leetcode": True, "reading": True}, AFTER_CUT)
|
|
assert day.term("workout").answer is None
|
|
assert day.term("workout").gaming_minutes == 0
|
|
|
|
|
|
def test_negative_count_is_zero() -> None:
|
|
day = resolve({"workout": -3, "leetcode": False, "reading": False}, AFTER_CUT)
|
|
assert day.term("workout").answer == 0
|
|
|
|
|
|
def test_missing_answer_is_logged_and_earns_nothing(
|
|
caplog: pytest.LogCaptureFixture,
|
|
) -> None:
|
|
with caplog.at_level(logging.WARNING):
|
|
day = resolve({"leetcode": True}, AFTER_CUT)
|
|
assert "No answer for the workout earner" in caplog.text
|
|
assert day.term("workout").answer is None
|
|
|
|
|
|
def test_unregistered_name_raises() -> None:
|
|
with pytest.raises(KeyError, match="anky"):
|
|
resolve({"anky": True})
|
|
|
|
|
|
def test_term_lookup_unknown_raises() -> None:
|
|
with pytest.raises(KeyError):
|
|
resolve({}, AFTER_CUT).term("nope")
|
|
|
|
|
|
def test_new_penalised_earner_keeps_the_best_case() -> None:
|
|
# A hypothetical next earner on top of the real registry (reading and
|
|
# anki and automation already penalised by 2026-10-09, the last day
|
|
# before the shutdown ladder): 5h - 1h - 30m - 30m - 30m.
|
|
piano = Earner(
|
|
name="piano",
|
|
label="piano",
|
|
gaming_minutes=30,
|
|
shutdown_minutes=30,
|
|
penalty_from=date(2026, 10, 8),
|
|
)
|
|
from earned_time import EARNERS
|
|
|
|
earners = (*EARNERS, piano)
|
|
later = date(2026, 10, 9)
|
|
assert base_for(later, earners).gaming_minutes == 150
|
|
assert base_for(later, earners).shutdown_minutes == 17 * 60 + 30
|
|
others = {e.name: 0 for e in EARNERS}
|
|
skipped = resolve({**others, "piano": 0}, later, earners)
|
|
done = resolve({**others, "piano": 1}, later, earners)
|
|
assert done.gaming_minutes - skipped.gaming_minutes == 30
|
|
assert done.shutdown_minutes == 18 * 60
|