Spaces:
Paused
Paused
| """Tests for reward and final score computation.""" | |
| import pytest | |
| from hr_env.server.scoring import compute_final_score, compute_quarterly_reward | |
| class TestQuarterlyReward: | |
| def test_positive_for_improvement(self): | |
| prev = {"hcva": 100, "hcroi": 1.5, "qips": {"composite": 0.6}, "five_indexes": {"cost": -0.05, "quality": 0.1, "human_reactions": 0.05, "quantity": 0.02}} | |
| curr = {"hcva": 110, "hcroi": 1.6, "qips": {"composite": 0.65}, "five_indexes": {"cost": -0.03, "quality": 0.12, "human_reactions": 0.08, "quantity": 0.03}} | |
| reward = compute_quarterly_reward(curr, prev) | |
| assert reward > 0, f"Reward should be positive for improvement, got {reward}" | |
| def test_negative_for_decline(self): | |
| prev = {"hcva": 110, "hcroi": 1.6, "qips": {"composite": 0.65}, "five_indexes": {"cost": 0.0, "quality": 0.0, "human_reactions": 0.0, "quantity": 0.0}} | |
| curr = {"hcva": 90, "hcroi": 1.3, "qips": {"composite": 0.55}, "five_indexes": {"cost": 0.1, "quality": -0.1, "human_reactions": -0.1, "quantity": -0.05}} | |
| reward = compute_quarterly_reward(curr, prev) | |
| assert reward < 0, f"Reward should be negative for decline, got {reward}" | |
| def test_near_zero_for_no_change(self): | |
| metrics = {"hcva": 100, "hcroi": 1.5, "qips": {"composite": 0.6}, "five_indexes": {"cost": 0.0, "quality": 0.0, "human_reactions": 0.0, "quantity": 0.0}} | |
| reward = compute_quarterly_reward(metrics, metrics) | |
| assert abs(reward) < 0.1, f"Reward should be near zero, got {reward}" | |
| class TestFinalScore: | |
| def test_bounded_zero_one(self): | |
| history = [ | |
| {"hcva": 100, "hcroi": 1.5, "qips": {"composite": 0.6}, "five_indexes": {"cost": 0, "quality": 0, "human_reactions": 0}, "employee_value": 0.5, "profit": 1000000}, | |
| {"hcva": 105, "hcroi": 1.55, "qips": {"composite": 0.62}, "five_indexes": {"cost": -0.02, "quality": 0.05, "human_reactions": 0.03}, "employee_value": 0.52, "profit": 1100000}, | |
| {"hcva": 110, "hcroi": 1.6, "qips": {"composite": 0.64}, "five_indexes": {"cost": -0.01, "quality": 0.03, "human_reactions": 0.02}, "employee_value": 0.55, "profit": 1200000}, | |
| ] | |
| score = compute_final_score(history) | |
| assert 0 <= score <= 1.0, f"Score {score} out of [0, 1] range" | |
| def test_higher_for_improvement_trajectory(self): | |
| improving = [ | |
| {"hcva": 100, "hcroi": 1.5, "qips": {"composite": 0.5}, "five_indexes": {"cost": 0, "quality": 0, "human_reactions": 0}, "employee_value": 0.4, "profit": 500000}, | |
| {"hcva": 120, "hcroi": 1.7, "qips": {"composite": 0.6}, "five_indexes": {"cost": -0.05, "quality": 0.1, "human_reactions": 0.1}, "employee_value": 0.5, "profit": 700000}, | |
| {"hcva": 140, "hcroi": 1.9, "qips": {"composite": 0.7}, "five_indexes": {"cost": -0.03, "quality": 0.08, "human_reactions": 0.05}, "employee_value": 0.6, "profit": 900000}, | |
| ] | |
| declining = [ | |
| {"hcva": 140, "hcroi": 1.9, "qips": {"composite": 0.7}, "five_indexes": {"cost": 0, "quality": 0, "human_reactions": 0}, "employee_value": 0.6, "profit": 900000}, | |
| {"hcva": 120, "hcroi": 1.5, "qips": {"composite": 0.55}, "five_indexes": {"cost": 0.1, "quality": -0.1, "human_reactions": -0.1}, "employee_value": 0.45, "profit": 500000}, | |
| {"hcva": 100, "hcroi": 1.2, "qips": {"composite": 0.4}, "five_indexes": {"cost": 0.15, "quality": -0.15, "human_reactions": -0.12}, "employee_value": 0.35, "profit": 200000}, | |
| ] | |
| score_improving = compute_final_score(improving) | |
| score_declining = compute_final_score(declining) | |
| assert score_improving > score_declining | |
| def test_empty_history(self): | |
| score = compute_final_score([]) | |
| assert score == 0.0 | |
| def test_single_quarter(self): | |
| score = compute_final_score([{"hcva": 100}]) | |
| assert score == 0.0 | |
| def test_profitable_scores_higher(self): | |
| profitable = [ | |
| {"hcva": 100, "hcroi": 1.5, "qips": {"composite": 0.6}, "five_indexes": {"cost": 0, "quality": 0, "human_reactions": 0}, "employee_value": 0.5, "profit": 1000000}, | |
| {"hcva": 100, "hcroi": 1.5, "qips": {"composite": 0.6}, "five_indexes": {"cost": 0, "quality": 0, "human_reactions": 0}, "employee_value": 0.5, "profit": 1000000}, | |
| ] | |
| unprofitable = [ | |
| {"hcva": 100, "hcroi": 1.5, "qips": {"composite": 0.6}, "five_indexes": {"cost": 0, "quality": 0, "human_reactions": 0}, "employee_value": 0.5, "profit": -500000}, | |
| {"hcva": 100, "hcroi": 1.5, "qips": {"composite": 0.6}, "five_indexes": {"cost": 0, "quality": 0, "human_reactions": 0}, "employee_value": 0.5, "profit": -500000}, | |
| ] | |
| assert compute_final_score(profitable) > compute_final_score(unprofitable) | |