Spaces:
Runtime error
Runtime error
File size: 2,105 Bytes
aeb3f7c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | """Unit tests for rubric service."""
import pytest
from writing_studio.services.rubric_service import RubricService
class TestRubricService:
"""Tests for RubricService."""
@pytest.fixture
def service(self):
"""Create rubric service instance."""
return RubricService()
def test_analyze_empty_text(self, service):
"""Test analysis of empty text."""
results = service.analyze_text("")
assert all(data["score"] == 0 for data in results.values())
def test_analyze_valid_text(self, service):
"""Test analysis of valid text."""
text = """This is a clear and concise text. It demonstrates good writing.
Furthermore, it has proper organization. The sentences are well-structured.
According to research, good writing includes evidence."""
results = service.analyze_text(text)
assert "Clarity" in results
assert "Conciseness" in results
assert results["Clarity"]["score"] > 0
assert results["Clarity"]["max_score"] == 5
def test_score_clarity(self, service):
"""Test clarity scoring."""
# Short sentences - should get lower clarity
text = "Short. Very short. Too short."
score, _ = service._score_clarity(text)
assert score <= 3
# Good sentence length
text = "This is a well-structured sentence with appropriate length and clarity."
score, _ = service._score_clarity(text)
assert score >= 3
def test_score_conciseness(self, service):
"""Test conciseness scoring."""
# Wordy text
text = "In order to achieve the goal, due to the fact that we need results."
score, _ = service._score_conciseness(text)
assert score <= 3
def test_format_feedback(self, service):
"""Test feedback formatting."""
results = {
"Clarity": {"score": 4, "max_score": 5, "feedback": "Good clarity"},
}
feedback = service.format_feedback(results)
assert "Clarity: 4/5" in feedback
assert "Good clarity" in feedback
|