Implements mocking for MoveData
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
ad9f17ccf1
commit
d4b1cadad0
|
@ -67,3 +67,4 @@ serde_json = "1.0.81"
|
||||||
serde_plain = "1.0.0"
|
serde_plain = "1.0.0"
|
||||||
# Allow us to assert whether floats are approximately a value
|
# Allow us to assert whether floats are approximately a value
|
||||||
assert_approx_eq = "1.1.0"
|
assert_approx_eq = "1.1.0"
|
||||||
|
mockall = "0.11.2"
|
|
@ -100,22 +100,13 @@ impl ValueIdentifiable for LearnedMove {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::static_data::{MoveCategory, MoveDataImpl, MoveTarget};
|
use crate::static_data::MockMoveData;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn create_learned_move_restore_uses() {
|
fn create_learned_move_restore_uses() {
|
||||||
let data: Arc<dyn MoveData> = Arc::new(MoveDataImpl::new(
|
let mut mock = MockMoveData::new();
|
||||||
&"foo".into(),
|
mock.expect_base_usages().return_const(30);
|
||||||
0u8.into(),
|
let data: Arc<dyn MoveData> = Arc::new(mock);
|
||||||
MoveCategory::Special,
|
|
||||||
100,
|
|
||||||
20,
|
|
||||||
30,
|
|
||||||
MoveTarget::All,
|
|
||||||
0,
|
|
||||||
None,
|
|
||||||
Default::default(),
|
|
||||||
));
|
|
||||||
let learned_move = LearnedMove::new(&data, MoveLearnMethod::Level);
|
let learned_move = LearnedMove::new(&data, MoveLearnMethod::Level);
|
||||||
assert!(learned_move.try_use(15));
|
assert!(learned_move.try_use(15));
|
||||||
learned_move.restore_uses(5);
|
learned_move.restore_uses(5);
|
||||||
|
|
|
@ -206,3 +206,27 @@ impl ValueIdentifiable for MoveDataImpl {
|
||||||
self.identifier
|
self.identifier
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mockall::mock! {
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub MoveData{}
|
||||||
|
impl MoveData for MoveData {
|
||||||
|
fn name(&self) -> &StringKey;
|
||||||
|
fn move_type(&self) -> TypeIdentifier;
|
||||||
|
fn category(&self) -> MoveCategory;
|
||||||
|
fn base_power(&self) -> u8;
|
||||||
|
fn accuracy(&self) -> u8;
|
||||||
|
fn base_usages(&self) -> u8;
|
||||||
|
fn target(&self) -> MoveTarget;
|
||||||
|
fn priority(&self) -> i8;
|
||||||
|
fn secondary_effect(&self) -> &Option<Box<dyn SecondaryEffect>>;
|
||||||
|
fn has_flag(&self, key: &StringKey) -> bool;
|
||||||
|
fn has_flag_by_hash(&self, key_hash: u32) -> bool;
|
||||||
|
}
|
||||||
|
impl ValueIdentifiable for MoveData{
|
||||||
|
fn value_identifier(&self) -> ValueIdentifier{
|
||||||
|
ValueIdentifier::new(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue