Skip to content

Instantly share code, notes, and snippets.

@thenormalsquid
Last active December 11, 2015 11:48
Show Gist options
  • Save thenormalsquid/4596252 to your computer and use it in GitHub Desktop.
Save thenormalsquid/4596252 to your computer and use it in GitHub Desktop.
import unittest
from ps5 import *
score = 0.0
potential_score = 0.0
def add_potential_points(points):
global potential_score
potential_score += points
def add_points(points):
global score
score += points
class ProblemSet5NewsStory(unittest.TestCase):
def setUp(self):
pass
def testNewsStoryConstructor(self):
add_potential_points(1)
story = NewsStory('', '', '', '', '')
add_points(1)
def testNewsStoryGetGuid(self):
add_potential_points(1)
story = NewsStory('test guid', 'test title', 'test subject',
'test summary', 'test link')
self.assertEquals(story.get_guid(), 'test guid')
add_points(1)
def testNewsStoryGetTitle(self):
add_potential_points(1)
story = NewsStory('test guid', 'test title', 'test subject',
'test summary', 'test link')
self.assertEquals(story.get_title(), 'test title')
add_points(1)
def testNewsStoryGetSubject(self):
add_potential_points(1)
story = NewsStory('test guid', 'test title', 'test subject',
'test summary', 'test link')
self.assertEquals(story.get_subject(), 'test subject')
add_points(1)
def testNewsStoryGetSummary(self):
add_potential_points(1)
story = NewsStory('test guid', 'test title', 'test subject',
'test summary', 'test link')
self.assertEquals(story.get_summary(), 'test summary')
add_points(1)
def testNewsStoryGetLink(self):
add_potential_points(1)
story = NewsStory('test guid', 'test title', 'test subject',
'test summary', 'test link')
self.assertEquals(story.get_link(), 'test link')
add_points(1)
class ProblemSet5(unittest.TestCase):
def setUp(self):
class TrueTrigger:
def evaluate(self, story): return True
class FalseTrigger:
def evaluate(self, story): return False
self.tt = TrueTrigger()
self.tt2 = TrueTrigger()
self.ft = FalseTrigger()
self.ft2 = FalseTrigger()
def test1TitleTrigger(self):
add_potential_points(5)
koala = NewsStory('', 'Koala bears are soft and cuddly', '', '', '')
pillow = NewsStory('', 'I prefer pillows that are soft.', '', '', '')
soda = NewsStory('', 'Soft drinks are great', '', '', '')
pink = NewsStory('', "Soft's the new pink!", '', '', '')
football = NewsStory('', '"Soft!" he exclaimed as he threw the football', '', '', '')
microsoft = NewsStory('', 'Microsoft announced today that pillows are bad', '', '', '')
nothing = NewsStory('', 'Reuters reports something really boring', '', '' ,'')
caps = NewsStory('', 'soft things are soft', '', '', '')
#s1 = TitleTrigger('SOFT')
s2 = TitleTrigger('soft')
for trig in [s2]:
self.assertTrue(trig.evaluate(koala), "TitleTrigger failed to fire when the word appeared in the title")
self.assertTrue(trig.evaluate(pillow), "TitleTrigger failed to fire when the word had punctuation on it")
self.assertTrue(trig.evaluate(soda), "TitleTrigger failed to fire when the case was different")
self.assertTrue(trig.evaluate(pink), "TitleTrigger failed to fire when the word had an apostrophe on it")
self.assertTrue(trig.evaluate(football), "TitleTrigger failed to fire in the presence of lots of punctuation")
self.assertTrue(trig.evaluate(caps), "TitleTrigger is case-sensitive and shouldn't be")
self.assertFalse(trig.evaluate(microsoft), "TitleTrigger fired when the word was present, but not as its own word (e.g. 'soft' and 'Microsoft)'")
self.assertFalse(trig.evaluate(nothing), "TitleTrigger fired when the word wasn't really present in the title")
add_points(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment