Improve unit test and a bunch of I forget what.
This commit is contained in:
@@ -5,7 +5,7 @@ use std::{fmt, io};
|
||||
pub enum LogFileError {
|
||||
IOError(io::Error),
|
||||
RonSpanned(ron::error::SpannedError),
|
||||
TooManyTeams(usize),
|
||||
TeamCount(usize),
|
||||
}
|
||||
|
||||
impl fmt::Display for LogFileError {
|
||||
@@ -13,7 +13,7 @@ impl fmt::Display for LogFileError {
|
||||
match self {
|
||||
Self::IOError(err) => write!(f, "{}", err),
|
||||
Self::RonSpanned(err) => write!(f, "{}", err),
|
||||
Self::TooManyTeams(err) => write!(f, "Expected two, found: {:?}", err),
|
||||
Self::TeamCount(err) => write!(f, "Expected two, found: {:?}", err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::{Down, Play, Quarter, TerrainState};
|
||||
use serde::Deserialize;
|
||||
use strum::EnumIter;
|
||||
|
||||
type Offence = Team;
|
||||
|
||||
@@ -86,7 +87,7 @@ impl Event {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone, PartialEq, Default)]
|
||||
#[derive(Debug, Deserialize, Clone, PartialEq, Default, EnumIter)]
|
||||
pub enum Team {
|
||||
ArizonaState,
|
||||
#[deprecated(since = "0.2.0", note = "Team left the project.")]
|
||||
|
||||
@@ -8,7 +8,7 @@ pub struct LogFile(pub Vec<Game>);
|
||||
|
||||
impl LogFile {
|
||||
/// Returns the most common action for a given team.
|
||||
pub fn most_frequent_action(&self, team: Team) -> Action {
|
||||
pub fn most_frequent_action(&self, team: Team) -> (Action, usize) {
|
||||
let mut most_freq_action = Action::default();
|
||||
let mut frequency = usize::MIN;
|
||||
let mut found = usize::MIN;
|
||||
@@ -25,12 +25,12 @@ impl LogFile {
|
||||
}
|
||||
});
|
||||
|
||||
most_freq_action
|
||||
(most_freq_action, frequency)
|
||||
}
|
||||
|
||||
/// Returns the least common action for a given team.
|
||||
/// This action has to have been played at least once.
|
||||
pub fn least_frequent_action(&self, team: Team) -> Action {
|
||||
pub fn least_frequent_action(&self, team: Team) -> (Action, usize) {
|
||||
let mut least_freq_action = Action::default();
|
||||
let mut frequency = usize::MAX;
|
||||
let mut found = usize::MAX;
|
||||
@@ -42,21 +42,20 @@ impl LogFile {
|
||||
found = team_actions.clone().filter(|a| *a == action).count();
|
||||
|
||||
if (found != 0_usize) && (found < frequency) {
|
||||
dbg!("hit");
|
||||
frequency = found;
|
||||
least_freq_action = action.to_owned();
|
||||
}
|
||||
});
|
||||
|
||||
least_freq_action
|
||||
(least_freq_action, frequency)
|
||||
}
|
||||
|
||||
pub fn most_effective_play(&self, team: Team) -> (Action, TerrainState) {
|
||||
let deltas: Vec<Vec<i8>> = self
|
||||
let deltas = self
|
||||
.0
|
||||
.iter()
|
||||
.map(|game| game.deltas(team.to_owned()))
|
||||
.collect();
|
||||
.collect::<Vec<Vec<i8>>>();
|
||||
|
||||
let team_events: Vec<Vec<Event>> = self
|
||||
.0
|
||||
@@ -65,7 +64,7 @@ impl LogFile {
|
||||
.collect::<Vec<TeamEvents>>()
|
||||
.iter()
|
||||
.map(|team_events| team_events.0.to_owned())
|
||||
.collect::<Vec<Vec<Event>>>();
|
||||
.collect();
|
||||
|
||||
let mut action_return = Action::Unknown;
|
||||
let mut terrain_delta: u8 = 0;
|
||||
@@ -87,15 +86,15 @@ impl LogFile {
|
||||
}
|
||||
}
|
||||
|
||||
event_idx += 1;
|
||||
if (event_idx + 1) == game.len() {
|
||||
event_idx = 0;
|
||||
continue;
|
||||
} else {
|
||||
event_idx += 1;
|
||||
}
|
||||
}
|
||||
|
||||
game_idx += 1;
|
||||
|
||||
if (event_idx + 1) == game.len() {
|
||||
event_idx = 0;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
let sum: u8 = action_deltas.iter().sum::<i8>() as u8;
|
||||
@@ -194,11 +193,11 @@ mod tests {
|
||||
..Default::default()
|
||||
}),
|
||||
Event::Play(Play {
|
||||
action: Action::Mesh,
|
||||
action: Action::Curls,
|
||||
..Default::default()
|
||||
}),
|
||||
Event::Play(Play {
|
||||
action: Action::Curls,
|
||||
action: Action::Mesh,
|
||||
..Default::default()
|
||||
}),
|
||||
Event::Play(Play {
|
||||
@@ -239,11 +238,11 @@ mod tests {
|
||||
..Default::default()
|
||||
}),
|
||||
Event::Play(Play {
|
||||
action: Action::Curls,
|
||||
action: Action::SlotOut,
|
||||
..Default::default()
|
||||
}),
|
||||
Event::Play(Play {
|
||||
action: Action::SlotOut,
|
||||
action: Action::Curls,
|
||||
..Default::default()
|
||||
}),
|
||||
Event::Kickoff(Team::ArizonaState),
|
||||
|
||||
@@ -37,7 +37,7 @@ impl Game {
|
||||
if teams.len() == 2 || ignore.len() != 0 {
|
||||
Ok(teams)
|
||||
} else {
|
||||
Err(error::LogFileError::TooManyTeams(teams.len()))
|
||||
Err(error::LogFileError::TeamCount(teams.len()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,13 @@ impl Game {
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
let len = events.len() - 1;
|
||||
|
||||
let len = if events.len() == 0 {
|
||||
return vec![0];
|
||||
} else {
|
||||
events.len() - 1
|
||||
};
|
||||
|
||||
let mut idx: usize = 0;
|
||||
let mut deltas: Vec<i8> = vec![];
|
||||
|
||||
@@ -326,7 +332,7 @@ impl Period {
|
||||
|
||||
#[derive(Debug, Deserialize, Clone, PartialEq)]
|
||||
pub enum Flags {
|
||||
ClockBleeding(Team),
|
||||
ClockBleed(Team),
|
||||
IgnoreActions,
|
||||
IgnoreTeam(Team),
|
||||
IgnoreScore,
|
||||
@@ -400,15 +406,6 @@ mod tests {
|
||||
};
|
||||
|
||||
let c = Game {
|
||||
events: vec![
|
||||
Event::Kickoff(Team::Nebraska),
|
||||
Event::Turnover(Team::ArizonaState),
|
||||
Event::Kickoff(Team::Nebraska),
|
||||
],
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let d = Game {
|
||||
flags: vec![Flags::IgnoreTeam(Team::Nebraska)],
|
||||
events: vec![Event::Kickoff(Team::Nebraska)],
|
||||
..Default::default()
|
||||
@@ -416,8 +413,7 @@ mod tests {
|
||||
|
||||
assert!(a.teams().unwrap() == vec![Team::Nebraska, Team::ArizonaState]);
|
||||
assert!(b.teams().is_err() == true);
|
||||
assert!(c.teams().unwrap() == vec![Team::ArizonaState]);
|
||||
assert!(d.teams().unwrap() == vec![]);
|
||||
assert!(c.teams().unwrap() == vec![]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user