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 = self.fetch_video_info(imdbID) | |
price = 3.95 | |
if rating > 7: | |
price += 1.0 |
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 main(): | |
customer = sys.argv[1] | |
imdbID = sys.argv[2] | |
rental = Rental(customer, imdbID) | |
print(rental) | |
if __name__ == "__main__": main() |
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().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 price(self, imdbID): | |
response = requests.get("http://www.omdbapi.com/?i=" + imdbID + "&apikey=6487ec62") | |
json = response.json() | |
title = json["Title"] | |
rating = float(json["imdbRating"]) |
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
public class PriceComparisonTest { | |
@Test | |
public void singleRetailerIsCheapest() { | |
Retailer retailer = (make, model) -> 0; | |
assertSame(retailer, | |
new Comparer(new Retailer[] {retailer}, mock(AdTargeting.class)) | |
.compare("X", "Y") | |
.getRetailer()); | |
} |
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
void loadTruck() { | |
execute(() -> truck.load(bay.unload())) | |
.until(truck::isLoaded, this); | |
} |
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
private void loadAll() { | |
execute(() -> { | |
bay.load(parcels.get(parcels.size() - 1)); | |
parcels.remove(parcels.size() - 1); | |
}) | |
.until(parcels::isEmpty, this); | |
} |
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
void load(Parcel parcel){ | |
execute(() -> parcels.add(parcel)) | |
.when(() -> !isFull(), this); | |
} | |
Parcel unload(){ | |
return execute(() -> parcels.remove(parcels.size() - 1)) | |
.when(() -> !parcels.isEmpty(), this); | |
} |
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
public class TruckLoader implements Runnable { | |
private final LoadingBay bay; | |
private final Truck truck; | |
TruckLoader(LoadingBay bay, Truck truck) { | |
this.bay = bay; | |
this.truck = truck; | |
} |
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 BayLoader implements Runnable { | |
private final LoadingBay bay; | |
private final List<Parcel> parcels; | |
BayLoader(LoadingBay bay, List<Parcel> parcels) { | |
this.bay = bay; | |
this.parcels = parcels; | |
} |