@@ -59,6 +59,7 @@ const describeStrategy = (description, strategy) => {
5959 expect ( callback ) . not . to . have . been . called
6060 } )
6161 } )
62+
6263 describe ( 'with some numbers' , function ( ) {
6364 beforeEach ( function ( ) {
6465 priv = new strategy ( {
@@ -212,6 +213,56 @@ const describeStrategy = (description, strategy) => {
212213 } )
213214 } )
214215
216+ describe ( 'with objects for which cmp(a, b) === 0 and a !== b' , function ( ) {
217+ beforeEach ( function ( ) {
218+ priv = new strategy ( {
219+ comparator : ( a , b ) => a . id - b . id
220+ } )
221+ // Insert in this order so binary tree isn't one-sided
222+ priv . insert ( { id : 2 } )
223+ priv . insert ( { id : 1 } )
224+ priv . insert ( { id : 3 } )
225+ } )
226+
227+ it ( 'should insert in the middle' , function ( ) {
228+ priv . insert ( { id : 2.5 } )
229+ expect ( priv . toArray ( ) ) . to . deep . eq ( [ { id : 1 } , { id : 2 } , { id : 2.5 } , { id : 3 } ] )
230+ } )
231+
232+ it ( 'should remove from the beginning' , function ( ) {
233+ priv . remove ( { id : 1 } )
234+ expect ( priv . toArray ( ) ) . to . deep . eq ( [ { id : 2 } , { id : 3 } ] )
235+ } )
236+
237+ it ( 'should remove from the end' , function ( ) {
238+ priv . remove ( { id : 3 } )
239+ expect ( priv . toArray ( ) ) . to . deep . eq ( [ { id : 1 } , { id : 2 } ] )
240+ } )
241+
242+ it ( 'should remove from the middle' , function ( ) {
243+ priv . remove ( { id : 2 } )
244+ expect ( priv . toArray ( ) ) . to . deep . eq ( [ { id : 1 } , { id : 3 } ] )
245+ } )
246+
247+ it ( 'should contain a middle value' , function ( ) {
248+ expect ( priv . contains ( { id : 2 } ) ) . to . eq ( true )
249+ } )
250+
251+ it ( 'should not contain a value in between two values' , function ( ) {
252+ expect ( priv . contains ( { id : 1.5 } ) ) . to . eq ( false )
253+ } )
254+
255+ it ( 'should find an iterator' , function ( ) {
256+ const iterator = priv . findIterator ( { id : 2 } )
257+ expect ( iterator . value ( ) ) . to . deep . eq ( { id : 2 } )
258+ } )
259+
260+ it ( 'should find an iterator between values' , function ( ) {
261+ const iterator = priv . findIterator ( { id : 1.5 } )
262+ expect ( iterator . value ( ) ) . to . deep . eq ( { id : 2 } )
263+ } )
264+ } )
265+
215266 describe ( 'with allowSetValue' , function ( ) {
216267 beforeEach ( function ( ) {
217268 priv = new strategy ( {
@@ -243,14 +294,8 @@ const describeStrategy = (description, strategy) => {
243294 }
244295 const onInsertConflict = SortedSet . OnInsertConflictThrow
245296 priv = new strategy ( { comparator, onInsertConflict } )
246- priv . insert ( {
247- v : 1 ,
248- q : 'a'
249- } )
250- priv . insert ( {
251- v : 2 ,
252- q : 'b'
253- } )
297+ priv . insert ( { v : 1 , q : 'a' } )
298+ priv . insert ( { v : 2 , q : 'b' } )
254299 } )
255300
256301 it ( 'should throw when inserting an element that matches another' , function ( ) {
@@ -266,30 +311,15 @@ const describeStrategy = (description, strategy) => {
266311 }
267312 onInsertConflict = SortedSet . OnInsertConflictReplace
268313 priv = new strategy ( { comparator, onInsertConflict } )
269- priv . insert ( {
270- v : 1 ,
271- q : 'a'
272- } )
273- priv . insert ( {
274- v : 2 ,
275- q : 'b'
276- } )
314+ priv . insert ( { v : 1 , q : 'a' } )
315+ priv . insert ( { v : 2 , q : 'b' } )
277316 } )
278317
279318 it ( 'should replace a matching element with the new element' , function ( ) {
280- priv . insert ( {
281- v : 1 ,
282- q : 'c'
283- } )
319+ priv . insert ( { v : 1 , q : 'c' } )
284320 expect ( priv . toArray ( ) ) . to . deep . eq ( [
285- {
286- v : 1 ,
287- q : 'c'
288- } ,
289- {
290- v : 2 ,
291- q : 'b'
292- }
321+ { v : 1 , q : 'c' } ,
322+ { v : 2 , q : 'b' }
293323 ] )
294324 } )
295325 } )
@@ -301,30 +331,15 @@ const describeStrategy = (description, strategy) => {
301331 }
302332 const onInsertConflict = SortedSet . OnInsertConflictIgnore
303333 priv = new strategy ( { comparator, onInsertConflict } )
304- priv . insert ( {
305- v : 1 ,
306- q : 'a'
307- } )
308- priv . insert ( {
309- v : 2 ,
310- q : 'b'
311- } )
334+ priv . insert ( { v : 1 , q : 'a' } )
335+ priv . insert ( { v : 2 , q : 'b' } )
312336 } )
313337
314338 it ( 'should ignore the new element when inserting an element that matches another ' , function ( ) {
315- priv . insert ( {
316- v : 1 ,
317- q : 'c'
318- } )
339+ priv . insert ( { v : 1 , q : 'c' } )
319340 expect ( priv . toArray ( ) ) . to . deep . eq ( [
320- {
321- v : 1 ,
322- q : 'a'
323- } ,
324- {
325- v : 2 ,
326- q : 'b'
327- }
341+ { v : 1 , q : 'a' } ,
342+ { v : 2 , q : 'b' }
328343 ] )
329344 } )
330345 } )
0 commit comments