More repo code
This commit is contained in:
1 parent
807f398d81
commit
d99fd337da
4 files changed
+359
-63
No files matched your search
@@ -0,0 +1,92 @@
|
||||
#[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)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user