def test_to_string(self): r = Review("Testing review.") for _ in range(1000): rand_num = random.random() r.set_positivity(rand_num) expected = "<--- Review Text ---> \n" + r.get_text() + "\n <--- Positivity ---> \n"+str(r.positivity)+"\n" actual = r.__str__() self.assertEqual(actual, expected)
def process_reviews(texts, pcalc): """ Take a list of strings, make a list of Review objects and calculate the positivity rating for each Review. Parameters: texts: a list of strings for the Reviews pcalc: a PositivityCalculator that will calculate all the ratings Returns: reviews: a list of fully formed Review objects """ reviews = [] for text in texts: rev = Review(text) pos = pcalc.calc_positivity(rev.get_text()) rev.set_positivity(pos) # Add to the reviews array reviews.append(rev) return reviews
def test_get_text(self): r = Review("Sample text.") actual = r.get_text() expected = "Sample text." self.assertEqual(actual, expected)