61 lines
1.4 KiB
Python
61 lines
1.4 KiB
Python
|
|
"""Unit tests for labor time algorithms."""
|
||
|
|
|
||
|
|
from app.labor_time_logic import (
|
||
|
|
apply_daily_limits,
|
||
|
|
normalize_time_value,
|
||
|
|
project_day_info,
|
||
|
|
sum_day_totals,
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
def test_normalize_time_quarters():
|
||
|
|
assert normalize_time_value(7.3) == 7.5
|
||
|
|
assert normalize_time_value(7.8) == 8.0
|
||
|
|
assert normalize_time_value(7.2) == 7.0
|
||
|
|
assert normalize_time_value(25.0) == 24.0
|
||
|
|
|
||
|
|
|
||
|
|
def test_apply_daily_limits_work_clamp():
|
||
|
|
time, limits = apply_daily_limits(
|
||
|
|
time=9.0,
|
||
|
|
is_over=False,
|
||
|
|
total_work=0.0,
|
||
|
|
total_over=0.0,
|
||
|
|
project_hours=0.0,
|
||
|
|
project_over=0.0,
|
||
|
|
max_work_hours=8.0,
|
||
|
|
max_over_hours=16.0,
|
||
|
|
)
|
||
|
|
assert time == 8.0
|
||
|
|
assert limits["clamped"] is True
|
||
|
|
|
||
|
|
|
||
|
|
def test_apply_daily_limits_replace_project_hours():
|
||
|
|
time, limits = apply_daily_limits(
|
||
|
|
time=6.0,
|
||
|
|
is_over=False,
|
||
|
|
total_work=8.0,
|
||
|
|
total_over=0.0,
|
||
|
|
project_hours=4.0,
|
||
|
|
project_over=0.0,
|
||
|
|
max_work_hours=8.0,
|
||
|
|
max_over_hours=16.0,
|
||
|
|
)
|
||
|
|
assert time == 4.0
|
||
|
|
assert limits["clamped"] is True
|
||
|
|
|
||
|
|
|
||
|
|
def test_sum_day_totals():
|
||
|
|
w, o = sum_day_totals(
|
||
|
|
[{"cc": 4, "is_over": 0}, {"cc": 2, "is_over": 1}]
|
||
|
|
)
|
||
|
|
assert w == 4.0
|
||
|
|
assert o == 2.0
|
||
|
|
|
||
|
|
|
||
|
|
def test_project_day_info():
|
||
|
|
info = project_day_info([{"cc": 3, "is_over": 0}, {"cc": 1, "is_over": 1}])
|
||
|
|
assert info["hours"] == 3.0
|
||
|
|
assert info["over"] == 1.0
|
||
|
|
assert info["total"] == 4.0
|