Skip to content

Instantly share code, notes, and snippets.

View jasongorman's full-sized avatar

Jason Gorman jasongorman

View GitHub Profile
class Rental(object):
def __init__(self, customer, imdbID, pricer):
self._customer = customer
self._movie = pricer.price(imdbID)
def __str__(self):
return "Movie Rental - customer: " + self._customer \
+ ". Movie => title: " + self._movie.title \
+ ", price: £" + str(self._movie.price)
class Pricer(object):
def __init__(self, movieInfo):
self.movieInfo = movieInfo
def price(self, imdbID):
rating, title = self.movieInfo.fetch_movie_info(imdbID)
price = 3.95
def price(self, imdbID):
rating, title = self.videoInfo.fetch_video_info(imdbID)
price = 3.95
if rating > 7:
price += 2.0
if rating < 4:
def price(self, imdbID):
rating, title = self.videoInfo.fetch_video_info(imdbID)
price = 3.95
if rating > 7:
price += 2.0
if rating < 4:
def test_high_rated_movie_price(self):
rental = Rental('jgorman', 'tt9999', Pricer(VideoInfoStub(7.1)))
self.assertEqual(5.95, rental.video.price)
class VideoInfoStub(VideoInfo):
def __init__(self, rating):
self.rating = rating
self.title = 'XXXXX'
def fetch_video_info(self, imdbID):
return self.rating, self.title
class RentalTest(unittest.TestCase):
class Rental(object):
def __init__(self, customer, imdbID, pricer):
self.customer = customer
self.video = pricer.price(imdbID)
def __str__(self):
return "Video Rental - customer: " + self.customer \
+ ". Video => title: " + self.video.title \
+ ", price: £" + str(self.video.price)
class Rental(object):
def __init__(self, customer, imdbID):
self.customer = customer
self.video = Pricer(VideoInfo()).price(imdbID)
def __str__(self):
return "Video Rental - customer: " + self.customer \
+ ". Video => title: " + self.video.title \
+ ", price: £" + str(self.video.price)
class Pricer(object):
def __init__(self, videoInfo):
self.videoInfo = videoInfo
def price(self, imdbID):
rating, title = self.videoInfo.fetch_video_info(imdbID)
price = 3.95
class Pricer(object):
def price(self, imdbID):
rating, title = VideoInfo().fetch_video_info(imdbID)
price = 3.95
if rating > 7:
price += 1.0