2026-08-26 17:53:09 +03:00
|
|
|
#[cfg(test)]
|
|
|
|
|
mod mod_tests {
|
|
|
|
|
use crate::data::Id;
|
|
|
|
|
use crate::data::entities::{EntityData, EntityHandle};
|
|
|
|
|
use crate::data::repositories::fast_position_of;
|
|
|
|
|
|
|
|
|
|
struct ProtoEntity {
|
|
|
|
|
id: Id,
|
|
|
|
|
_data: i128,
|
|
|
|
|
}
|
|
|
|
|
impl EntityData for ProtoEntity {
|
|
|
|
|
fn id(&self) -> Id {
|
|
|
|
|
self.id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn set_id(&mut self, id: Id) {
|
|
|
|
|
self.id = id;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ProtoEntity {
|
|
|
|
|
fn new(n: i128) -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
id: (n as u32).into(),
|
|
|
|
|
_data: n,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn search_direct() {
|
2026-08-29 22:41:11 +03:00
|
|
|
let mut entity = EntityHandle::new(8.into(), 3, true);
|
2026-08-26 17:53:09 +03:00
|
|
|
assert_eq!(
|
|
|
|
|
fast_position_of(&[1, 2, 3, 8, 9, 12].map(ProtoEntity::new), &mut entity),
|
|
|
|
|
Some(3)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn search_0() {
|
2026-08-29 22:41:11 +03:00
|
|
|
let mut entity = EntityHandle::new(8.into(), 4, true);
|
2026-08-26 17:53:09 +03:00
|
|
|
assert_eq!(
|
|
|
|
|
fast_position_of(&[1, 2, 3, 8, 9, 12].map(ProtoEntity::new), &mut entity),
|
|
|
|
|
Some(3)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn search_1() {
|
2026-08-29 22:41:11 +03:00
|
|
|
let mut entity = EntityHandle::new(9.into(), 5, true);
|
2026-08-26 17:53:09 +03:00
|
|
|
assert_eq!(
|
|
|
|
|
fast_position_of(&[1, 2, 3, 8, 9, 12].map(ProtoEntity::new), &mut entity),
|
2026-08-27 09:21:16 +03:00
|
|
|
Some(4)
|
2026-08-26 17:53:09 +03:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn search_2() {
|
2026-08-29 22:41:11 +03:00
|
|
|
let mut entity = EntityHandle::new(106.into(), 25, true);
|
2026-08-26 17:53:09 +03:00
|
|
|
assert_eq!(
|
|
|
|
|
fast_position_of(
|
|
|
|
|
&[
|
|
|
|
|
1, 2, 3, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 20, 21, 22, 23, 105, 106, 107,
|
|
|
|
|
108, 109, 110
|
|
|
|
|
]
|
|
|
|
|
.map(ProtoEntity::new),
|
|
|
|
|
&mut entity
|
|
|
|
|
),
|
2026-08-27 09:21:16 +03:00
|
|
|
Some(18)
|
2026-08-26 17:53:09 +03:00
|
|
|
);
|
|
|
|
|
}
|
2026-08-29 22:41:11 +03:00
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn id_0() {
|
|
|
|
|
let entity: EntityHandle<ProtoEntity> = EntityHandle::new(8.into(), 25, true);
|
|
|
|
|
assert_eq!(entity.real(), true)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn id_1() {
|
|
|
|
|
let entity: EntityHandle<ProtoEntity> = EntityHandle::new(8.into(), 25, false);
|
|
|
|
|
assert_eq!(entity.real(), false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn id_3() {
|
|
|
|
|
let entity: EntityHandle<ProtoEntity> = EntityHandle::new(8.into(), 25, true);
|
|
|
|
|
assert_eq!(entity.index(), 25)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn id_4() {
|
|
|
|
|
let entity: EntityHandle<ProtoEntity> = EntityHandle::new(8.into(), 25, false);
|
|
|
|
|
assert_eq!(entity.index(), 25)
|
|
|
|
|
}
|
|
|
|
|
#[test]
|
|
|
|
|
fn id_5() {
|
|
|
|
|
let mut entity: EntityHandle<ProtoEntity> = EntityHandle::new(8.into(), 25, true);
|
|
|
|
|
entity.set_real(true);
|
|
|
|
|
assert_eq!(entity.real(), true)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn id_6() {
|
|
|
|
|
let mut entity: EntityHandle<ProtoEntity> = EntityHandle::new(8.into(), 25, false);
|
|
|
|
|
entity.set_real(true);
|
|
|
|
|
assert_eq!(entity.real(), true)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn id_7() {
|
|
|
|
|
let mut entity: EntityHandle<ProtoEntity> = EntityHandle::new(8.into(), 25, true);
|
|
|
|
|
entity.set_index(0);
|
|
|
|
|
assert_eq!(entity.index(), 0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn id_8() {
|
|
|
|
|
let mut entity: EntityHandle<ProtoEntity> = EntityHandle::new(8.into(), 25, false);
|
|
|
|
|
entity.set_index(0);
|
|
|
|
|
assert_eq!(entity.index(), 0)
|
|
|
|
|
}
|
2026-08-26 17:53:09 +03:00
|
|
|
}
|