Skip to content

Commit ab35df5

Browse files
committed
tests: added tests to the vec3 utils
1 parent dd0ae3d commit ab35df5

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/utils.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,34 @@ impl ChunkFromPosition for glam::Vec3 {
191191
);
192192
}
193193
}
194+
195+
mod tests {
196+
use crate::utils::{ChunkFromPosition, RelativeFromAbsolute};
197+
198+
#[test]
199+
fn should_get_the_correct_chunk_from_position_absolute() {
200+
let absolute_position = glam::vec3(17.0, 0.0, 20.0);
201+
assert_eq!(absolute_position.get_chunk_from_position_absolute(), (1, 1));
202+
let absolute_position = glam::vec3(32.0, 0.0, 20.0);
203+
assert_eq!(absolute_position.get_chunk_from_position_absolute(), (2, 1));
204+
let absolute_position = glam::vec3(-5.0, 0.0, -20.0);
205+
assert_eq!(
206+
absolute_position.get_chunk_from_position_absolute(),
207+
(-1, -2)
208+
); //
209+
}
210+
211+
#[test]
212+
fn should_get_the_correct_relative_position() {
213+
let absolute_position = glam::vec3(17.0, 0.0, 20.0); // Since there are 16 blocks 0->15, the next chunk will start from 16->31
214+
assert_eq!(
215+
absolute_position.relative_from_absolute(),
216+
glam::vec3(1.0, 0.0, 4.0)
217+
);
218+
let absolute_position = glam::vec3(-1.0, 0.0, -1.0);
219+
assert_eq!(
220+
absolute_position.relative_from_absolute(),
221+
glam::vec3(15.0, 0.0, 15.0)
222+
);
223+
}
224+
}

0 commit comments

Comments
 (0)