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";
Comment thread
Tarcaye marked this conversation as resolved.

/**
* Created by thomas on 02/12/2019.
Comment thread
Tarcaye marked this conversation as resolved.
* This class is a basket
Comment thread
Tarcaye marked this conversation as resolved.
*/

export class BasketInformations {
Comment thread
Tarcaye marked this conversation as resolved.
// The product of the basket
static map: Map<string, number> = new Map<string, number>()
Comment thread
Tarcaye marked this conversation as resolved.

addProductToBasket(product: string, price: number) {
Comment thread
Tarcaye marked this conversation as resolved.
BasketInformations.map.set(product, price)
}

getBasketPrice(inCents: boolean): Number {
var v = 0;
Comment thread
Tarcaye marked this conversation as resolved.
for (let s of Array.from(BasketInformations.map.values())) {
Comment thread
Tarcaye marked this conversation as resolved.
v += s;
Comment thread
Tarcaye marked this conversation as resolved.
}
return inCents ? new Number(v * 100) : Number(v)
}

resetBasket() {
Comment thread
Tarcaye marked this conversation as resolved.
this.buyBasket();
Comment thread
Tarcaye marked this conversation as resolved.
}

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

isBasketContains(produit: string): boolean {
Comment thread
Tarcaye marked this conversation as resolved.
var found: boolean = false;
for (let s of Array.from(BasketInformations.map.keys())) {
Comment thread
Tarcaye marked this conversation as resolved.
if (s == produit) found = true;
}
return found;
}


mixWithBasket(b: BasketInformations) {
Comment thread
Tarcaye marked this conversation as resolved.
for (let [s,z] of Array.from(BasketInformations.map)) {
Comment thread
Tarcaye marked this conversation as resolved.
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", () => {
Comment thread
Tarcaye marked this conversation as resolved.

test("0 when empty", () => {
Comment thread
Tarcaye marked this conversation as resolved.
expect(new BasketInformations().getBasketPrice(false)).toBe(0);
});

test("1000 otherwise", () => {
Comment thread
Tarcaye marked this conversation as resolved.
let basketInformations = new BasketInformations();
basketInformations.resetBasket()
Comment thread
Tarcaye marked this conversation as resolved.
basketInformations.addProductToBasket("Toto", 1000)
expect(basketInformations.getBasketPrice(false)).toBe(1000);
});

});