Files
jap_learn/src/tests.rs
T

92 lines
2.1 KiB
Rust
Raw Normal View History

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() {
let mut entity = EntityHandle {
_phantom: Default::default(),
id: 8.into(),
real: true,
index: 3,
};
assert_eq!(
fast_position_of(&[1, 2, 3, 8, 9, 12].map(ProtoEntity::new), &mut entity),
Some(3)
);
}
#[test]
fn search_0() {
let mut entity = EntityHandle {
_phantom: Default::default(),
id: 8.into(),
real: true,
index: 4,
};
assert_eq!(
fast_position_of(&[1, 2, 3, 8, 9, 12].map(ProtoEntity::new), &mut entity),
Some(3)
);
}
#[test]
fn search_1() {
let mut entity = EntityHandle {
_phantom: Default::default(),
id: 9.into(),
real: true,
index: 5,
};
assert_eq!(
fast_position_of(&[1, 2, 3, 8, 9, 12].map(ProtoEntity::new), &mut entity),
Some(1)
);
}
#[test]
fn search_2() {
let mut entity = EntityHandle {
_phantom: Default::default(),
id: 106.into(),
real: true,
index: 5,
};
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
),
Some(1)
);
}
}