File tree Expand file tree Collapse file tree
src/world-company-remuneration
test/world-company-remuneration Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ const K = "K" ;
2+
3+ /**
4+ * Created by thomas on 02/12/2019.
5+ * This class is a basket
6+ */
7+
8+ export class BasketInformations {
9+ // The product of the basket
10+ static map : Map < string , number > = new Map < string , number > ( )
11+
12+ addProductToBasket ( product : string , price : number ) {
13+ BasketInformations . map . set ( product , price )
14+ }
15+
16+ getBasketPrice ( inCents : boolean ) : Number {
17+ var v = 0 ;
18+ for ( let s of Array . from ( BasketInformations . map . values ( ) ) ) {
19+ v += s ;
20+ }
21+ return inCents ? new Number ( v * 100 ) : Number ( v )
22+ }
23+
24+ resetBasket ( ) {
25+ this . buyBasket ( ) ;
26+ }
27+
28+ buyBasket ( ) {
29+ BasketInformations . map . clear ( ) ;
30+ }
31+
32+ isBasketContains ( produit : string ) : boolean {
33+ var found : boolean = false ;
34+ for ( let s of Array . from ( BasketInformations . map . keys ( ) ) ) {
35+ if ( s == produit ) found = true ;
36+ }
37+ return found ;
38+ }
39+
40+
41+ mixWithBasket ( b : BasketInformations ) {
42+ for ( let [ s , z ] of Array . from ( BasketInformations . map ) ) {
43+ BasketInformations . map . set ( s , z )
44+ }
45+ }
46+ }
Original file line number Diff line number Diff line change 1+ import { BasketInformations } from "../../src/world-company-remuneration/basket-informations" ;
2+
3+ describe ( "a basket should cost" , ( ) => {
4+
5+ test ( "0 when empty" , ( ) => {
6+ expect ( new BasketInformations ( ) . getBasketPrice ( false ) ) . toBe ( 0 ) ;
7+ } ) ;
8+
9+ test ( "1000 otherwise" , ( ) => {
10+ let basketInformations = new BasketInformations ( ) ;
11+ basketInformations . resetBasket ( )
12+ basketInformations . addProductToBasket ( "Toto" , 1000 )
13+ expect ( basketInformations . getBasketPrice ( false ) ) . toBe ( 1000 ) ;
14+ } ) ;
15+
16+ } ) ;
You can’t perform that action at this time.
0 commit comments