11import { describe , it , expect } from "vitest" ;
2- import { MutatableRotatableArray } from "../src/index" ;
2+ import { RotatableMutatableArray } from "../src/index" ;
33
4- describe ( "MutatableRotatableArray " , ( ) => {
4+ describe ( "RotatableMutatableArray " , ( ) => {
55 it ( "throws on empty source array" , ( ) => {
6- expect ( ( ) => new MutatableRotatableArray ( [ ] ) ) . toThrowError ( / n o n - e m p t y / i) ;
6+ expect ( ( ) => new RotatableMutatableArray ( [ ] ) ) . toThrowError ( / n o n - e m p t y / i) ;
77 } ) ;
88
99 it ( "push/add appends without moving the cursor" , ( ) => {
10- const rot = new MutatableRotatableArray ( [ "A" , "B" ] ) ;
10+ const rot = new RotatableMutatableArray ( [ "A" , "B" ] ) ;
1111 rot . setIndex ( 1 ) ; // B
1212 expect ( rot . push ( "C" ) ) . toBe ( 3 ) ;
1313 expect ( rot . add ( "D" ) ) . toBe ( 4 ) ;
@@ -16,7 +16,7 @@ describe("MutatableRotatableArray", () => {
1616 } ) ;
1717
1818 it ( "next() reflects new items appended mid-rotation" , ( ) => {
19- const rot = new MutatableRotatableArray ( [ 1 , 2 , 3 ] ) ;
19+ const rot = new RotatableMutatableArray ( [ 1 , 2 , 3 ] ) ;
2020 expect ( rot . next ( ) ) . toBe ( 1 ) ;
2121 rot . push ( 4 ) ;
2222 rot . push ( 5 ) ;
@@ -28,21 +28,21 @@ describe("MutatableRotatableArray", () => {
2828 } ) ;
2929
3030 it ( "insert() before or at the cursor keeps the same current item" , ( ) => {
31- const rot = new MutatableRotatableArray ( [ "A" , "B" , "C" ] ) ;
31+ const rot = new RotatableMutatableArray ( [ "A" , "B" , "C" ] ) ;
3232 rot . setIndex ( 1 ) ; // B
3333 rot . insert ( 0 , "X" ) ;
3434 expect ( rot . peek ( ) ) . toBe ( "B" ) ;
3535 expect ( [ ...rot . cycle ( ) ] ) . toEqual ( [ "B" , "C" , "X" , "A" ] ) ;
3636
37- const rot2 = new MutatableRotatableArray ( [ "A" , "B" , "C" ] ) ;
37+ const rot2 = new RotatableMutatableArray ( [ "A" , "B" , "C" ] ) ;
3838 rot2 . setIndex ( 1 ) ; // B
3939 rot2 . insert ( 1 , "Y" ) ;
4040 expect ( rot2 . peek ( ) ) . toBe ( "B" ) ;
4141 expect ( [ ...rot2 . cycle ( ) ] ) . toEqual ( [ "B" , "C" , "A" , "Y" ] ) ;
4242 } ) ;
4343
4444 it ( "insert() after the cursor does not move the cursor" , ( ) => {
45- const rot = new MutatableRotatableArray ( [ "A" , "B" , "C" ] ) ;
45+ const rot = new RotatableMutatableArray ( [ "A" , "B" , "C" ] ) ;
4646 rot . setIndex ( 1 ) ; // B
4747 rot . insert ( 3 , "D" ) ; // append
4848 expect ( rot . peek ( ) ) . toBe ( "B" ) ;
@@ -54,7 +54,7 @@ describe("MutatableRotatableArray", () => {
5454 } ) ;
5555
5656 it ( "insert() at index 0 keeps the current item when cursor is 0" , ( ) => {
57- const rot = new MutatableRotatableArray ( [ "A" , "B" , "C" ] ) ;
57+ const rot = new RotatableMutatableArray ( [ "A" , "B" , "C" ] ) ;
5858 rot . setIndex ( 0 ) ; // A
5959 rot . insert ( 0 , "X" ) ;
6060 expect ( rot . peek ( ) ) . toBe ( "A" ) ;
@@ -66,7 +66,7 @@ describe("MutatableRotatableArray", () => {
6666 } ) ;
6767
6868 it ( "insert() returns the new length and allows index == length" , ( ) => {
69- const rot = new MutatableRotatableArray ( [ "A" ] ) ;
69+ const rot = new RotatableMutatableArray ( [ "A" ] ) ;
7070 expect ( rot . insert ( 1 , "B" ) ) . toBe ( 2 ) ;
7171 expect ( rot . length ) . toBe ( 2 ) ;
7272 expect ( rot . next ( ) ) . toBe ( "A" ) ;
@@ -75,28 +75,28 @@ describe("MutatableRotatableArray", () => {
7575 } ) ;
7676
7777 it ( "removeAt() shifts the cursor to keep the same current item" , ( ) => {
78- const rot = new MutatableRotatableArray ( [ "A" , "B" , "C" , "D" ] ) ;
78+ const rot = new RotatableMutatableArray ( [ "A" , "B" , "C" , "D" ] ) ;
7979 rot . setIndex ( 2 ) ; // C
8080 expect ( rot . removeAt ( 0 ) ) . toBe ( "A" ) ;
8181 expect ( rot . peek ( ) ) . toBe ( "C" ) ;
8282 expect ( [ ...rot . cycle ( ) ] ) . toEqual ( [ "C" , "D" , "B" ] ) ;
8383 } ) ;
8484
8585 it ( "removeAt() advances when removing the current item and wraps on last" , ( ) => {
86- const rot = new MutatableRotatableArray ( [ "A" , "B" , "C" ] ) ;
86+ const rot = new RotatableMutatableArray ( [ "A" , "B" , "C" ] ) ;
8787 rot . setIndex ( 1 ) ; // B
8888 expect ( rot . removeAt ( 1 ) ) . toBe ( "B" ) ;
8989 expect ( rot . peek ( ) ) . toBe ( "C" ) ;
9090 expect ( [ ...rot . cycle ( ) ] ) . toEqual ( [ "C" , "A" ] ) ;
9191
92- const rot2 = new MutatableRotatableArray ( [ "A" , "B" , "C" ] ) ;
92+ const rot2 = new RotatableMutatableArray ( [ "A" , "B" , "C" ] ) ;
9393 rot2 . setIndex ( 2 ) ; // C
9494 rot2 . removeAt ( 2 ) ;
9595 expect ( rot2 . peek ( ) ) . toBe ( "A" ) ;
9696 } ) ;
9797
9898 it ( "removeAt() after the cursor keeps the cursor position" , ( ) => {
99- const rot = new MutatableRotatableArray ( [ "A" , "B" , "C" , "D" ] ) ;
99+ const rot = new RotatableMutatableArray ( [ "A" , "B" , "C" , "D" ] ) ;
100100 rot . setIndex ( 1 ) ; // B
101101 expect ( rot . removeAt ( 3 ) ) . toBe ( "D" ) ;
102102 expect ( rot . peek ( ) ) . toBe ( "B" ) ;
@@ -107,7 +107,7 @@ describe("MutatableRotatableArray", () => {
107107 } ) ;
108108
109109 it ( "removeAt() on a 2-item array leaves the remaining item current" , ( ) => {
110- const rot = new MutatableRotatableArray ( [ "A" , "B" ] ) ;
110+ const rot = new RotatableMutatableArray ( [ "A" , "B" ] ) ;
111111 rot . setIndex ( 0 ) ; // A
112112 expect ( rot . removeAt ( 0 ) ) . toBe ( "A" ) ;
113113 expect ( rot . length ) . toBe ( 1 ) ;
@@ -117,12 +117,12 @@ describe("MutatableRotatableArray", () => {
117117 } ) ;
118118
119119 it ( "removeAt() throws when removing the last element" , ( ) => {
120- const rot = new MutatableRotatableArray ( [ "only" ] ) ;
120+ const rot = new RotatableMutatableArray ( [ "only" ] ) ;
121121 expect ( ( ) => rot . removeAt ( 0 ) ) . toThrowError ( / a t l e a s t o n e / i) ;
122122 } ) ;
123123
124124 it ( "validates indices for insert/remove" , ( ) => {
125- const rot = new MutatableRotatableArray ( [ "A" , "B" ] ) ;
125+ const rot = new RotatableMutatableArray ( [ "A" , "B" ] ) ;
126126 expect ( ( ) => rot . insert ( - 1 , "X" ) ) . toThrow ( RangeError ) ;
127127 expect ( ( ) => rot . insert ( 3 , "X" ) ) . toThrow ( RangeError ) ;
128128 expect ( ( ) => rot . insert ( 0.5 , "X" ) ) . toThrow ( RangeError ) ;
@@ -136,13 +136,13 @@ describe("MutatableRotatableArray", () => {
136136
137137 it ( "respects copy=true vs copy=false semantics" , ( ) => {
138138 const srcForCopy = [ 1 , 2 ] ;
139- const copied = new MutatableRotatableArray ( srcForCopy , true ) ;
139+ const copied = new RotatableMutatableArray ( srcForCopy , true ) ;
140140 copied . push ( 3 ) ;
141141 expect ( srcForCopy ) . toEqual ( [ 1 , 2 ] ) ;
142142 expect ( copied . toArray ( ) ) . toEqual ( [ 1 , 2 , 3 ] ) ;
143143
144144 const srcForShare = [ 1 , 2 ] ;
145- const shared = new MutatableRotatableArray ( srcForShare , false ) ;
145+ const shared = new RotatableMutatableArray ( srcForShare , false ) ;
146146 shared . push ( 3 ) ;
147147 expect ( srcForShare ) . toEqual ( [ 1 , 2 , 3 ] ) ;
148148 srcForShare . push ( 4 ) ;
0 commit comments