Files
o2o-weather/backend/tests/test_outing_score_table.py

59 lines
3.1 KiB
Python

from common.enums import RainType, Sky
from services.calc.index_calc import Hour, Outing, outing
from services.weekend_rank import OUTING_SCORE_TABLE, TRIP_MIN_SCORE, calibrated_outing, outing_day_score
def test_table_is_a_monotonic_0_to_100_lookup():
assert len(OUTING_SCORE_TABLE) == 101
assert all(0 <= v <= 100 for v in OUTING_SCORE_TABLE)
assert all(a <= b for a, b in zip(OUTING_SCORE_TABLE, OUTING_SCORE_TABLE[1:]))
assert OUTING_SCORE_TABLE[0] < OUTING_SCORE_TABLE[100] == 100
def test_table_makes_top_scores_rare_and_centers_60():
"""원래 점수가 높을수록 표시 점수가 오르되, 90점 이상으로 가는 원래 점수는 위쪽 일부뿐."""
assert any(55 <= v <= 65 for v in OUTING_SCORE_TABLE)
assert sum(v >= 90 for v in OUTING_SCORE_TABLE) <= 15
# 맑고 알맞은 날(원래 100)과 조금 못 미치는 날(원래 97)이 모두 100점으로 몰리지 않는다
assert calibrated_outing(95) < 100
def test_calibrated_outing_reads_the_table():
assert calibrated_outing(70) == OUTING_SCORE_TABLE[70]
assert calibrated_outing(0) == OUTING_SCORE_TABLE[0]
def test_day_score_uses_calibrated_value_for_hourly_and_estimated_results():
for estimated in (False, True):
r = Outing(score=80, factors={}, notes={}, reason="비 0% · 체감 21° · 맑음", estimated=estimated)
assert outing_day_score(r) == OUTING_SCORE_TABLE[80]
def test_trip_min_score_keeps_the_same_weather_quality():
"""당일치기 최소 기준은 원래 점수 50과 같은 날씨 수준을 표시 점수로 옮긴 값."""
assert TRIP_MIN_SCORE == calibrated_outing(50)
# 표는 가까운 원래 점수끼리 같은 값이 될 수 있어, 눈에 띄게 낮은 날은 빠지고 높은 날은 들어가는지만 본다
assert calibrated_outing(45) < TRIP_MIN_SCORE <= calibrated_outing(55)
def _day(feels: float = 21.0, wind: float = 0.5, prob: int = 0, sky: Sky = Sky.CLEAR) -> list[Hour]:
return [Hour(hour=h, feels_c=feels, rain_type=RainType.NONE, rain_prob=prob, wind_ms=wind, humidity=50, sky=sky) for h in range(10, 18)]
def test_outing_100_needs_exact_temperature_and_very_calm_wind():
"""맑고 비 없는 날도 체감 21° 근처(±0.5°)·바람 초속 1m 이하여야 100점. 그래야 같은 예보의 여러 지역이 한꺼번에 100점이 되지 않는다."""
assert outing(_day()).score == 100
assert outing(_day(feels=21.4)).factors["temp"] == 100
assert outing(_day(feels=22.3)).factors["temp"] < 100
assert outing(_day(wind=1.0)).factors["wind"] == 100
assert outing(_day(wind=1.8)).factors["wind"] < 95
assert outing(_day(wind=1.2)).score > outing(_day(wind=1.8)).score > outing(_day(wind=2.0)).score
def test_100_only_for_a_perfect_original_score_and_top_scores_stay_distinct():
"""맨 위가 100으로 잘려 원래 96·97·99가 모두 100점이 되던 것을 막는다: 100점은 원래 100뿐, 그 아래는 서로 다른 점수."""
assert OUTING_SCORE_TABLE[100] == 100
assert OUTING_SCORE_TABLE[99] < 100
top = OUTING_SCORE_TABLE[90:]
assert all(a < b for a, b in zip(top, top[1:]))