1+ using NUnit . Framework ;
2+ using static Box2D . NET . B2ArenaAllocators ;
3+
4+ namespace Box2D . NET . Test ;
5+
6+ public class B2ArenaAllocatorTypedTests
7+ {
8+ [ Test ]
9+ public void Constructor_InitializesCorrectly ( )
10+ {
11+ B2ArenaAllocatorTyped < int > alloc = b2CreateArenaAllocator < int > ( 10 ) ;
12+ Assert . That ( alloc . capacity , Is . EqualTo ( 10 ) ) ;
13+ Assert . That ( alloc . data . Array , Is . Not . Null ) ;
14+ Assert . That ( alloc . data . Count , Is . EqualTo ( 10 ) ) ;
15+ Assert . That ( alloc . index , Is . EqualTo ( 0 ) ) ;
16+ Assert . That ( alloc . allocation , Is . EqualTo ( 0 ) ) ;
17+ Assert . That ( alloc . maxAllocation , Is . EqualTo ( 0 ) ) ;
18+ Assert . That ( alloc . entries . data , Is . Not . Null ) ;
19+ Assert . That ( alloc . entries . count , Is . EqualTo ( 0 ) ) ;
20+ Assert . That ( alloc . entries . capacity , Is . EqualTo ( 10 ) ) ;
21+ }
22+
23+ [ Test ]
24+ public void Grow_IncreasesCapacityWhenMaxAllocationExceedsCurrent ( )
25+ {
26+ B2ArenaAllocatorTyped < int > alloc = b2CreateArenaAllocator < int > ( 10 ) ;
27+
28+ alloc . maxAllocation = 15 ;
29+ int oldCapacity = alloc . capacity ;
30+ int newCapacity = alloc . Grow ( ) ;
31+
32+ Assert . That ( newCapacity , Is . GreaterThan ( oldCapacity ) ) ;
33+ Assert . That ( newCapacity , Is . EqualTo ( 15 + 15 / 2 ) ) ; // Check the growth factor
34+ Assert . That ( alloc . data . Count , Is . EqualTo ( newCapacity ) ) ;
35+ Assert . That ( alloc . allocation , Is . EqualTo ( 0 ) ) ; // Allocation should be 0 before grow
36+ }
37+
38+ [ Test ]
39+ public void Grow_DoesNotIncreaseCapacityWhenMaxAllocationIsWithinCurrent ( )
40+ {
41+ B2ArenaAllocatorTyped < int > alloc = b2CreateArenaAllocator < int > ( 10 ) ;
42+
43+ alloc . maxAllocation = 5 ;
44+ int oldCapacity = alloc . capacity ;
45+ int newCapacity = alloc . Grow ( ) ;
46+
47+ Assert . That ( newCapacity , Is . EqualTo ( oldCapacity ) ) ;
48+ Assert . That ( alloc . data . Count , Is . EqualTo ( newCapacity ) ) ;
49+ Assert . That ( alloc . allocation , Is . EqualTo ( 0 ) ) ; // Allocation should be 0 before grow
50+ }
51+
52+ [ Test ]
53+ public void Destroy_ReleasesResourcesAndResetsProperties ( )
54+ {
55+ B2ArenaAllocatorTyped < int > alloc = b2CreateArenaAllocator < int > ( 10 ) ;
56+
57+ alloc . Destroy ( ) ;
58+
59+ Assert . That ( alloc . data . Array , Is . Null ) ;
60+ Assert . That ( alloc . capacity , Is . EqualTo ( 0 ) ) ;
61+ Assert . That ( alloc . index , Is . EqualTo ( 0 ) ) ;
62+ Assert . That ( alloc . allocation , Is . EqualTo ( 0 ) ) ;
63+ Assert . That ( alloc . maxAllocation , Is . EqualTo ( 0 ) ) ;
64+ Assert . That ( alloc . entries . data , Is . Null ) ;
65+ Assert . That ( alloc . entries . count , Is . EqualTo ( 0 ) ) ;
66+ Assert . That ( alloc . entries . capacity , Is . EqualTo ( 0 ) ) ;
67+ }
68+ }
0 commit comments