Skip to content

Commit

Permalink
Break: fix winner_team_number for a draw
Browse files Browse the repository at this point in the history
  • Loading branch information
eigenein committed May 2, 2023
1 parent c9a2adf commit 59353a9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/models/battle_results.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use prost::bytes::Buf;
use prost::Message;
use prost::{Enumeration, Message};
use serde::Serialize;

use crate::result::Result;
Expand All @@ -22,7 +22,7 @@ pub struct BattleResults {
#[prost(int64, tag = "2")]
pub timestamp: i64,

#[prost(enumeration = "TeamNumber", tag = "3")]
#[prost(enumeration = "WinnerTeamNumber", tag = "3")]
pub winner_team_number: i32,

/// Replay's author results.
Expand Down Expand Up @@ -78,15 +78,21 @@ pub struct PlayerInfo {
pub avatar: Avatar,
}

#[derive(
Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, prost::Enumeration, Serialize,
)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Enumeration, Serialize)]
#[repr(i32)]
pub enum TeamNumber {
One = 1,
Two = 2,
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Enumeration, Serialize)]
#[repr(i32)]
pub enum WinnerTeamNumber {
Neither = 0,
One = 1,
Two = 2,
}

/// Player's battle results.
#[derive(Message, Serialize)]
pub struct PlayerResults {
Expand Down
8 changes: 8 additions & 0 deletions tests/battle_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,11 @@ fn victory_points_ok() -> Result<()> {

Ok(())
}

#[test]
fn draw_ok() -> Result<()> {
let battle_results = Replay::open(File::open("tests/replays/20230503_0027__helaas_pindakaas_A140_ASTRON_REX_105_2319058483532631656.wotbreplay")?)?
.read_battle_results()?;
assert_eq!(battle_results.winner_team_number, 0);
Ok(())
}
Binary file not shown.

0 comments on commit 59353a9

Please sign in to comment.