A bunch of work on unit testing
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-11-26 15:33:50 +01:00
parent a6a9cb573f
commit d1ed14119d
10 changed files with 332 additions and 26 deletions

View File

@@ -181,6 +181,7 @@ pub struct MoveChoice {
impl MoveChoice {
/// Initializes the data for a new move choice.
pub fn new(user: Arc<Pokemon>, used_move: Arc<LearnedMove>, target_side: u8, target_index: u8) -> Self {
let speed = user.boosted_stats().speed();
Self {
used_move,
target_side,
@@ -190,7 +191,7 @@ impl MoveChoice {
choice_data: Box::new(CommonChoiceData {
identifier: Default::default(),
user,
speed: 0,
speed,
random_value: 0,
has_failed: Default::default(),
script_source_data: Default::default(),
@@ -258,11 +259,12 @@ pub struct ItemChoice {
impl ItemChoice {
/// Initialised a new item choice.
pub fn new(user: Arc<Pokemon>) -> Self {
let speed = user.boosted_stats().speed();
Self {
choice_data: Box::new(CommonChoiceData {
identifier: Default::default(),
user,
speed: 0,
speed,
random_value: 0,
has_failed: Default::default(),
script_source_data: Default::default(),
@@ -297,11 +299,12 @@ pub struct SwitchChoice {
impl SwitchChoice {
/// Initialise the turn choice data.
pub fn new(user: Arc<Pokemon>) -> Self {
let speed = user.boosted_stats().speed();
Self {
choice_data: Box::new(CommonChoiceData {
identifier: Default::default(),
user,
speed: 0,
speed,
random_value: 0,
has_failed: Default::default(),
script_source_data: Default::default(),
@@ -375,11 +378,12 @@ pub struct PassChoice {
impl PassChoice {
/// Initialised a new pass choice.
pub fn new(user: Arc<Pokemon>) -> Self {
let speed = user.boosted_stats().speed();
Self {
choice_data: Box::new(CommonChoiceData {
identifier: Default::default(),
user,
speed: 0,
speed,
random_value: 0,
has_failed: Default::default(),
script_source_data: Default::default(),
@@ -474,7 +478,16 @@ impl Ord for TurnChoice {
}
std::cmp::Ordering::Less
}
TurnChoice::Pass(..) => std::cmp::Ordering::Less,
TurnChoice::Pass(..) => {
if let TurnChoice::Pass { .. } = other {
let speed_compare = self.speed().cmp(&other.speed());
if speed_compare != std::cmp::Ordering::Equal {
return speed_compare;
}
return self.random_value().cmp(&other.random_value());
}
std::cmp::Ordering::Less
}
}
}
}