@@ -110,3 +110,59 @@ impl ChunkManager {
110
110
self . get_chunk ( chunk_position)
111
111
}
112
112
}
113
+
114
+ #[ cfg( test) ]
115
+ mod tests {
116
+ use super :: * ;
117
+
118
+ #[ test]
119
+ fn test_chunk_manager_new ( ) {
120
+ let chunk_manager = ChunkManager :: new ( ) ;
121
+ assert ! ( chunk_manager. chunks. is_empty( ) ) ;
122
+ }
123
+
124
+ #[ test]
125
+ fn test_instantiate_chunks ( ) {
126
+ let position = Vec3 :: new ( 0.0 , 0.0 , 0.0 ) ;
127
+ let render_distance = 2 ;
128
+ let chunks = ChunkManager :: instantiate_chunks ( position, render_distance) ;
129
+ assert_eq ! ( chunks. len( ) , ( render_distance * render_distance * render_distance) as usize ) ;
130
+ }
131
+
132
+ #[ test]
133
+ fn test_insert_chunks ( ) {
134
+ let mut chunk_manager = ChunkManager :: new ( ) ;
135
+ let position = Vec3 :: new ( 0.0 , 0.0 , 0.0 ) ;
136
+ let render_distance = 2 ;
137
+ let chunks = ChunkManager :: instantiate_chunks ( position, render_distance) ;
138
+
139
+ chunk_manager. insert_chunks ( chunks) ;
140
+ assert_eq ! ( chunk_manager. chunks. len( ) , ( render_distance * render_distance * render_distance) as usize ) ;
141
+ }
142
+
143
+ #[ test]
144
+ fn test_set_and_get_chunk ( ) {
145
+ let mut chunk_manager = ChunkManager :: new ( ) ;
146
+ let position = Vec3 :: new ( 0.0 , 0.0 , 0.0 ) ;
147
+ let chunk = Chunk :: new ( position) ;
148
+
149
+ chunk_manager. set_chunk ( position, chunk. clone ( ) ) ;
150
+ let retrieved_chunk = chunk_manager. get_chunk ( position) . unwrap ( ) ;
151
+ assert_eq ! ( retrieved_chunk. position, chunk. position) ;
152
+ }
153
+
154
+ #[ test]
155
+ fn test_set_and_get_block ( ) {
156
+ let mut chunk_manager = ChunkManager :: new ( ) ;
157
+ let position = Vec3 :: new ( 0.0 , 0.0 , 0.0 ) ;
158
+ let chunk = Chunk :: new ( position) ;
159
+
160
+ chunk_manager. set_chunk ( position, chunk) ;
161
+ let block_position = Vec3 :: new ( 1.0 , 1.0 , 1.0 ) ;
162
+ let block_id = BlockId :: Stone ;
163
+
164
+ chunk_manager. set_block ( block_position, block_id) ;
165
+ let retrieved_block = chunk_manager. get_block ( block_position) . unwrap ( ) ;
166
+ assert_eq ! ( retrieved_block, block_id) ;
167
+ }
168
+ }
0 commit comments