File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change
1
+ export default class {
2
+ constructor ( ) {
3
+ this . size = 0 ;
4
+ this . keys = [ ] ;
5
+ this . values = [ ] ;
6
+ }
7
+
8
+ get ( key ) {
9
+ const index = this . keys . indexOf ( key ) ;
10
+
11
+ return this . values [ index ] ;
12
+ }
13
+
14
+ set ( key , value ) {
15
+ this . keys . push ( key ) ;
16
+ this . values . push ( value ) ;
17
+ this . size = this . keys . length ;
18
+
19
+ return value ;
20
+ }
21
+ }
Original file line number Diff line number Diff line change
1
+ import {
2
+ expect
3
+ } from 'chai' ;
4
+ import SimpleMap from './../src/SimpleMap' ;
5
+
6
+ describe ( 'SimpleMap' , ( ) => {
7
+ context ( 'simple map with primitive or object as keys' , ( ) => {
8
+ const values = [
9
+ [ 1 , 'something' ] ,
10
+ [ '1' , 'somethingElse' ] ,
11
+ [ { } , [ ] ] ,
12
+ [ null , null ]
13
+ ] ;
14
+
15
+ let map ;
16
+
17
+ beforeEach ( ( ) => {
18
+ map = new SimpleMap ( ) ;
19
+ } ) ;
20
+
21
+ it ( 'should set' , ( ) => {
22
+ values . forEach ( ( [ key , value ] ) => {
23
+ map . set ( key , value ) ;
24
+ } ) ;
25
+ expect ( map . size ) . to . equal ( values . length ) ;
26
+ } ) ;
27
+
28
+ it ( 'should get' , ( ) => {
29
+ values . forEach ( ( [ key , value ] ) => {
30
+ map . set ( key , value ) ;
31
+ } ) ;
32
+
33
+ values . forEach ( ( [ key , value ] ) => {
34
+ expect ( map . get ( key ) ) . to . equal ( value ) ;
35
+ } ) ;
36
+ } ) ;
37
+ } ) ;
38
+ } ) ;
You can’t perform that action at this time.
0 commit comments