Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge 6721b43 into 523c848
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorj committed Oct 18, 2015
2 parents 523c848 + 6721b43 commit e234105
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
28 changes: 28 additions & 0 deletions ia_cache_test.go
@@ -0,0 +1,28 @@
package TicTacToe_test

import (
"testing"

"github.com/hectorj/TicTacToe"
"github.com/stretchr/testify/assert"
)

func TestGetAllGrids(t *testing.T) {
grids := TicTacToe.GetAllGrids()

expectedLen := 5478

assert.Len(t, grids, 5478)

gridIDsHitList := make(map[uint32]struct{}, expectedLen)

for _, grid := range grids {
ID := grid.GetID()

if _, exists := gridIDsHitList[ID]; exists {
t.Fatalf("Duplicated grid ID: %d", ID)
}

gridIDsHitList[ID] = struct{}{}
}
}
16 changes: 16 additions & 0 deletions web/render_test.go
Expand Up @@ -15,3 +15,19 @@ func TestRender_EmptyGrid(t *testing.T) {

assert.Equal(t, "\n<html>\n<head>\n <title>Tic Tac Toe - Human vs CPU</title>\n\n <link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css\">\n <link href=\"assets/main.css\" rel=\"stylesheet\"/>\n</head>\n<body>\n <h1>Tic Tac Toe</h1>\n <p class=\"well well-sm text-center\" >\n \n You play as <a class=\"btn btn-danger\" disabled=\"disabled\">X</a>\n \n </p>\n <br/>\n <div id=\"grid\">\n \n<div class=\"grid\">\n \n \n \n \n \n <a class=\"btn btn-default\" href=\"./3.html\"></a>\n \n \n\n \n \n \n \n <a class=\"btn btn-default\" href=\"./129.html\"></a>\n \n \n\n \n \n \n \n <a class=\"btn btn-default\" href=\"./8193.html\"></a>\n \n \n\n \n <br/>\n \n \n \n \n \n <a class=\"btn btn-default\" href=\"./9.html\"></a>\n \n \n\n \n \n \n \n <a class=\"btn btn-default\" href=\"./513.html\"></a>\n \n \n\n \n \n \n \n <a class=\"btn btn-default\" href=\"./32769.html\"></a>\n \n \n\n \n <br/>\n \n \n \n \n \n <a class=\"btn btn-default\" href=\"./33.html\"></a>\n \n \n\n \n \n \n \n <a class=\"btn btn-default\" href=\"./2049.html\"></a>\n \n \n\n \n \n \n \n <a class=\"btn btn-default\" href=\"./131073.html\"></a>\n \n \n\n \n <br/>\n \n</div>\n\n </div>\n <br/>\n <p class=\"text-center\"><a class=\"btn btn-success btn-lg\" href=\"./\">New game</a></p>\n</body>\n</html>\n", buffer.String())
}

func TestRender_HalfFullGrid_Win(t *testing.T) {
buffer := &bytes.Buffer{}

web.Render(buffer, 492166)

assert.Equal(t, "\n<html>\n<head>\n <title>Tic Tac Toe - Human vs CPU</title>\n\n <link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css\">\n <link href=\"assets/main.css\" rel=\"stylesheet\"/>\n</head>\n<body>\n <h1>Tic Tac Toe</h1>\n <p class=\"well well-sm text-center\" >\n \n <strong>Game over</strong> : the winner is <a class=\"btn btn-warning\" disabled=\"disabled\">O</a>\n \n </p>\n <br/>\n <div id=\"grid\">\n \n<div class=\"grid\">\n \n \n \n \n ", buffer.String())
}

func TestRender_FullGrid_Draw(t *testing.T) {
buffer := &bytes.Buffer{}

web.Render(buffer, 502766)

assert.Equal(t, "\n<html>\n<head>\n <title>Tic Tac Toe - Human vs CPU</title>\n\n <link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css\">\n <link href=\"assets/main.css\" rel=\"stylesheet\"/>\n</head>\n<body>\n <h1>Tic Tac Toe</h1>\n <p class=\"well well-sm text-center\" >\n \n <strong>Game over</strong> : the winner is <a class=\"btn btn-warning\" disabled=\"disabled\">nobody</a>\n \n </p>\n <br/>\n <div id=\"grid\">\n \n<div class=\"grid\">\n \n \n \n \n ", buffer.String())
}

0 comments on commit e234105

Please sign in to comment.