Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions utils/tests/sentiment_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import unittest
from utils.sentiment import detect_sentiment

class TestSentimentAnalysis(unittest.TestCase):
def test_positive_sentiment(self):
text = "I love this product. It's amazing."
result = detect_sentiment(text)
self.assertEqual(len(result), 2)
self.assertEqual(result[0][1], 'Positive')
self.assertEqual(result[1][1], 'Positive')

Check warning on line 10 in utils/tests/sentiment_test.py

View check run for this annotation

Codecov Notifications / codecov/patch

utils/tests/sentiment_test.py#L4-L10

Added lines #L4 - L10 were not covered by tests

def test_negative_sentiment(self):
text = "This is terrible. I hate it."
result = detect_sentiment(text)
self.assertEqual(len(result), 2)
self.assertEqual(result[0][1], 'Negative')
self.assertEqual(result[1][1], 'Negative')

Check warning on line 17 in utils/tests/sentiment_test.py

View check run for this annotation

Codecov Notifications / codecov/patch

utils/tests/sentiment_test.py#L12-L17

Added lines #L12 - L17 were not covered by tests

def test_neutral_sentiment(self):
text = "The sky is blue. Water is wet."
result = detect_sentiment(text)
self.assertEqual(len(result), 2)
self.assertEqual(result[0][1], 'Neutral')
self.assertEqual(result[1][1], 'Neutral')

Check warning on line 24 in utils/tests/sentiment_test.py

View check run for this annotation

Codecov Notifications / codecov/patch

utils/tests/sentiment_test.py#L19-L24

Added lines #L19 - L24 were not covered by tests

def test_mixed_sentiment(self):
text = "I love this product. However, the price is too high."
result = detect_sentiment(text)
self.assertEqual(len(result), 2)
self.assertEqual(result[0][1], 'Positive')
self.assertEqual(result[1][1], 'Negative')

Check warning on line 31 in utils/tests/sentiment_test.py

View check run for this annotation

Codecov Notifications / codecov/patch

utils/tests/sentiment_test.py#L26-L31

Added lines #L26 - L31 were not covered by tests

def test_empty_input(self):
text = ""
result = detect_sentiment(text)
self.assertEqual(len(result), 0)

Check warning on line 36 in utils/tests/sentiment_test.py

View check run for this annotation

Codecov Notifications / codecov/patch

utils/tests/sentiment_test.py#L33-L36

Added lines #L33 - L36 were not covered by tests

def test_single_word(self):
text = "Fantastic"
result = detect_sentiment(text)
self.assertEqual(len(result), 1)
self.assertEqual(result[0][1], 'Positive')

Check warning on line 42 in utils/tests/sentiment_test.py

View check run for this annotation

Codecov Notifications / codecov/patch

utils/tests/sentiment_test.py#L38-L42

Added lines #L38 - L42 were not covered by tests

if __name__ == '__main__':
unittest.main()

Check warning on line 45 in utils/tests/sentiment_test.py

View check run for this annotation

Codecov Notifications / codecov/patch

utils/tests/sentiment_test.py#L44-L45

Added lines #L44 - L45 were not covered by tests
Loading