55 ComponentIdManager ,
66 createComponentId ,
77 createEntityId ,
8- createRelationId ,
8+ relation ,
99 decodeRelationId ,
1010 ENTITY_ID_START ,
1111 EntityIdManager ,
@@ -38,7 +38,7 @@ describe("Entity ID System", () => {
3838 expect ( isComponentId ( createComponentId ( 2 ) ) ) . toBe ( true ) ;
3939 expect ( isComponentId ( createComponentId ( COMPONENT_ID_MAX ) ) ) . toBe ( true ) ;
4040 expect ( isComponentId ( createEntityId ( ENTITY_ID_START ) ) ) . toBe ( false ) ;
41- expect ( isComponentId ( createRelationId ( createComponentId ( 1 ) , createEntityId ( ENTITY_ID_START ) ) ) ) . toBe ( false ) ;
41+ expect ( isComponentId ( relation ( createComponentId ( 1 ) , createEntityId ( ENTITY_ID_START ) ) ) ) . toBe ( false ) ;
4242 } ) ;
4343 } ) ;
4444
@@ -58,15 +58,15 @@ describe("Entity ID System", () => {
5858 expect ( isEntityId ( createEntityId ( ENTITY_ID_START ) ) ) . toBe ( true ) ;
5959 expect ( isEntityId ( createEntityId ( 10000 ) ) ) . toBe ( true ) ;
6060 expect ( isEntityId ( createComponentId ( 1 ) ) ) . toBe ( false ) ;
61- expect ( isEntityId ( createRelationId ( createComponentId ( 1 ) , createEntityId ( ENTITY_ID_START ) ) ) ) . toBe ( false ) ;
61+ expect ( isEntityId ( relation ( createComponentId ( 1 ) , createEntityId ( ENTITY_ID_START ) ) ) ) . toBe ( false ) ;
6262 } ) ;
6363 } ) ;
6464
6565 describe ( "Relation IDs" , ( ) => {
6666 it ( "should create valid relation IDs with entities" , ( ) => {
6767 const compId = createComponentId ( 5 ) ;
6868 const entId = createEntityId ( ENTITY_ID_START + 10 ) ;
69- const relationId = createRelationId ( compId , entId ) ;
69+ const relationId = relation ( compId , entId ) ;
7070
7171 expect ( relationId ) . toBeLessThan ( 0 ) ;
7272 expect ( isRelationId ( relationId ) ) . toBe ( true ) ;
@@ -75,25 +75,23 @@ describe("Entity ID System", () => {
7575 it ( "should create valid relation IDs with components" , ( ) => {
7676 const compId1 = createComponentId ( 5 ) ;
7777 const compId2 = createComponentId ( 10 ) ;
78- const relationId = createRelationId ( compId1 , compId2 ) ;
78+ const relationId = relation ( compId1 , compId2 ) ;
7979
8080 expect ( relationId ) . toBeLessThan ( 0 ) ;
8181 expect ( isRelationId ( relationId ) ) . toBe ( true ) ;
8282 } ) ;
8383
8484 it ( "should reject invalid relation creation" , ( ) => {
8585 const entId = createEntityId ( ENTITY_ID_START ) ;
86- expect ( ( ) => createRelationId ( 1024 as EntityId , entId ) ) . toThrow ( ) ; // invalid component id
87- expect ( ( ) => createRelationId ( createComponentId ( 5 ) , - 1 as EntityId ) ) . toThrow ( ) ; // invalid target id
88- expect ( ( ) =>
89- createRelationId ( createComponentId ( 5 ) , createRelationId ( createComponentId ( 1 ) , createEntityId ( 1025 ) ) ) ,
90- ) . toThrow ( ) ; // relation as target
86+ expect ( ( ) => relation ( 1024 as EntityId , entId ) ) . toThrow ( ) ; // invalid component id
87+ expect ( ( ) => relation ( createComponentId ( 5 ) , - 1 as EntityId ) ) . toThrow ( ) ; // invalid target id
88+ expect ( ( ) => relation ( createComponentId ( 5 ) , relation ( createComponentId ( 1 ) , createEntityId ( 1025 ) ) ) ) . toThrow ( ) ; // relation as target
9189 } ) ;
9290
9391 it ( "should decode relation IDs with entities correctly" , ( ) => {
9492 const compId = createComponentId ( 42 ) ;
9593 const entId = createEntityId ( ENTITY_ID_START + 123 ) ;
96- const relationId = createRelationId ( compId , entId ) ;
94+ const relationId = relation ( compId , entId ) ;
9795
9896 const decoded = decodeRelationId ( relationId ) ;
9997 expect ( decoded . componentId ) . toBe ( compId ) ;
@@ -104,7 +102,7 @@ describe("Entity ID System", () => {
104102 it ( "should decode relation IDs with components correctly" , ( ) => {
105103 const compId1 = createComponentId ( 42 ) ;
106104 const compId2 = createComponentId ( 100 ) ;
107- const relationId = createRelationId ( compId1 , compId2 ) ;
105+ const relationId = relation ( compId1 , compId2 ) ;
108106
109107 const decoded = decodeRelationId ( relationId ) ;
110108 expect ( decoded . componentId ) . toBe ( compId1 ) ;
@@ -114,17 +112,17 @@ describe("Entity ID System", () => {
114112
115113 it ( "should create valid wildcard relation IDs" , ( ) => {
116114 const compId = createComponentId ( 5 ) ;
117- const relationId = createRelationId ( compId , "*" ) ;
115+ const relationId = relation ( compId , "*" ) ;
118116
119117 expect ( relationId ) . toBeLessThan ( 0 ) ;
120118 expect ( isRelationId ( relationId ) ) . toBe ( true ) ;
121119 } ) ;
122120
123121 it ( "should identify wildcard relation IDs correctly" , ( ) => {
124122 const compId = createComponentId ( 5 ) ;
125- const wildcardRelationId = createRelationId ( compId , "*" ) ;
126- const entityRelationId = createRelationId ( compId , createEntityId ( ENTITY_ID_START ) ) ;
127- const componentRelationId = createRelationId ( compId , createComponentId ( 10 ) ) ;
123+ const wildcardRelationId = relation ( compId , "*" ) ;
124+ const entityRelationId = relation ( compId , createEntityId ( ENTITY_ID_START ) ) ;
125+ const componentRelationId = relation ( compId , createComponentId ( 10 ) ) ;
128126 const entityId = createEntityId ( ENTITY_ID_START ) ;
129127 const componentId = createComponentId ( 1 ) ;
130128
@@ -137,7 +135,7 @@ describe("Entity ID System", () => {
137135
138136 it ( "should decode wildcard relation IDs correctly" , ( ) => {
139137 const compId = createComponentId ( 42 ) ;
140- const relationId = createRelationId ( compId , "*" ) ;
138+ const relationId = relation ( compId , "*" ) ;
141139
142140 const decoded = decodeRelationId ( relationId ) ;
143141 expect ( decoded . componentId ) . toBe ( compId ) ;
@@ -152,11 +150,9 @@ describe("Entity ID System", () => {
152150 expect ( getIdType ( createComponentId ( 500 ) ) ) . toBe ( "component" ) ;
153151 expect ( getIdType ( createEntityId ( ENTITY_ID_START ) ) ) . toBe ( "entity" ) ;
154152 expect ( getIdType ( createEntityId ( 10000 ) ) ) . toBe ( "entity" ) ;
155- expect ( getIdType ( createRelationId ( createComponentId ( 1 ) , createEntityId ( ENTITY_ID_START ) ) ) ) . toBe (
156- "entity-relation" ,
157- ) ;
158- expect ( getIdType ( createRelationId ( createComponentId ( 1 ) , createComponentId ( 2 ) ) ) ) . toBe ( "component-relation" ) ;
159- expect ( getIdType ( createRelationId ( createComponentId ( 1 ) , "*" ) ) ) . toBe ( "wildcard-relation" ) ;
153+ expect ( getIdType ( relation ( createComponentId ( 1 ) , createEntityId ( ENTITY_ID_START ) ) ) ) . toBe ( "entity-relation" ) ;
154+ expect ( getIdType ( relation ( createComponentId ( 1 ) , createComponentId ( 2 ) ) ) ) . toBe ( "component-relation" ) ;
155+ expect ( getIdType ( relation ( createComponentId ( 1 ) , "*" ) ) ) . toBe ( "wildcard-relation" ) ;
160156
161157 // Invalid IDs
162158 expect ( getIdType ( INVALID_COMPONENT_ID as EntityId ) ) . toBe ( "invalid" ) ;
@@ -177,21 +173,21 @@ describe("Entity ID System", () => {
177173 expect ( entityResult . targetId ) . toBeUndefined ( ) ;
178174
179175 // Entity relation
180- const entityRelationId = createRelationId ( createComponentId ( 5 ) , createEntityId ( ENTITY_ID_START + 200 ) ) ;
176+ const entityRelationId = relation ( createComponentId ( 5 ) , createEntityId ( ENTITY_ID_START + 200 ) ) ;
181177 const entityRelationResult = getDetailedIdType ( entityRelationId ) ;
182178 expect ( entityRelationResult . type ) . toBe ( "entity-relation" ) ;
183179 expect ( entityRelationResult . componentId ) . toBe ( createComponentId ( 5 ) ) ;
184180 expect ( entityRelationResult . targetId ) . toBe ( createEntityId ( ENTITY_ID_START + 200 ) ) ;
185181
186182 // Component relation
187- const compRelationId = createRelationId ( createComponentId ( 10 ) , createComponentId ( 20 ) ) ;
183+ const compRelationId = relation ( createComponentId ( 10 ) , createComponentId ( 20 ) ) ;
188184 const compRelationResult = getDetailedIdType ( compRelationId ) ;
189185 expect ( compRelationResult . type ) . toBe ( "component-relation" ) ;
190186 expect ( compRelationResult . componentId ) . toBe ( createComponentId ( 10 ) ) ;
191187 expect ( compRelationResult . targetId ) . toBe ( createComponentId ( 20 ) ) ;
192188
193189 // Wildcard relation
194- const wildcardRelationId = createRelationId ( createComponentId ( 15 ) , "*" ) ;
190+ const wildcardRelationId = relation ( createComponentId ( 15 ) , "*" ) ;
195191 const wildcardRelationResult = getDetailedIdType ( wildcardRelationId ) ;
196192 expect ( wildcardRelationResult . type ) . toBe ( "wildcard-relation" ) ;
197193 expect ( wildcardRelationResult . componentId ) . toBe ( createComponentId ( 15 ) ) ;
@@ -229,15 +225,15 @@ describe("Entity ID System", () => {
229225 it ( "should inspect relation IDs with entities" , ( ) => {
230226 const compId = createComponentId ( 5 ) ;
231227 const entId = createEntityId ( ENTITY_ID_START + 10 ) ;
232- const relationId = createRelationId ( compId , entId ) ;
228+ const relationId = relation ( compId , entId ) ;
233229
234230 expect ( inspectEntityId ( relationId ) ) . toBe ( "Relation ID: Component ID (5) -> Entity ID (1034)" ) ;
235231 } ) ;
236232
237233 it ( "should inspect relation IDs with components" , ( ) => {
238234 const compId1 = createComponentId ( 10 ) ;
239235 const compId2 = createComponentId ( 20 ) ;
240- const relationId = createRelationId ( compId1 , compId2 ) ;
236+ const relationId = relation ( compId1 , compId2 ) ;
241237
242238 expect ( inspectEntityId ( relationId ) ) . toBe ( "Relation ID: Component ID (10) -> Component ID (20)" ) ;
243239 } ) ;
@@ -250,7 +246,7 @@ describe("Entity ID System", () => {
250246
251247 it ( "should inspect wildcard relation IDs" , ( ) => {
252248 const compId = createComponentId ( 15 ) ;
253- const relationId = createRelationId ( compId , "*" ) ;
249+ const relationId = relation ( compId , "*" ) ;
254250
255251 expect ( inspectEntityId ( relationId ) ) . toBe ( "Relation ID: Component ID (15) -> Wildcard (*)" ) ;
256252 } ) ;
@@ -263,7 +259,7 @@ describe("Entity ID System", () => {
263259 expect ( Number . isSafeInteger ( largeEntityId ) ) . toBe ( true ) ;
264260
265261 const compId = createComponentId ( 1023 ) ;
266- const relationId = createRelationId ( compId , largeEntityId as EntityId ) ;
262+ const relationId = relation ( compId , largeEntityId as EntityId ) ;
267263 expect ( Number . isSafeInteger ( relationId ) ) . toBe ( true ) ;
268264
269265 const decoded = decodeRelationId ( relationId ) ;
@@ -309,7 +305,7 @@ describe("EntityIdManager", () => {
309305 const manager = new EntityIdManager ( ) ;
310306 expect ( ( ) => manager . deallocate ( 1000 as EntityId ) ) . toThrow ( ) ; // Below ENTITY_ID_START
311307 expect ( ( ) => manager . deallocate ( createComponentId ( 5 ) ) ) . toThrow ( ) ; // Component ID
312- expect ( ( ) => manager . deallocate ( createRelationId ( createComponentId ( 1 ) , createEntityId ( 1025 ) ) ) ) . toThrow ( ) ; // Relation ID
308+ expect ( ( ) => manager . deallocate ( relation ( createComponentId ( 1 ) , createEntityId ( 1025 ) ) ) ) . toThrow ( ) ; // Relation ID
313309 } ) ;
314310
315311 it ( "should reject deallocation of unallocated IDs" , ( ) => {
0 commit comments