@@ -90,7 +90,7 @@ if (arrays_match_1.arraysMatch(arr.insert.data, arr.data))
90
90
else
91
91
console . log ( 'test 6A FAILED' ) ;
92
92
// Test 6B: arr.data must remain in-sync with arr.insert.data after calling an arr.insert method:
93
- arr . insert . at ( 1 , [ 'h' ] ) ;
93
+ arr . insert . at ( 1 , [ 'h' , 'j' ] ) ;
94
94
if ( arrays_match_1 . arraysMatch ( arr . insert . data , arr . data ) )
95
95
console . log ( 'test 6B passed' ) ;
96
96
else
@@ -111,6 +111,132 @@ if (arrays_match_1.arraysMatch(arr.remove.data, arr.data))
111
111
console . log ( 'test 7B passed' ) ;
112
112
else
113
113
console . log ( 'test 7B FAILED' ) ;
114
+ // Test 8: arr.replace must be instance of PublicArrayReplacer:
115
+ if ( arr . replace . className && arr . replace . className === 'PublicArrayReplacer' )
116
+ console . log ( 'test 8 passed' ) ;
117
+ else
118
+ console . log ( 'test 8 FAILED' ) ;
119
+ // Test 8A: arr.replace.data must match arr.data:
120
+ if ( arrays_match_1 . arraysMatch ( arr . replace . data , arr . data ) )
121
+ console . log ( 'test 8A passed' ) ;
122
+ else
123
+ console . log ( 'test 8A FAILED' ) ;
124
+ // Test 8B: arr.data must remain in-sync with arr.replace.data after calling an arr.replace method:
125
+ arr . replace . firstOf ( 'j' , 'J' ) ;
126
+ if ( arrays_match_1 . arraysMatch ( arr . replace . data , arr . data ) )
127
+ console . log ( 'test 8B passed' ) ;
128
+ else
129
+ console . log ( 'test 8B FAILED' ) ;
130
+ // Test 9: arr.sort must be instance of PublicArraySorter:
131
+ if ( arr . sort . className && arr . sort . className === 'PublicArraySorter' )
132
+ console . log ( 'test 9 passed' ) ;
133
+ else
134
+ console . log ( 'test 9 FAILED' ) ;
135
+ // Test 9A: arr.sort.data must match arr.data:
136
+ if ( arrays_match_1 . arraysMatch ( arr . sort . data , arr . data ) )
137
+ console . log ( 'test 9A passed' ) ;
138
+ else
139
+ console . log ( 'test 9A FAILED' ) ;
140
+ // Test 9B: arr.data must remain in-sync with arr.sort.data after calling an arr.sort method:
141
+ arr . sort . alphabetize ( ) ;
142
+ if ( arrays_match_1 . arraysMatch ( arr . sort . data , arr . data ) )
143
+ console . log ( 'test 9B passed' ) ;
144
+ else
145
+ console . log ( 'test 9B FAILED' ) ;
146
+ // Test 10: make sure .copy property is copy of the arr instance:
114
147
var copy = arr . copy ;
115
- copy . data = [ 'j' ] ;
116
- console . log ( arr . data ) ;
148
+ if ( copy . className && copy . className === 'PublicArray' && arrays_match_1 . arraysMatch ( copy . data , arr . data ) &&
149
+ copy . filter && copy . getAndRemove )
150
+ console . log ( 'test 10 passed' ) ;
151
+ else
152
+ console . log ( 'test 10 FAILED' ) ;
153
+ // Test 10A: make sure copy.data is not linked with arr.data:
154
+ copy . data . push ( 'blah' ) ;
155
+ if ( arrays_match_1 . arraysMatch ( copy . data , arr . data ) )
156
+ console . log ( 'test 10A FAILED' ) ;
157
+ else
158
+ console . log ( 'test 10A passed' ) ;
159
+ // Test 11: make sure .append() works:
160
+ arr . append ( [ 'blah' , 'goo' ] ) ;
161
+ if ( arr . data [ arr . data . length - 1 ] === 'goo' && arr . data [ arr . data . length - 2 ] === 'blah' )
162
+ console . log ( 'test 11 passed' ) ;
163
+ else
164
+ console . log ( 'test 11 FAILED' ) ;
165
+ // Test 12: make sure .prepend() works:
166
+ arr . prepend ( [ 'ccc' , 'ddd' ] ) ;
167
+ if ( arr . data [ 0 ] === 'ccc' && arr . data [ 1 ] === 'ddd' )
168
+ console . log ( 'test 12 passed' ) ;
169
+ else
170
+ console . log ( 'test 12 FAILED' ) ;
171
+ // Test 13: make sure .forEach() lets you access the current item, its index, and entire array:
172
+ arr . data = [ 'a' , 'b' , 'c' , 'd' ] ;
173
+ var allData = [ ] ;
174
+ arr . forEach ( function ( item , index , theArr ) {
175
+ allData . push ( [ item , index , theArr ] ) ;
176
+ } ) ;
177
+ if ( arrays_match_1 . arraysMatch ( allData , [
178
+ [ 'a' , 0 , [ 'a' , 'b' , 'c' , 'd' ] ] , [ 'b' , 1 , [ 'a' , 'b' , 'c' , 'd' ] ] ,
179
+ [ 'c' , 2 , [ 'a' , 'b' , 'c' , 'd' ] ] , [ 'd' , 3 , [ 'a' , 'b' , 'c' , 'd' ] ]
180
+ ] ) )
181
+ console . log ( 'test 13 passed' ) ;
182
+ else
183
+ console . log ( 'test 13 FAILED' ) ;
184
+ // Test 13A: make sure .forEach() allows you to change the values of each item:
185
+ arr . forEach ( function ( item , index , theArr ) {
186
+ theArr [ index ] = index ;
187
+ } ) ;
188
+ if ( arrays_match_1 . arraysMatch ( arr . data , [ 0 , 1 , 2 , 3 ] ) )
189
+ console . log ( 'test 13A passed' ) ;
190
+ else
191
+ console . log ( 'test 13A FAILED' ) ;
192
+ // Test 14: make sure .set() changes value of arr.data without breaking memory reference:
193
+ var dataCopy = arr . data ;
194
+ arr . set ( [ 6 , 7 , 8 , 9 ] ) ;
195
+ if ( arrays_match_1 . arraysMatch ( arr . data , [ 6 , 7 , 8 , 9 ] ) && arrays_match_1 . arraysMatch ( arr . data , dataCopy ) )
196
+ console . log ( 'test 14 passed' ) ;
197
+ else
198
+ console . log ( 'test 14 FAILED' ) ;
199
+ // Test 15: check .notEmpty property:
200
+ if ( arr . notEmpty )
201
+ console . log ( 'test 15 passed' ) ;
202
+ else
203
+ console . log ( 'test 15 FAILED' ) ;
204
+ // Test 16: check .isEmpty property:
205
+ if ( arr . isEmpty )
206
+ console . log ( 'test 16 FAILED' ) ;
207
+ else
208
+ console . log ( 'test 16 passed' ) ;
209
+ // Test 17: check .length property:
210
+ if ( arr . length === 4 )
211
+ console . log ( 'test 17 passed' ) ;
212
+ else
213
+ console . log ( 'test 17 FAILED' ) ;
214
+ // Test 18: make sure .length is writable:
215
+ arr . length = 1 ;
216
+ if ( arrays_match_1 . arraysMatch ( arr . data , [ 6 ] ) )
217
+ console . log ( 'test 18 passed' ) ;
218
+ else
219
+ console . log ( 'test 18 FAILED' ) ;
220
+ // Test 19: make sure .asString() works:
221
+ arr . data = [ 1 , 2 , 3 , 4 , 5 ] ;
222
+ var str = arr . asString ( '-' ) ;
223
+ if ( str === '1-2-3-4-5' )
224
+ console . log ( 'test 19 passed' ) ;
225
+ else
226
+ console . log ( 'test 19 FAILED' ) ;
227
+ // Test 20: make sure .matches() works:
228
+ if ( arr . matches ( [ 1 , 2 , 3 , 4 , 5 ] ) )
229
+ console . log ( 'test 20 passed' ) ;
230
+ else
231
+ console . log ( 'test 20 FAILED' ) ;
232
+ // Test 21: make sure .has() works:
233
+ if ( arr . has ( 4 ) )
234
+ console . log ( 'test 21 passed' ) ;
235
+ else
236
+ console . log ( 'test 21 FAILED' ) ;
237
+ // Test 22: make sure .indexesThatPass() works:
238
+ var indexes = arr . indexesThatPass ( function ( item ) { return ( item % 2 === 0 ) ; } ) ;
239
+ if ( arrays_match_1 . arraysMatch ( indexes , [ 1 , 3 ] ) )
240
+ console . log ( 'test 22 passed' ) ;
241
+ else
242
+ console . log ( 'test 22 FAILED' ) ;
0 commit comments