@@ -5,21 +5,19 @@ describe("RotatableSet", () => {
55 it ( "starts empty and throws on next/furthest/peek" , ( ) => {
66 const ring = new RotatableSet < number > ( ) ;
77 expect ( ring . size ) . toBe ( 0 ) ;
8- expect ( ring . length ) . toBe ( 0 ) ;
98 expect ( ring . isEmpty ) . toBe ( true ) ;
109 expect ( ( ) => ring . next ( ) ) . toThrowError ( / e m p t y / i) ;
1110 expect ( ( ) => ring . getFurthestItem ( ) ) . toThrowError ( / e m p t y / i) ;
1211 expect ( ( ) => ring . peek ( ) ) . toThrowError ( / e m p t y / i) ;
13- expect ( ring . removeItem ( 1 ) ) . toBe ( false ) ;
12+ expect ( ring . delete ( 1 ) ) . toBe ( false ) ;
1413 expect ( [ ...ring . cycle ( ) ] ) . toEqual ( [ ] ) ;
1514 expect ( Array . from ( ring . toSet ( ) ) ) . toEqual ( [ ] ) ;
1615 } ) ;
1716
1817 it ( "preserves insertion order when adding to empty ring" , ( ) => {
1918 const ring = new RotatableSet < number > ( ) ;
20- expect ( ring . addItem ( 1 ) ) . toBe ( true ) ;
21- expect ( ring . addItem ( 2 ) ) . toBe ( true ) ;
22- expect ( ring . addItem ( 3 ) ) . toBe ( true ) ;
19+ ring . add ( 1 ) . add ( 2 ) . add ( 3 ) ;
20+ expect ( ring . size ) . toBe ( 3 ) ;
2321 expect ( ring . toArray ( ) ) . toEqual ( [ 1 , 2 , 3 ] ) ;
2422 expect ( ring . next ( ) ) . toBe ( 1 ) ;
2523 expect ( ring . next ( ) ) . toBe ( 2 ) ;
@@ -42,25 +40,25 @@ describe("RotatableSet", () => {
4240 expect ( ring . toArray ( ) ) . toEqual ( [ 1 , 2 , 3 ] ) ;
4341 } ) ;
4442
45- it ( "addItem does not move the cursor" , ( ) => {
43+ it ( "add does not move the cursor" , ( ) => {
4644 const ring = new RotatableSet ( [ 1 , 2 , 3 ] ) ;
4745 ring . next ( ) ; // 1, cursor at 2
48- ring . addItem ( 4 ) ;
46+ ring . add ( 4 ) ;
4947 expect ( ring . peek ( ) ) . toBe ( 2 ) ;
5048 expect ( ring . toArray ( ) ) . toEqual ( [ 2 , 3 , 1 , 4 ] ) ;
5149 expect ( ring . next ( ) ) . toBe ( 2 ) ;
5250 } ) ;
5351
54- it ( "addItem returns false for existing items and keeps state unchanged" , ( ) => {
52+ it ( "adding an existing item keeps state unchanged" , ( ) => {
5553 const ring = new RotatableSet ( [ 1 , 2 , 3 ] ) ;
5654 ring . next ( ) ; // 1, cursor at 2
57- expect ( ring . addItem ( 2 ) ) . toBe ( false ) ;
55+ ring . add ( 2 ) ; // duplicate
5856 expect ( ring . size ) . toBe ( 3 ) ;
5957 expect ( ring . peek ( ) ) . toBe ( 2 ) ;
6058 expect ( ring . toArray ( ) ) . toEqual ( [ 2 , 3 , 1 ] ) ;
6159 } ) ;
6260
63- it ( "add() matches Set semantics and is an alias for addItem " , ( ) => {
61+ it ( "add() matches Set semantics" , ( ) => {
6462 const ring = new RotatableSet < number > ( ) ;
6563 const ret = ring . add ( 1 ) . add ( 2 ) ;
6664 expect ( ret ) . toBe ( ring ) ;
@@ -121,19 +119,19 @@ describe("RotatableSet", () => {
121119 expect ( [ ...ring . cycle ( ) ] ) . toEqual ( [ "only" ] ) ;
122120 } ) ;
123121
124- it ( "removeItem removes items and maintains cursor" , ( ) => {
122+ it ( "delete removes items and maintains cursor" , ( ) => {
125123 const ring = new RotatableSet ( [ 1 , 2 , 3 ] ) ;
126124 ring . next ( ) ; // 1, cursor at 2
127- expect ( ring . removeItem ( 2 ) ) . toBe ( true ) ; // remove current
125+ expect ( ring . delete ( 2 ) ) . toBe ( true ) ; // remove current
128126 expect ( ring . peek ( ) ) . toBe ( 3 ) ;
129127 expect ( ring . size ) . toBe ( 2 ) ;
130128 expect ( [ ...ring . cycle ( ) ] ) . toEqual ( [ 3 , 1 ] ) ;
131129
132- expect ( ring . removeItem ( 99 ) ) . toBe ( false ) ;
130+ expect ( ring . delete ( 99 ) ) . toBe ( false ) ;
133131 expect ( ring . size ) . toBe ( 2 ) ;
134132 } ) ;
135133
136- it ( "delete() matches Set semantics and is an alias for removeItem " , ( ) => {
134+ it ( "delete() matches Set semantics" , ( ) => {
137135 const ring = new RotatableSet ( [ 1 , 2 , 3 ] ) ;
138136 expect ( ring . delete ( 2 ) ) . toBe ( true ) ;
139137 expect ( ring . delete ( 2 ) ) . toBe ( false ) ;
@@ -144,24 +142,24 @@ describe("RotatableSet", () => {
144142 it ( "removing current from a 2-item set leaves the other item current" , ( ) => {
145143 const ring = new RotatableSet ( [ "A" , "B" ] ) ;
146144 ring . next ( ) ; // A, cursor at B
147- expect ( ring . removeItem ( "B" ) ) . toBe ( true ) ;
145+ expect ( ring . delete ( "B" ) ) . toBe ( true ) ;
148146 expect ( ring . size ) . toBe ( 1 ) ;
149147 expect ( ring . peek ( ) ) . toBe ( "A" ) ;
150148 expect ( ring . getFurthestItem ( ) ) . toBe ( "A" ) ;
151149 } ) ;
152150
153- it ( "removeItem of a non-current item does not move the cursor" , ( ) => {
151+ it ( "deleting a non-current item does not move the cursor" , ( ) => {
154152 const ring = new RotatableSet ( [ 1 , 2 , 3 , 4 ] ) ;
155153 ring . next ( ) ; // 1, cursor at 2
156- expect ( ring . removeItem ( 4 ) ) . toBe ( true ) ;
154+ expect ( ring . delete ( 4 ) ) . toBe ( true ) ;
157155 expect ( ring . peek ( ) ) . toBe ( 2 ) ;
158156 expect ( ring . toArray ( ) ) . toEqual ( [ 2 , 3 , 1 ] ) ;
159157 expect ( ring . getFurthestItem ( ) ) . toBe ( 1 ) ;
160158 } ) ;
161159
162- it ( "enforces uniqueness on addItem " , ( ) => {
160+ it ( "enforces uniqueness on add " , ( ) => {
163161 const ring = new RotatableSet ( [ 1 , 2 , 3 ] ) ;
164- expect ( ring . addItem ( 2 ) ) . toBe ( false ) ;
162+ ring . add ( 2 ) ;
165163 expect ( ring . size ) . toBe ( 3 ) ;
166164 expect ( ring . toArray ( ) ) . toEqual ( [ 1 , 2 , 3 ] ) ;
167165 } ) ;
@@ -178,11 +176,11 @@ describe("RotatableSet", () => {
178176
179177 it ( "removing the last item resets ring and allows fresh adds" , ( ) => {
180178 const ring = new RotatableSet < number > ( [ 10 ] ) ;
181- expect ( ring . removeItem ( 10 ) ) . toBe ( true ) ;
179+ expect ( ring . delete ( 10 ) ) . toBe ( true ) ;
182180 expect ( ring . size ) . toBe ( 0 ) ;
183181 expect ( ( ) => ring . next ( ) ) . toThrowError ( / e m p t y / i) ;
184- ring . addItem ( 20 ) ;
185- ring . addItem ( 30 ) ;
182+ ring . add ( 20 ) ;
183+ ring . add ( 30 ) ;
186184 expect ( ring . toArray ( ) ) . toEqual ( [ 20 , 30 ] ) ;
187185 expect ( ring . next ( ) ) . toBe ( 20 ) ;
188186 } ) ;
0 commit comments