Skip to content

Instantly share code, notes, and snippets.

View jasongorman's full-sized avatar

Jason Gorman jasongorman

View GitHub Profile
class Pricer(object):
def price(self, imdbID):
rating, title = self.fetch_video_info(imdbID)
price = 3.95
if rating > 7:
price += 1.0
def main():
customer = sys.argv[1]
imdbID = sys.argv[2]
rental = Rental(customer, imdbID)
print(rental)
if __name__ == "__main__": main()
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)
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"])
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());
}
void loadTruck() {
execute(() -> truck.load(bay.unload()))
.until(truck::isLoaded, this);
}
private void loadAll() {
execute(() -> {
bay.load(parcels.get(parcels.size() - 1));
parcels.remove(parcels.size() - 1);
})
.until(parcels::isEmpty, this);
}
void load(Parcel parcel){
execute(() -> parcels.add(parcel))
.when(() -> !isFull(), this);
}
Parcel unload(){
return execute(() -> parcels.remove(parcels.size() - 1))
.when(() -> !parcels.isEmpty(), this);
}
public class TruckLoader implements Runnable {
private final LoadingBay bay;
private final Truck truck;
TruckLoader(LoadingBay bay, Truck truck) {
this.bay = bay;
this.truck = truck;
}
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;
}