Skip to content

Commit

Permalink
Use slice instead of Vec for passing player moves
Browse files Browse the repository at this point in the history
  • Loading branch information
BartoszCiesla committed Feb 13, 2024
1 parent 4fa142d commit df2b2cd
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ impl Game {
}
}

fn is_war(table: &Vec<PlayerMove>) -> Option<Vec<PlayerId>> {
fn is_war(table: &[PlayerMove]) -> Option<Vec<PlayerId>> {
if table.len() > 1 {
let first_card = &table[0].card;
let first_player = table[0].player_id;
Expand Down Expand Up @@ -315,7 +315,7 @@ mod test {
fn test_is_war() {
assert_eq!(
Some(vec![1, 3, 4]),
is_war(&vec![
is_war(&[
PlayerMove::new(1, Card::new(Rank::Ace, Color::Spades)),
PlayerMove::new(3, Card::new(Rank::Ace, Color::Diamonds)),
PlayerMove::new(4, Card::new(Rank::Ace, Color::Hearts)),
Expand All @@ -328,7 +328,7 @@ mod test {
fn test_is_war_no_war() {
assert_eq!(
None,
is_war(&vec![
is_war(&[
PlayerMove::new(3, Card::new(Rank::Ace, Color::Diamonds)),
PlayerMove::new(1, Card::new(Rank::Two, Color::Clubs)),
PlayerMove::new(2, Card::new(Rank::Ten, Color::Hearts)),
Expand All @@ -340,7 +340,7 @@ mod test {
fn test_is_war_not_first() {
assert_eq!(
None,
is_war(&vec![
is_war(&[
PlayerMove::new(3, Card::new(Rank::Ace, Color::Diamonds)),
PlayerMove::new(1, Card::new(Rank::Ten, Color::Clubs)),
PlayerMove::new(2, Card::new(Rank::Ten, Color::Hearts)),
Expand All @@ -352,7 +352,7 @@ mod test {
fn test_is_war_one_item() {
assert_eq!(
None,
is_war(&vec![PlayerMove::new(
is_war(&[PlayerMove::new(
1,
Card::new(Rank::King, Color::Spades)
)])
Expand All @@ -361,6 +361,6 @@ mod test {

#[test]
fn test_is_war_empty_table() {
assert_eq!(None, is_war(&Vec::new()));
assert_eq!(None, is_war(&[]));
}
}

0 comments on commit df2b2cd

Please sign in to comment.