Skip to content

Commit

Permalink
test: unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
daithihearn committed Jan 30, 2024
1 parent 974020d commit 5dd3301
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pkg/game/game_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,26 @@ func TestGame_GetState(t *testing.T) {
Round: PlayingGame_RoundStart("3").CurrentRound,
},
},
{
name: "Game with completed rounds",
game: GameWithCompletedRounds(),
playerID: "1",
expectedState: State{
ID: GameWithCompletedRounds().ID,
Revision: GameWithCompletedRounds().Revision,
Me: GameWithCompletedRounds().Players[0],
Cards: GameWithCompletedRounds().Players[0].Cards,
IamDealer: true,
IamGoer: true,
IamSpectator: false,
IsMyGo: false,
Status: GameWithCompletedRounds().Status,
MaxCall: 0,
Players: GameWithCompletedRounds().Players,
Round: GameWithCompletedRounds().CurrentRound,
PrevRound: GameWithCompletedRounds().Completed[len(GameWithCompletedRounds().Completed)-1],
},
},
}

for _, test := range tests {
Expand Down Expand Up @@ -215,6 +235,9 @@ func TestGame_GetState(t *testing.T) {
if state.Round.Number != test.expectedState.Round.Number {
t.Errorf("expected Round Number to be %d, got %d", test.expectedState.Round.Number, state.Round.Number)
}
if state.PrevRound.Number != test.expectedState.PrevRound.Number {
t.Errorf("expected PrevRound Number to be %d, got %d", test.expectedState.PrevRound.Number, state.PrevRound.Number)
}
}
})
}
Expand Down
87 changes: 87 additions & 0 deletions pkg/game/testdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,3 +720,90 @@ func CompletedGame() Game {
AdminID: "1",
}
}

func GameWithCompletedRounds() Game {
p1 := Player1()
p1.Score = 110
p2 := Player2()
p2.Score = 90

return Game{
ID: "2",
Name: "Test Game",
Status: Completed,
Timestamp: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),
Players: []Player{p1, p2},
AdminID: "1",
CurrentRound: Round{
Number: 1,
DealerID: "1",
GoerID: "1",
Suit: Spades,
Status: Completed,
CompletedHands: []Hand{
{
LeadOut: FIVE_SPADES,
CurrentPlayerID: "2",
PlayedCards: []PlayedCard{
{
PlayerID: "1",
Card: FIVE_SPADES,
},
{
PlayerID: "2",
Card: TEN_SPADES,
},
},
},
},
},
Completed: []Round{
{
Number: 1,
DealerID: "1",
GoerID: "1",
Suit: Spades,
Status: Completed,
CompletedHands: []Hand{
{
LeadOut: FIVE_SPADES,
CurrentPlayerID: "2",
PlayedCards: []PlayedCard{
{
PlayerID: "1",
Card: FIVE_SPADES,
},
{
PlayerID: "2",
Card: TEN_SPADES,
},
},
},
},
},
{
Number: 2,
DealerID: "1",
GoerID: "1",
Suit: Spades,
Status: Completed,
CompletedHands: []Hand{
{
LeadOut: FIVE_SPADES,
CurrentPlayerID: "2",
PlayedCards: []PlayedCard{
{
PlayerID: "1",
Card: FIVE_SPADES,
},
{
PlayerID: "2",
Card: TEN_SPADES,
},
},
},
},
},
},
}
}

0 comments on commit 5dd3301

Please sign in to comment.