Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions typescript/src/world-company-remuneration/basket-informations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const K = "K";

/**
* Created by thomas on 02/12/2019.
* This class is a basket
*/

export class BasketInformations {
// The product of the basket
static map: Map<string, number> = new Map<string, number>()

addProductToBasket(product: string, price: number) {
BasketInformations.map.set(product, price)
}

getBasketPrice(inCents: boolean): Number {
var v = 0;
for (let s of Array.from(BasketInformations.map.values())) {
v += s;
}
return inCents ? new Number(v * 100) : Number(v)
}

resetBasket() {
this.buyBasket();
}

buyBasket() {
BasketInformations.map.clear();
}

isBasketContains(produit: string): boolean {
var found: boolean = false;
for (let s of Array.from(BasketInformations.map.keys())) {
if (s == produit) found = true;
}
return found;
}


mixWithBasket(b: BasketInformations) {
for (let [s,z] of Array.from(BasketInformations.map)) {
BasketInformations.map.set(s,z)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {BasketInformations} from "../../src/world-company-remuneration/basket-informations";

describe("a basket should cost", () => {

test("0 when empty", () => {
expect(new BasketInformations().getBasketPrice(false)).toBe(0);
});

test("1000 otherwise", () => {
let basketInformations = new BasketInformations();
basketInformations.resetBasket()
basketInformations.addProductToBasket("Toto", 1000)
expect(basketInformations.getBasketPrice(false)).toBe(1000);
});

});