Skip to content
Snippets Groups Projects
Commit 767f8142 authored by Sam Neupane's avatar Sam Neupane
Browse files

hw

parent 45063937
No related branches found
No related tags found
No related merge requests found
import unittest
class MyTestCase(unittest.TestCase):
def test_sentim(self):
self.assertEqual(method_11)
if __name__ == '__main__':
unittest.main()
...@@ -2,12 +2,9 @@ from __future__ import print_function, division ...@@ -2,12 +2,9 @@ from __future__ import print_function, division
from builtins import input from builtins import input
def main(): def main():
reviews = list() reviews = list()
try: try:
with open('sentiment.txt') as s: with open('sentiment.txt') as s:
reviews = list(s) reviews = list(s)
...@@ -70,7 +67,6 @@ def main(): ...@@ -70,7 +67,6 @@ def main():
if word_in_file in sentiments.keys(): if word_in_file in sentiments.keys():
average.append(sum(sentiments[word]) / len(sentiments[word])) average.append(sum(sentiments[word]) / len(sentiments[word]))
if y == 2: if y == 2:
average.append(sum(sentiments[word_in_file]) / len(sentiments[word_in_file])) average.append(sum(sentiments[word_in_file]) / len(sentiments[word_in_file]))
if not average: if not average:
...@@ -81,15 +77,13 @@ def main(): ...@@ -81,15 +77,13 @@ def main():
if average_words >= 2.01: if average_words >= 2.01:
print('The average score of words in {y} is {av}'.format(y=file, av=average_words)) print('The average score of words in {y} is {av}'.format(y=file, av=average_words))
print('The overall sentiment of {y} is positive'.format(y=file)) print('The overall sentiment of {y} is positive'.format(y=file))
if average_words <= 1.99: elif average_words <= 1.99:
print('The average score of words in {y} is {av}'.format(y=file, av=average_words)) print('The average score of words in {y} is {av}'.format(y=file, av=average_words))
print('The overall sentiment of {y} is negative'.format(y=file)) print('The overall sentiment of {y} is negative'.format(y=file))
else: else:
print('The average score of words in {y} is {av}'.format(y=file, av=average_words)) print('The average score of words in {y} is {av}'.format(y=file, av=average_words))
print('The overall sentiment of {y} is neutral'.format(y=file)) print('The overall sentiment of {y} is neutral'.format(y=file))
if y == 3: if y == 3:
# rating = sum(sentiments[x])/len(sentiments[x]) # rating = sum(sentiments[x])/len(sentiments[x])
split_file = file.split() split_file = file.split()
...@@ -103,11 +97,6 @@ def main(): ...@@ -103,11 +97,6 @@ def main():
method_11(check_word) method_11(check_word)
sum_word = sum(method_11(check_word)) / len(method_11(check_word)) sum_word = sum(method_11(check_word)) / len(method_11(check_word))
for file_word, rate in sum_word.items(): for file_word, rate in sum_word.items():
if rate == highest_score: if rate == highest_score:
j = file_word j = file_word
......
from unittest import TestCase from unittest import TestCase
from sentiment import method_11
class TestMethod_11(TestCase): class TestMethod_11(TestCase):
def test_method_11(self,reviews,sentiments): def test_method_11(self):
self.assertEqual(['arty'], ) reviews = ['John', "jack "]
sentiments = [2,2]
self.assertEqual(method_11(reviews,sentiments)[3,0,1,1], ['arty'])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment