Implemented delta-ing methods w/ unit tests.
This commit is contained in:
@@ -57,13 +57,14 @@ impl Event {
|
||||
unreachable!()
|
||||
};
|
||||
|
||||
Some((a - b) as i8)
|
||||
Some(a as i8 - b as i8)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone, PartialEq)]
|
||||
#[derive(Debug, Deserialize, Clone, PartialEq, Default)]
|
||||
pub enum ScorePoints {
|
||||
#[default]
|
||||
Touchdown,
|
||||
FieldGoal,
|
||||
Safety,
|
||||
@@ -86,3 +87,73 @@ impl ScorePoints {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{Action, Down, Team, TerrainState};
|
||||
|
||||
#[test]
|
||||
fn delta() {
|
||||
let kickoff = Event::Kickoff(Team::Nebraska);
|
||||
let first_down = Event::Play(Play {
|
||||
action: Action::Unknown,
|
||||
down: Some(Down::First),
|
||||
terrain: Some(TerrainState::Yards(10)),
|
||||
});
|
||||
let second_down = Event::Play(Play {
|
||||
action: Action::Unknown,
|
||||
down: Some(Down::Second),
|
||||
terrain: Some(TerrainState::Yards(10)),
|
||||
});
|
||||
let third_down = Event::Play(Play {
|
||||
action: Action::Unknown,
|
||||
down: Some(Down::Third),
|
||||
terrain: Some(TerrainState::Yards(13)),
|
||||
});
|
||||
let fourth_down = Event::Play(Play {
|
||||
action: Action::Unknown,
|
||||
down: Some(Down::Fourth),
|
||||
terrain: Some(TerrainState::Yards(5)),
|
||||
});
|
||||
let penalty = Event::Penalty(TerrainState::Yards(15));
|
||||
let turnover = Event::Turnover(Team::Nebraska);
|
||||
let noned_down = Event::Play(Play {
|
||||
action: Action::Unknown,
|
||||
down: None,
|
||||
terrain: None,
|
||||
});
|
||||
let score = Event::Score(ScorePoints::default());
|
||||
let goal_line = Event::Play(Play {
|
||||
action: Action::Unknown,
|
||||
down: Some(Down::First),
|
||||
terrain: Some(TerrainState::GoalLine),
|
||||
});
|
||||
let inches = Event::Play(Play {
|
||||
action: Action::Unknown,
|
||||
down: Some(Down::First),
|
||||
terrain: Some(TerrainState::Inches),
|
||||
});
|
||||
|
||||
assert!(10_i8 == kickoff.delta(&first_down).unwrap());
|
||||
assert!(0_i8 == first_down.delta(&second_down).unwrap());
|
||||
assert!(-3_i8 == second_down.delta(&third_down).unwrap());
|
||||
assert!(10_i8 == first_down.delta(&kickoff).unwrap());
|
||||
assert!(10_i8 == first_down.delta(&goal_line).unwrap());
|
||||
assert!(10_i8 == first_down.delta(&inches).unwrap());
|
||||
assert!(13_i8 == third_down.delta(&kickoff).unwrap());
|
||||
assert!(8_i8 == third_down.delta(&fourth_down).unwrap());
|
||||
assert!(13_i8 == third_down.delta(&goal_line).unwrap());
|
||||
assert!(None == fourth_down.delta(&turnover));
|
||||
assert!(None == kickoff.delta(&penalty));
|
||||
assert!(None == first_down.delta(&penalty));
|
||||
assert!(None == noned_down.delta(&kickoff));
|
||||
assert!(None == noned_down.delta(&turnover));
|
||||
assert!(None == kickoff.delta(&score));
|
||||
assert!(None == first_down.delta(&score));
|
||||
assert!(None == turnover.delta(&score));
|
||||
assert!(None == goal_line.delta(&first_down));
|
||||
assert!(None == inches.delta(&first_down));
|
||||
assert!(None == goal_line.delta(&inches));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user