View basket.ts
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
export class Basket { | |
//... | |
private applyDiscount(totalOfSameBookBorrowed: number, price: number): number { | |
switch (totalOfSameBookBorrowed) { | |
case 1: | |
return price | |
case 2: | |
return price * (1 - 0.05) | |
default: |
View basket.ts
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
export class Basket { | |
//... | |
private applyDiscount(totalOfSameBookBorrowed: number, price: number): number { | |
return DiscountCalculatorFactory | |
.for(totalOfSameBookBorrowed) | |
.applyDiscountOn(price) | |
} | |
} |
View discountCalculatorFactory.ts
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
export class DiscountCalculatorFactory { | |
static for(numberOfSameBook: number): DiscountCalculator { | |
switch (numberOfSameBook) { | |
case 1: | |
return new NoDiscountCalculator() | |
case 2: | |
return new TwoSameBooksDiscountCalculator() | |
default: | |
return new ThreeOrMoreSameBooksDiscountCalculator() | |
} |
View discountCalculator.ts
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
export interface DiscountCalculator { | |
applyDiscountOn(price: number): number | |
} |
View twoSameTomes.discountCalculator.ts
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
export class TwoSameTomesDiscountCalculator implements DiscountCalculator { | |
private FIVE_PERCENT_DISCOUNT = 1 - 0.05 | |
applyDiscountOn(price: number): number { | |
return price * this.FIVE_PERCENT_DISCOUNT | |
} | |
} |
View threeOrMoreSameBooks.discountCalculator.ts
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
export class ThreeOrMoreSameBooksDiscountCalculator implements DiscountCalculator { | |
private TWENTY_FIVE_PERCENT_DISCOUNT = 1 - 0.25 | |
applyDiscountOn(price: number): number { | |
return price * this.TWENTY_FIVE_PERCENT_DISCOUNT | |
} | |
} |
View noDiscountCalculator.ts
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
export class NoDiscountCalculator implements DiscountCalculator { | |
applyDiscountOn(price: number): number { | |
return price | |
} | |
} |
View Saga.scala
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 PhoneNumbersSaga(eventPublisher: EventPublisher) extends EventListener { | |
private var tracker = new PhoneNumberStateTracker | |
def handle(phoneNumbers: List[String]): PhoneNumberStateTracker = { | |
eventPublisher.publish(AllPhoneNumberListed(phoneNumbers)) | |
tracker | |
} | |
override def execute(event: Event): Unit = event match { | |
case apnc: AllPhoneNumbersCounted => tracker = PhoneNumberStateTracker(apnc.total, tracker.totalMatchedPhoneNumbers) |
View basketCalculation.test.ts
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
describe('Unit | Basket price calculation', () => { | |
let basket: Basket | |
beforeEach(() => basket = new Basket()) | |
it('For an empty basket', () => { | |
expect(basket.price).to.equal(0) | |
}) | |
describe('Borrowing n different books', () => { |
View panierCalcule.test.ts
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
describe('Unit | Caclcule du prix du panier', () => { | |
let basket: Basket | |
beforeEach(() => basket = new Basket()) | |
it('Pour un panier vide', () => { | |
expect(basket.price).to.equal(0) | |
}) | |
describe('Emprunter n livres différents', () => { |
OlderNewer