SentimentDetectiontest / backend /test_sentiment.py
Scribbler310's picture
Deploy educational sentiment detection chatbot (excluding PDF)
131da12
Raw
History Blame Contribute Delete
1.88 kB
import os
import sys
# Add current directory to path for imports
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from main import map_distilroberta_emotions
def test_mapping():
print("Testing DistilRoBERTa emotion mapping logic...")
# 1. Frustration tests
anger_test = [{"label": "anger", "score": 0.8}, {"label": "neutral", "score": 0.2}]
assert map_distilroberta_emotions(anger_test) == "frustration", f"Expected frustration, got {map_distilroberta_emotions(anger_test)}"
disgust_test = [{"label": "disgust", "score": 0.6}]
assert map_distilroberta_emotions(disgust_test) == "frustration", f"Expected frustration, got {map_distilroberta_emotions(disgust_test)}"
# 2. Confusion tests
sadness_test = [{"label": "sadness", "score": 0.9}]
assert map_distilroberta_emotions(sadness_test) == "confusion", f"Expected confusion, got {map_distilroberta_emotions(sadness_test)}"
surprise_test = [{"label": "surprise", "score": 0.55}]
assert map_distilroberta_emotions(surprise_test) == "confusion", f"Expected confusion, got {map_distilroberta_emotions(surprise_test)}"
fear_test = [{"label": "fear", "score": 0.7}]
assert map_distilroberta_emotions(fear_test) == "confusion", f"Expected confusion, got {map_distilroberta_emotions(fear_test)}"
# 3. Confidence tests
joy_test = [{"label": "joy", "score": 0.95}]
assert map_distilroberta_emotions(joy_test) == "confidence", f"Expected confidence, got {map_distilroberta_emotions(joy_test)}"
# 4. Boredom tests
neutral_test = [{"label": "neutral", "score": 0.9}]
assert map_distilroberta_emotions(neutral_test) == "boredom", f"Expected boredom, got {map_distilroberta_emotions(neutral_test)}"
print("All DistilRoBERTa mapping assertions passed successfully!")
if __name__ == "__main__":
test_mapping()