add tests for MoveValueStats
This commit is contained in:
@@ -17,6 +17,36 @@ pub struct MoveValueStats {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl MoveValueStats {
|
impl MoveValueStats {
|
||||||
|
#[cfg(test)]
|
||||||
|
pub const fn new_from_wins_losses(wins: u16, losses: u16) -> Self {
|
||||||
|
Self {
|
||||||
|
state: None,
|
||||||
|
wins,
|
||||||
|
losses,
|
||||||
|
value: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub const fn new_from_value(value: i32) -> Self {
|
||||||
|
Self {
|
||||||
|
state: None,
|
||||||
|
wins: 0,
|
||||||
|
losses: 0,
|
||||||
|
value,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub const fn new_from_state(state: Option<MVSGameState>) -> Self {
|
||||||
|
Self {
|
||||||
|
state,
|
||||||
|
wins: 0,
|
||||||
|
losses: 0,
|
||||||
|
value: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn chance_win(&self) -> Option<f32> {
|
fn chance_win(&self) -> Option<f32> {
|
||||||
let sum = self.losses + self.wins;
|
let sum = self.losses + self.wins;
|
||||||
if sum == 0 {
|
if sum == 0 {
|
||||||
@@ -55,16 +85,39 @@ impl Ord for MoveValueStats {
|
|||||||
return self.state.cmp(&other.state);
|
return self.state.cmp(&other.state);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(s_cw) = self.chance_win() {
|
let (s_cw, o_cw) = (self.chance_win(), other.chance_win());
|
||||||
if let Some(o_cw) = other.chance_win() {
|
if s_cw > o_cw {
|
||||||
if s_cw > o_cw {
|
return Ordering::Greater;
|
||||||
return Ordering::Greater;
|
} else if o_cw > s_cw {
|
||||||
} else if o_cw > s_cw {
|
return Ordering::Less;
|
||||||
return Ordering::Less;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.value.cmp(&other.value)
|
self.value.cmp(&other.value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn two_prob() {
|
||||||
|
let one = MoveValueStats::new_from_wins_losses(10, 4);
|
||||||
|
let two = MoveValueStats::new_from_wins_losses(4, 6);
|
||||||
|
assert!(one > two);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn one_prob_one_non() {
|
||||||
|
let one = MoveValueStats::new_from_wins_losses(10, 4);
|
||||||
|
let two = MoveValueStats::new_from_value(10);
|
||||||
|
assert!(one > two);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn one_prob_one_win() {
|
||||||
|
let one = MoveValueStats::new_from_wins_losses(10, 4);
|
||||||
|
let two = MoveValueStats::new_from_state(Some(MVSGameState::Win));
|
||||||
|
assert!(one < two);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user