1
1
var Tuple = require ( '../../tupleDataStructure/tupleJS' ) ;
2
2
var expect = require ( 'chai' ) . expect ;
3
3
4
- describe ( 'Tuple' , function ( ) {
4
+ describe ( 'Simple Tuple' , function ( ) {
5
5
6
6
it ( 'should store the values put into it' , function ( ) {
7
7
t = new Tuple ( [ "blah" , { two : 2 } , 5 ] ) ;
@@ -158,16 +158,185 @@ describe('Tuple', function() {
158
158
expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
159
159
expect ( t . findValue ( 'four' ) ) . to . deep . equal ( undefined ) ;
160
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);
161
+ } ) ;
162
+
163
+ it ( 'should rename the key if the correct arguments are passed in' , function ( ) {
164
+ t = new Tuple ( [ "blah" , { two : 2 } , { three : 7 } ] ) ;
165
+ expect ( t . findValue ( 0 ) ) . to . deep . equal ( "blah" ) ;
166
+ expect ( t . findValue ( 1 ) ) . to . deep . equal ( 2 ) ;
167
+ expect ( t . findValue ( 2 ) ) . to . deep . equal ( 7 ) ;
168
+ expect ( t . findValue ( 'three' ) ) . to . deep . equal ( 7 ) ;
169
+ expect ( t . findValue ( 'two' ) ) . to . deep . equal ( 2 ) ;
170
+ expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
171
+ t . renameElement ( "two" , "ten" ) ;
172
+ expect ( t . findValue ( 0 ) ) . to . deep . equal ( "blah" ) ;
173
+ expect ( t . findValue ( 1 ) ) . to . deep . equal ( 2 ) ;
174
+ expect ( t . findValue ( 'two' ) ) . to . deep . equal ( undefined ) ;
175
+ expect ( t . findValue ( 'ten' ) ) . to . deep . equal ( 2 ) ;
176
+ expect ( t . findValue ( 2 ) ) . to . deep . equal ( 7 ) ;
177
+ expect ( t . findValue ( 'three' ) ) . to . deep . equal ( 7 ) ;
178
+ expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
179
+ } ) ;
180
+
181
+ } ) ;
182
+
183
+ describe ( 'Nested Tuple' , function ( ) {
184
+
185
+ it ( 'should store the values put into it' , function ( ) {
186
+ t = new Tuple ( [ "blah" , { two : 2 } , 5 ] ) ;
187
+ expect ( t . findValue ( 0 ) ) . to . deep . equal ( "blah" ) ;
188
+ expect ( t . findValue ( 1 ) ) . to . deep . equal ( 2 ) ;
189
+ expect ( t . findValue ( 2 ) ) . to . deep . equal ( 5 ) ;
190
+ expect ( t . findValue ( 'two' ) ) . to . deep . equal ( 2 ) ;
191
+ expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
192
+ expect ( t . findValue ( 'three' ) ) . to . deep . equal ( undefined ) ;
193
+ } ) ;
194
+
195
+ it ( 'should function like an array if only values are put into it' , function ( ) {
196
+ t = new Tuple ( [ "blah" , 3 , true ] ) ;
197
+ expect ( t . findValue ( 0 ) ) . to . deep . equal ( "blah" ) ;
198
+ expect ( t . findValue ( 1 ) ) . to . deep . equal ( 3 ) ;
199
+ expect ( t . findValue ( 2 ) ) . to . deep . equal ( true ) ;
200
+ expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
201
+ expect ( t . findValue ( 'three' ) ) . to . deep . equal ( undefined ) ;
202
+ } ) ;
203
+
204
+ it ( 'should function like an dictionary if only objects are put into it' , function ( ) {
205
+ t = new Tuple ( [ { one : 1 } , { two : true } , { three : "blah" } ] ) ;
206
+ expect ( t . findValue ( 0 ) ) . to . deep . equal ( 1 ) ;
207
+ expect ( t . findValue ( 'one' ) ) . to . deep . equal ( 1 ) ;
208
+ expect ( t . findValue ( 1 ) ) . to . deep . equal ( true ) ;
209
+ expect ( t . findValue ( 'two' ) ) . to . deep . equal ( true ) ;
210
+ expect ( t . findValue ( 2 ) ) . to . deep . equal ( "blah" ) ;
211
+ expect ( t . findValue ( 'three' ) ) . to . deep . equal ( "blah" ) ;
212
+ expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
213
+ expect ( t . findValue ( 'four' ) ) . to . deep . equal ( undefined ) ;
214
+ } ) ;
215
+
216
+ it ( 'should not modify values if new and old value types do not match' , function ( ) {
217
+ t = new Tuple ( [ "blah" , { two : 2 } , { three : 7 } ] ) ;
218
+ expect ( t . findValue ( 0 ) ) . to . deep . equal ( "blah" ) ;
219
+ expect ( t . findValue ( 1 ) ) . to . deep . equal ( 2 ) ;
220
+ expect ( t . findValue ( 2 ) ) . to . deep . equal ( 7 ) ;
221
+ expect ( t . findValue ( 'three' ) ) . to . deep . equal ( 7 ) ;
222
+ expect ( t . findValue ( 'two' ) ) . to . deep . equal ( 2 ) ;
223
+ expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
224
+ t . modifyVal ( 0 , 7 ) ;
225
+ expect ( t . findValue ( 0 ) ) . to . deep . equal ( "blah" ) ;
226
+ expect ( t . findValue ( 1 ) ) . to . deep . equal ( 2 ) ;
227
+ expect ( t . findValue ( 2 ) ) . to . deep . equal ( 7 ) ;
228
+ expect ( t . findValue ( 'three' ) ) . to . deep . equal ( 7 ) ;
229
+ expect ( t . findValue ( 'two' ) ) . to . deep . equal ( 2 ) ;
230
+ expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
231
+ t . modifyVal ( 1 , "someString" ) ;
232
+ expect ( t . findValue ( 0 ) ) . to . deep . equal ( "blah" ) ;
233
+ expect ( t . findValue ( 1 ) ) . to . deep . equal ( 2 ) ;
234
+ expect ( t . findValue ( 2 ) ) . to . deep . equal ( 7 ) ;
235
+ expect ( t . findValue ( 'three' ) ) . to . deep . equal ( 7 ) ;
236
+ expect ( t . findValue ( 'two' ) ) . to . deep . equal ( 2 ) ;
237
+ expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
238
+ } ) ;
239
+
240
+ it ( 'should modify only the values requested and if the types of values match' , function ( ) {
241
+ t = new Tuple ( [ "blah" , { two : 2 } , { three : 7 } ] ) ;
242
+ expect ( t . findValue ( 0 ) ) . to . deep . equal ( "blah" ) ;
243
+ expect ( t . findValue ( 1 ) ) . to . deep . equal ( 2 ) ;
244
+ expect ( t . findValue ( 2 ) ) . to . deep . equal ( 7 ) ;
245
+ expect ( t . findValue ( 'three' ) ) . to . deep . equal ( 7 ) ;
246
+ expect ( t . findValue ( 'two' ) ) . to . deep . equal ( 2 ) ;
247
+ expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
248
+ t . modifyVal ( 0 , "newBlah" ) ;
249
+ expect ( t . findValue ( 0 ) ) . to . deep . equal ( "newBlah" ) ;
250
+ expect ( t . findValue ( 1 ) ) . to . deep . equal ( 2 ) ;
251
+ expect ( t . findValue ( 2 ) ) . to . deep . equal ( 7 ) ;
252
+ expect ( t . findValue ( 'three' ) ) . to . deep . equal ( 7 ) ;
253
+ expect ( t . findValue ( 'two' ) ) . to . deep . equal ( 2 ) ;
254
+ expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
255
+ t . modifyVal ( 1 , 8 ) ;
256
+ expect ( t . findValue ( 0 ) ) . to . deep . equal ( "newBlah" ) ;
257
+ expect ( t . findValue ( 1 ) ) . to . deep . equal ( 8 ) ;
258
+ expect ( t . findValue ( 2 ) ) . to . deep . equal ( 7 ) ;
259
+ expect ( t . findValue ( 'three' ) ) . to . deep . equal ( 7 ) ;
260
+ expect ( t . findValue ( 'two' ) ) . to . deep . equal ( 8 ) ;
261
+ expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
262
+ // t.modifyVal("three",21);
263
+ // expect(t.findValue(0)).to.deep.equal("newBlah");
264
+ // expect(t.findValue(1)).to.deep.equal(8);
164
265
// 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);
266
+ // expect(t.findValue('three')).to.deep.equal(21);
267
+ // expect(t.findValue('two')).to.deep.equal(8);
168
268
// 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);
269
+ } ) ;
270
+
271
+ // it('should delete only the values requested', function () {
272
+ // t = new Tuple(["blah", {two: 2}, {three: 7}]);
273
+ // expect(t.findValue(0)).to.deep.equal("blah");
274
+ // expect(t.findValue(1)).to.deep.equal(2);
275
+ // expect(t.findValue(2)).to.deep.equal(7);
276
+ // expect(t.findValue('three')).to.deep.equal(7);
277
+ // expect(t.findValue('two')).to.deep.equal(2);
278
+ // expect(t.findValue(3)).to.deep.equal(undefined);
279
+ // t.deleteElement(0);
280
+ // expect(t.findValue(0)).to.deep.equal(undefined);
281
+ // expect(t.findValue(1)).to.deep.equal(2);
282
+ // expect(t.findValue('two')).to.deep.equal(2);
283
+ // expect(t.findValue(2)).to.deep.equal(7);
284
+ // expect(t.findValue('three')).to.deep.equal(7);
285
+ // expect(t.findValue(3)).to.deep.equal(undefined);
286
+ // t.deleteElement(1);
287
+ // expect(t.findValue(0)).to.deep.equal(undefined);
288
+ // expect(t.findValue(1)).to.deep.equal(undefined);
289
+ // expect(t.findValue('two')).to.deep.equal(undefined);
290
+ // expect(t.findValue(2)).to.deep.equal(7);
291
+ // expect(t.findValue('three')).to.deep.equal(7);
292
+ // expect(t.findValue(3)).to.deep.equal(undefined);
293
+ // t.deleteElement("three");
294
+ // expect(t.findValue(0)).to.deep.equal(undefined);
295
+ // expect(t.findValue(1)).to.deep.equal(undefined);
296
+ // expect(t.findValue('two')).to.deep.equal(undefined);
297
+ // expect(t.findValue(2)).to.deep.equal(undefined);
298
+ // expect(t.findValue('three')).to.deep.equal(undefined);
299
+ // expect(t.findValue(3)).to.deep.equal(undefined);
300
+ // });
301
+
302
+ it ( 'should not rename the key if passed incorrect arguments' , function ( ) {
303
+ t = new Tuple ( [ "blah" , { two : 2 } , { three : 7 } ] ) ;
304
+ expect ( t . findValue ( 0 ) ) . to . deep . equal ( "blah" ) ;
305
+ expect ( t . findValue ( 1 ) ) . to . deep . equal ( 2 ) ;
306
+ expect ( t . findValue ( 2 ) ) . to . deep . equal ( 7 ) ;
307
+ expect ( t . findValue ( 'three' ) ) . to . deep . equal ( 7 ) ;
308
+ expect ( t . findValue ( 'two' ) ) . to . deep . equal ( 2 ) ;
309
+ expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
310
+ t . renameElement ( 0 , 1 ) ;
311
+ expect ( t . findValue ( 0 ) ) . to . deep . equal ( "blah" ) ;
312
+ expect ( t . findValue ( 1 ) ) . to . deep . equal ( 2 ) ;
313
+ expect ( t . findValue ( 2 ) ) . to . deep . equal ( 7 ) ;
314
+ expect ( t . findValue ( 'three' ) ) . to . deep . equal ( 7 ) ;
315
+ expect ( t . findValue ( 'two' ) ) . to . deep . equal ( 2 ) ;
316
+ expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
317
+ t . renameElement ( 0 , "abc" ) ;
318
+ expect ( t . findValue ( 0 ) ) . to . deep . equal ( "blah" ) ;
319
+ expect ( t . findValue ( 1 ) ) . to . deep . equal ( 2 ) ;
320
+ expect ( t . findValue ( 2 ) ) . to . deep . equal ( 7 ) ;
321
+ expect ( t . findValue ( 'three' ) ) . to . deep . equal ( 7 ) ;
322
+ expect ( t . findValue ( 'two' ) ) . to . deep . equal ( 2 ) ;
323
+ expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
324
+ t . renameElement ( "abc" , 1 ) ;
325
+ expect ( t . findValue ( 0 ) ) . to . deep . equal ( "blah" ) ;
326
+ expect ( t . findValue ( 1 ) ) . to . deep . equal ( 2 ) ;
327
+ expect ( t . findValue ( 2 ) ) . to . deep . equal ( 7 ) ;
328
+ expect ( t . findValue ( 'three' ) ) . to . deep . equal ( 7 ) ;
329
+ expect ( t . findValue ( 'two' ) ) . to . deep . equal ( 2 ) ;
330
+ expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
331
+ t . renameElement ( "four" , "five" ) ;
332
+ expect ( t . findValue ( 0 ) ) . to . deep . equal ( "blah" ) ;
333
+ expect ( t . findValue ( 1 ) ) . to . deep . equal ( 2 ) ;
334
+ expect ( t . findValue ( 2 ) ) . to . deep . equal ( 7 ) ;
335
+ expect ( t . findValue ( 'three' ) ) . to . deep . equal ( 7 ) ;
336
+ expect ( t . findValue ( 'two' ) ) . to . deep . equal ( 2 ) ;
337
+ expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
338
+ expect ( t . findValue ( 'four' ) ) . to . deep . equal ( undefined ) ;
339
+ expect ( t . findValue ( 'five' ) ) . to . deep . equal ( undefined ) ;
171
340
} ) ;
172
341
173
342
it ( 'should rename the key if the correct arguments are passed in' , function ( ) {
@@ -188,4 +357,5 @@ describe('Tuple', function() {
188
357
expect ( t . findValue ( 3 ) ) . to . deep . equal ( undefined ) ;
189
358
} ) ;
190
359
191
- } ) ;
360
+ } ) ;
361
+
0 commit comments