1
+ var Tuple = require ( '../../tupleDataStructure/tupleJS' ) ;
2
+ var expect = require ( 'chai' ) . expect ;
3
+
4
+ describe ( 'Tuple' , function ( ) {
5
+
6
+ it ( 'should store the values put into it' , function ( ) {
7
+ t = new Tuple ( [ "blah" , { two : 2 } , 5 ] ) ;
8
+ expect ( t . findValue ( 0 ) ) . to . deep . equal ( "blah" ) ;
9
+ expect ( t . findValue ( 1 ) ) . to . deep . equal ( 2 ) ;
10
+ expect ( t . findValue ( 2 ) ) . to . deep . equal ( 5 ) ;
11
+ expect ( t . findValue ( 'two' ) ) . to . deep . equal ( 2 ) ;
12
+ expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
13
+ expect ( t . findValue ( 'three' ) ) . to . deep . equal ( undefined ) ;
14
+ } ) ;
15
+
16
+ it ( 'should function like an array if only values are put into it' , function ( ) {
17
+ t = new Tuple ( [ "blah" , 3 , true ] ) ;
18
+ expect ( t . findValue ( 0 ) ) . to . deep . equal ( "blah" ) ;
19
+ expect ( t . findValue ( 1 ) ) . to . deep . equal ( 3 ) ;
20
+ expect ( t . findValue ( 2 ) ) . to . deep . equal ( true ) ;
21
+ expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
22
+ expect ( t . findValue ( 'three' ) ) . to . deep . equal ( undefined ) ;
23
+ } ) ;
24
+
25
+ it ( 'should function like an dictionary if only objects are put into it' , function ( ) {
26
+ t = new Tuple ( [ { one : 1 } , { two : true } , { three : "blah" } ] ) ;
27
+ expect ( t . findValue ( 0 ) ) . to . deep . equal ( 1 ) ;
28
+ expect ( t . findValue ( 'one' ) ) . to . deep . equal ( 1 ) ;
29
+ expect ( t . findValue ( 1 ) ) . to . deep . equal ( true ) ;
30
+ expect ( t . findValue ( 'two' ) ) . to . deep . equal ( true ) ;
31
+ expect ( t . findValue ( 2 ) ) . to . deep . equal ( "blah" ) ;
32
+ expect ( t . findValue ( 'three' ) ) . to . deep . equal ( "blah" ) ;
33
+ expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
34
+ expect ( t . findValue ( 'four' ) ) . to . deep . equal ( undefined ) ;
35
+ } ) ;
36
+
37
+ it ( 'should not modify values if new and old value types do not match' , function ( ) {
38
+ t = new Tuple ( [ "blah" , { two : 2 } , { three : 7 } ] ) ;
39
+ expect ( t . findValue ( 0 ) ) . to . deep . equal ( "blah" ) ;
40
+ expect ( t . findValue ( 1 ) ) . to . deep . equal ( 2 ) ;
41
+ expect ( t . findValue ( 2 ) ) . to . deep . equal ( 7 ) ;
42
+ expect ( t . findValue ( 'three' ) ) . to . deep . equal ( 7 ) ;
43
+ expect ( t . findValue ( 'two' ) ) . to . deep . equal ( 2 ) ;
44
+ expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
45
+ t . modifyVal ( 0 , 7 ) ;
46
+ expect ( t . findValue ( 0 ) ) . to . deep . equal ( "blah" ) ;
47
+ expect ( t . findValue ( 1 ) ) . to . deep . equal ( 2 ) ;
48
+ expect ( t . findValue ( 2 ) ) . to . deep . equal ( 7 ) ;
49
+ expect ( t . findValue ( 'three' ) ) . to . deep . equal ( 7 ) ;
50
+ expect ( t . findValue ( 'two' ) ) . to . deep . equal ( 2 ) ;
51
+ expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
52
+ t . modifyVal ( 1 , "someString" ) ;
53
+ expect ( t . findValue ( 0 ) ) . to . deep . equal ( "blah" ) ;
54
+ expect ( t . findValue ( 1 ) ) . to . deep . equal ( 2 ) ;
55
+ expect ( t . findValue ( 2 ) ) . to . deep . equal ( 7 ) ;
56
+ expect ( t . findValue ( 'three' ) ) . to . deep . equal ( 7 ) ;
57
+ expect ( t . findValue ( 'two' ) ) . to . deep . equal ( 2 ) ;
58
+ expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
59
+ } ) ;
60
+
61
+ it ( 'should modify only the values requested and if the types of values match' , function ( ) {
62
+ t = new Tuple ( [ "blah" , { two : 2 } , { three : 7 } ] ) ;
63
+ expect ( t . findValue ( 0 ) ) . to . deep . equal ( "blah" ) ;
64
+ expect ( t . findValue ( 1 ) ) . to . deep . equal ( 2 ) ;
65
+ expect ( t . findValue ( 2 ) ) . to . deep . equal ( 7 ) ;
66
+ expect ( t . findValue ( 'three' ) ) . to . deep . equal ( 7 ) ;
67
+ expect ( t . findValue ( 'two' ) ) . to . deep . equal ( 2 ) ;
68
+ expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
69
+ t . modifyVal ( 0 , "newBlah" ) ;
70
+ expect ( t . findValue ( 0 ) ) . to . deep . equal ( "newBlah" ) ;
71
+ expect ( t . findValue ( 1 ) ) . to . deep . equal ( 2 ) ;
72
+ expect ( t . findValue ( 2 ) ) . to . deep . equal ( 7 ) ;
73
+ expect ( t . findValue ( 'three' ) ) . to . deep . equal ( 7 ) ;
74
+ expect ( t . findValue ( 'two' ) ) . to . deep . equal ( 2 ) ;
75
+ expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
76
+ t . modifyVal ( 1 , 8 ) ;
77
+ expect ( t . findValue ( 0 ) ) . to . deep . equal ( "newBlah" ) ;
78
+ expect ( t . findValue ( 1 ) ) . to . deep . equal ( 8 ) ;
79
+ expect ( t . findValue ( 2 ) ) . to . deep . equal ( 7 ) ;
80
+ expect ( t . findValue ( 'three' ) ) . to . deep . equal ( 7 ) ;
81
+ expect ( t . findValue ( 'two' ) ) . to . deep . equal ( 8 ) ;
82
+ expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
83
+ // t.modifyVal("three",21);
84
+ // expect(t.findValue(0)).to.deep.equal("newBlah");
85
+ // expect(t.findValue(1)).to.deep.equal(8);
86
+ // expect(t.findValue(2)).to.deep.equal(7);
87
+ // expect(t.findValue('three')).to.deep.equal(21);
88
+ // expect(t.findValue('two')).to.deep.equal(8);
89
+ // expect(t.findValue(3)).to.deep.equal(undefined);
90
+ } ) ;
91
+
92
+ // it('should delete only the values requested', function () {
93
+ // t = new Tuple(["blah", {two: 2}, {three: 7}]);
94
+ // expect(t.findValue(0)).to.deep.equal("blah");
95
+ // expect(t.findValue(1)).to.deep.equal(2);
96
+ // expect(t.findValue(2)).to.deep.equal(7);
97
+ // expect(t.findValue('three')).to.deep.equal(7);
98
+ // expect(t.findValue('two')).to.deep.equal(2);
99
+ // expect(t.findValue(3)).to.deep.equal(undefined);
100
+ // t.deleteElement(0);
101
+ // expect(t.findValue(0)).to.deep.equal(undefined);
102
+ // expect(t.findValue(1)).to.deep.equal(2);
103
+ // expect(t.findValue('two')).to.deep.equal(2);
104
+ // expect(t.findValue(2)).to.deep.equal(7);
105
+ // expect(t.findValue('three')).to.deep.equal(7);
106
+ // expect(t.findValue(3)).to.deep.equal(undefined);
107
+ // t.deleteElement(1);
108
+ // expect(t.findValue(0)).to.deep.equal(undefined);
109
+ // expect(t.findValue(1)).to.deep.equal(undefined);
110
+ // expect(t.findValue('two')).to.deep.equal(undefined);
111
+ // expect(t.findValue(2)).to.deep.equal(7);
112
+ // expect(t.findValue('three')).to.deep.equal(7);
113
+ // expect(t.findValue(3)).to.deep.equal(undefined);
114
+ // t.deleteElement("three");
115
+ // expect(t.findValue(0)).to.deep.equal(undefined);
116
+ // expect(t.findValue(1)).to.deep.equal(undefined);
117
+ // expect(t.findValue('two')).to.deep.equal(undefined);
118
+ // expect(t.findValue(2)).to.deep.equal(undefined);
119
+ // expect(t.findValue('three')).to.deep.equal(undefined);
120
+ // expect(t.findValue(3)).to.deep.equal(undefined);
121
+ // });
122
+
123
+ it ( 'should not rename the key if passed incorrect arguments' , function ( ) {
124
+ t = new Tuple ( [ "blah" , { two : 2 } , { three : 7 } ] ) ;
125
+ expect ( t . findValue ( 0 ) ) . to . deep . equal ( "blah" ) ;
126
+ expect ( t . findValue ( 1 ) ) . to . deep . equal ( 2 ) ;
127
+ expect ( t . findValue ( 2 ) ) . to . deep . equal ( 7 ) ;
128
+ expect ( t . findValue ( 'three' ) ) . to . deep . equal ( 7 ) ;
129
+ expect ( t . findValue ( 'two' ) ) . to . deep . equal ( 2 ) ;
130
+ expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
131
+ t . renameElement ( 0 , 1 ) ;
132
+ expect ( t . findValue ( 0 ) ) . to . deep . equal ( "blah" ) ;
133
+ expect ( t . findValue ( 1 ) ) . to . deep . equal ( 2 ) ;
134
+ expect ( t . findValue ( 2 ) ) . to . deep . equal ( 7 ) ;
135
+ expect ( t . findValue ( 'three' ) ) . to . deep . equal ( 7 ) ;
136
+ expect ( t . findValue ( 'two' ) ) . to . deep . equal ( 2 ) ;
137
+ expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
138
+ t . renameElement ( 0 , "abc" ) ;
139
+ expect ( t . findValue ( 0 ) ) . to . deep . equal ( "blah" ) ;
140
+ expect ( t . findValue ( 1 ) ) . to . deep . equal ( 2 ) ;
141
+ expect ( t . findValue ( 2 ) ) . to . deep . equal ( 7 ) ;
142
+ expect ( t . findValue ( 'three' ) ) . to . deep . equal ( 7 ) ;
143
+ expect ( t . findValue ( 'two' ) ) . to . deep . equal ( 2 ) ;
144
+ expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
145
+ t . renameElement ( "abc" , 1 ) ;
146
+ expect ( t . findValue ( 0 ) ) . to . deep . equal ( "blah" ) ;
147
+ expect ( t . findValue ( 1 ) ) . to . deep . equal ( 2 ) ;
148
+ expect ( t . findValue ( 2 ) ) . to . deep . equal ( 7 ) ;
149
+ expect ( t . findValue ( 'three' ) ) . to . deep . equal ( 7 ) ;
150
+ expect ( t . findValue ( 'two' ) ) . to . deep . equal ( 2 ) ;
151
+ expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
152
+ t . renameElement ( "four" , "five" ) ;
153
+ expect ( t . findValue ( 0 ) ) . to . deep . equal ( "blah" ) ;
154
+ expect ( t . findValue ( 1 ) ) . to . deep . equal ( 2 ) ;
155
+ expect ( t . findValue ( 2 ) ) . to . deep . equal ( 7 ) ;
156
+ expect ( t . findValue ( 'three' ) ) . to . deep . equal ( 7 ) ;
157
+ expect ( t . findValue ( 'two' ) ) . to . deep . equal ( 2 ) ;
158
+ expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
159
+ expect ( t . findValue ( 'four' ) ) . to . deep . equal ( undefined ) ;
160
+ expect ( t . findValue ( 'five' ) ) . to . deep . equal ( undefined ) ;
161
+ // t.renameElement("two","ten");
162
+ // expect(t.findValue(0)).to.deep.equal("blah");
163
+ // expect(t.findValue(1)).to.deep.equal(2);
164
+ // expect(t.findValue(2)).to.deep.equal(7);
165
+ // expect(t.findValue('three')).to.deep.equal(7);
166
+ // expect(t.findValue('two')).to.deep.equal(undefined);
167
+ // expect(t.findValue('ten')).to.deep.equal(undefined);
168
+ // expect(t.findValue(3)).to.deep.equal(undefined);
169
+ // expect(t.findValue('four')).to.deep.equal(undefined);
170
+ // expect(t.findValue('five')).to.deep.equal(undefined);
171
+ } ) ;
172
+
173
+ it ( 'should rename the key if the correct arguments are passed in' , function ( ) {
174
+ t = new Tuple ( [ "blah" , { two : 2 } , { three : 7 } ] ) ;
175
+ expect ( t . findValue ( 0 ) ) . to . deep . equal ( "blah" ) ;
176
+ expect ( t . findValue ( 1 ) ) . to . deep . equal ( 2 ) ;
177
+ expect ( t . findValue ( 2 ) ) . to . deep . equal ( 7 ) ;
178
+ expect ( t . findValue ( 'three' ) ) . to . deep . equal ( 7 ) ;
179
+ expect ( t . findValue ( 'two' ) ) . to . deep . equal ( 2 ) ;
180
+ expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
181
+ t . renameElement ( "two" , "ten" ) ;
182
+ expect ( t . findValue ( 0 ) ) . to . deep . equal ( "blah" ) ;
183
+ expect ( t . findValue ( 1 ) ) . to . deep . equal ( 2 ) ;
184
+ expect ( t . findValue ( 'two' ) ) . to . deep . equal ( undefined ) ;
185
+ expect ( t . findValue ( 'ten' ) ) . to . deep . equal ( 2 ) ;
186
+ expect ( t . findValue ( 2 ) ) . to . deep . equal ( 7 ) ;
187
+ expect ( t . findValue ( 'three' ) ) . to . deep . equal ( 7 ) ;
188
+ expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
189
+ } ) ;
190
+
191
+ } ) ;
0 commit comments