|
| 1 | +import time |
| 2 | +import uuid |
| 3 | + |
| 4 | +from feedback_agent.database import StudentDatabase |
| 5 | +from feedback_agent.memory import MemoryService |
| 6 | + |
| 7 | + |
| 8 | +def _log_exam(db: StudentDatabase, student_id: str, subject: str, score: int, max_score: int, weaknesses): |
| 9 | + exam_id = str(uuid.uuid4()) |
| 10 | + db.log_exam(exam_id, student_id, subject, score, max_score) |
| 11 | + db.log_analysis(exam_id, weaknesses=weaknesses, topics=[subject]) |
| 12 | + return exam_id |
| 13 | + |
| 14 | + |
| 15 | +def test_memory_service_recurring_and_velocity(tmp_path): |
| 16 | + db_path = tmp_path / "students.db" |
| 17 | + db = StudentDatabase(str(db_path)) |
| 18 | + student_id = str(uuid.uuid4()) |
| 19 | + db.add_student(student_id, "Test Student") |
| 20 | + memory = MemoryService(db) |
| 21 | + |
| 22 | + _log_exam(db, student_id, "Math", 6, 10, [{"topic": "Algebra", "severity": "high"}]) |
| 23 | + time.sleep(0.01) |
| 24 | + _log_exam(db, student_id, "Math", 7, 10, [{"topic": "Algebra", "severity": "medium"}]) |
| 25 | + time.sleep(0.01) |
| 26 | + _log_exam(db, student_id, "Science", 9, 10, [{"topic": "Chemistry", "severity": "low"}]) |
| 27 | + |
| 28 | + recurring = memory.get_recurring_weaknesses(student_id, min_occurrences=2) |
| 29 | + assert any(p.topic == "Algebra" and p.occurrences == 2 for p in recurring) |
| 30 | + |
| 31 | + velocity = memory.get_learning_velocity(student_id) |
| 32 | + assert velocity is not None |
| 33 | + assert velocity.total_exams == 3 |
| 34 | + assert 0 <= velocity.average_score <= 100 |
| 35 | + |
| 36 | + |
| 37 | +def test_memory_service_recommendations(tmp_path): |
| 38 | + db_path = tmp_path / "students.db" |
| 39 | + db = StudentDatabase(str(db_path)) |
| 40 | + student_id = str(uuid.uuid4()) |
| 41 | + db.add_student(student_id, "Test Student") |
| 42 | + memory = MemoryService(db) |
| 43 | + |
| 44 | + _log_exam(db, student_id, "History", 5, 10, [{"topic": "Revolutions", "severity": "high"}]) |
| 45 | + time.sleep(0.01) |
| 46 | + _log_exam(db, student_id, "History", 6, 10, [{"topic": "Revolutions", "severity": "high"}]) |
| 47 | + |
| 48 | + recommendations = memory.recommend_review_topics(student_id, max_topics=3) |
| 49 | + assert recommendations |
| 50 | + assert recommendations[0]["topic"] == "Revolutions" |
0 commit comments