-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestCalculateSentiments.py
80 lines (60 loc) · 2.98 KB
/
TestCalculateSentiments.py
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
Created on Oct 30 2020
@author: tincythomas
JUNIT test cases to check the scores of Tweets from Covid19 Hotspots
"""
import unittest
from CalculateSentiment import *
import pandas as pd
from io import StringIO
class TestCalculateSentiments(unittest.TestCase):
def setUp(self):
c = CalculateSentiments()
self.sadnessScore = c.getScoreForText('I am sad');
self.joyScore = c.getScoreForText('I am happy');
self.angerScore = c.getScoreForText('I am angry');
self.fearScore = c.getScoreForText('I am afraid');
self.confidentScore = c.getScoreForText('I am confident that I have found the right path.');
self.tentativeScore = c.getScoreForText('She tentatively raised her hand.');
self.analyticScore = c.getScoreForText('Everybody knows that the world is round.');
def testGetSadScore(self):
self.assertTrue((self.sadnessScore['text']['sadnessScore'])>0)
def testGetHappyScore(self):
self.assertTrue((self.joyScore['text']['joyScore'])>0)
def testGetAngryScore(self):
self.assertTrue((self.angerScore['text']['angerScore'])>0)
def testGetFearScore(self):
self.assertTrue((self.fearScore['text']['fearScore'])>0)
def testGetConfidentScore(self):
self.assertTrue((self.confidentScore['text']['confidentScore'])>0)
def testGetTentativeScore(self):
self.assertTrue((self.tentativeScore['text']['tentativeScore'])>0)
def testGetAnalyticScore(self):
self.assertTrue((self.analyticScore['text']['analyticScore'])>0)
def testNegativeSadScore(self):
self.assertTrue((self.sadnessScore['text']['joyScore'])==0)
def testNegativeJoyScore(self):
self.assertTrue((self.joyScore['text']['sadnessScore'])==0)
def testNegativeFearScore(self):
self.assertTrue((self.fearScore['text']['joyScore'])==0)
def testNegativeAngerScore(self):
self.assertTrue((self.angerScore['text']['sadnessScore'])==0)
def testNegativeConfidentScore(self):
self.assertTrue((self.confidentScore['text']['sadnessScore'])==0)
def testNegativeTentativeScore(self):
self.assertTrue((self.tentativeScore['text']['angerScore'])==0)
def testNegativeAnalyticScore(self):
self.assertTrue((self.analyticScore['text']['confidentScore'])==0)
def testTweetsSentiments(self):
StringData = StringIO("""text;user_location
#COVID19 does not even spare alcoholics. So, bust this myth and stop consuming alcohol to safeguard yourself from #Coronavirus.;Delhi
Better be at home and take precautionary measures to fight against #CoronavirusPandemic. ;Poetry
""")
tweet_text = pd.read_csv(StringData, sep =";")
cal = CalculateSentiments()
result = cal.getScoresforTweets('Delhi',tweet_text)
self.assertTrue(len(result) != 0)
self.assertTrue('Delhi' in result.values())
self.assertTrue('fearScore' in result.keys())
if __name__ == '__main__':
unittest.main()