This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def price(self, imdbID): | |
rating, title = self.videoInfo.fetch_video_info(imdbID) | |
price = 3.95 | |
if rating > 7: | |
price += 2.0 | |
if rating < 4: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def price(self, imdbID): | |
rating, title = self.videoInfo.fetch_video_info(imdbID) | |
price = 3.95 | |
if rating > 7: | |
price += 2.0 | |
if rating < 4: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def test_high_rated_movie_price(self): | |
rental = Rental('jgorman', 'tt9999', Pricer(VideoInfoStub(7.1))) | |
self.assertEqual(5.95, rental.video.price) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Pricer(object): | |
def price(self, imdbID): | |
rating, title = VideoInfo().fetch_video_info(imdbID) | |
price = 3.95 | |
if rating > 7: | |
price += 1.0 |