"""Tests for report logic — topic weakness, leaderboard scoring, completion.""" class TestLeaderboardScoring: """Leaderboard rewards mastery, improvement, and consistency — not speed.""" def test_mastery_weight(self): mastery = 90.0 improvement = 10.0 consistency = 5.0 # Weighted: mastery 40%, improvement 30%, consistency 30% score = mastery * 0.4 + improvement * 0.3 + consistency * 0.3 assert score == 40.5 def test_speed_not_primary_factor(self): """Speed should not be the primary ranking driver.""" # Score formula does not include speed score_components = ["mastery", "improvement", "consistency"] assert "speed" not in score_components def test_high_mastery_high_score(self): score1 = 95 * 0.4 + 5 * 0.3 + 3 * 0.3 # 41.4 score2 = 60 * 0.4 + 20 * 0.3 + 10 * 0.3 # 33.0 assert score1 > score2, "Higher mastery should rank higher" def test_improvement_bonus(self): """Someone who improves from 50% to 90% should get improvement points.""" first_score = 50.0 latest_score = 90.0 improvement_delta = latest_score - first_score assert improvement_delta > 0 improvement_points = improvement_delta * 0.3 assert improvement_points > 0 class TestTopicWeaknessReport: """Topic weakness report logic.""" def test_group_by_topic(self): answers = [ {"topic": "solar_panels", "correct": True}, {"topic": "solar_panels", "correct": False}, {"topic": "financing", "correct": True}, {"topic": "financing", "correct": True}, ] topics = {} for a in answers: t = a["topic"] if t not in topics: topics[t] = {"total": 0, "correct": 0} topics[t]["total"] += 1 if a["correct"]: topics[t]["correct"] += 1 assert topics["solar_panels"]["total"] == 2 assert topics["solar_panels"]["correct"] == 1 assert topics["financing"]["total"] == 2 assert topics["financing"]["correct"] == 2 def test_weakness_threshold(self): """Topics with >30% weakness ratio are flagged.""" weakness_ratio = 0.4 is_weak = weakness_ratio > 0.3 assert is_weak is True weakness_ratio = 0.2 is_weak = weakness_ratio > 0.3 assert is_weak is False class TestCompletionReport: """Completion report logic.""" def test_best_vs_latest(self): best_score = 90.0 latest_score = 75.0 # Best should always be >= latest assert best_score >= latest_score def test_replay_improvement_delta(self): best = 85.0 latest = 90.0 delta = latest - best # If latest > best, delta is positive (improvement) assert delta >= 0 or best >= latest def test_attempt_count(self): attempt_count = 3 assert attempt_count > 0 def test_not_passed_not_complete(self): is_passed = False signed_off = False is_complete = is_passed and signed_off assert is_complete is False