games_test.go 1021 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package games
  2. import (
  3. "testing"
  4. )
  5. func TestAddGame(t *testing.T) {
  6. game := NewGame(100,100)
  7. games := New()
  8. games.AddGame(game)
  9. if len(games.ListGames()) != 1 {
  10. t.Fatalf("Incorrect ListGames size expeciting 1 got %v", len(games.ListGames()))
  11. }
  12. }
  13. func TestAdd2Games(t *testing.T) {
  14. game := NewGame(100,100)
  15. game2 := NewGame(100,100)
  16. games := New()
  17. games.AddGame(game)
  18. games.AddGame(game2)
  19. if len(games.ListGames()) != 2 {
  20. t.Fatalf("Incorrect ListGames size expeciting 2 got %v", len(games.ListGames()))
  21. }
  22. if games.ListGames()[0].Id != game.Id {
  23. t.Fatalf("Incorrect gameid expected %v got %v", games.ListGames()[0].Id, game.Id)
  24. }
  25. }
  26. func TestAddGetGame(t *testing.T) {
  27. game := NewGame(100,100)
  28. game2 := NewGame(100,100)
  29. game3 := NewGame(100,100)
  30. games := New()
  31. games.AddGame(game)
  32. games.AddGame(game2)
  33. games.AddGame(game3)
  34. resultGame := games.GetGame(game2.Id)
  35. if resultGame.Id != game2.Id {
  36. t.Fatalf("Incorrect ListGames size expeciting %v got %v", resultGame.Id, game2.Id)
  37. }
  38. }