Commit b4c1198e authored by santiaago's avatar santiaago
Browse files

test spaceinvader.go

parent eea87b0f
Loading
Loading
Loading
Loading
+1 −16
Original line number Diff line number Diff line
package spaceinvaders

import (
	"crypto/md5"
	"fmt"
	"io"
	"testing"
)

var (
	key string
)

func init() {
	h := md5.New()
	io.WriteString(h, "hello")
	key = fmt.Sprintf("%x", h.Sum(nil)[:])
}
import "testing"

func TestnewInvader(t *testing.T) {

+0 −24
Original line number Diff line number Diff line
@@ -404,27 +404,3 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size
	}
	canvas.End()
}

func fillWhite() string {
	return "stroke:black;stroke-width:2;fill:rgb(255,255,255)"
}

func fillBlack() string {
	return "stroke:black;stroke-width:2;fill:rgb(0,0,0)"
}

func fillGrey() string {
	return "stroke:black;stroke-width:2;fill:rgb(160,160,160)"
}

func fillGreen() string {
	return "stroke:black;stroke-width:2;fill:rgb(0,255,0)"
}

func fillRed() string {
	return "stroke:black;stroke-width:2;fill:rgb(255,0,0)"
}

func fillBlue() string {
	return "stroke:black;stroke-width:2;fill:rgb(0,0,255)"
}
+59 −0
Original line number Diff line number Diff line
package spaceinvaders

import (
	"crypto/md5"
	"fmt"
	"image/color"
	"io"
	"net/http"
	"net/http/httptest"
	"testing"
)

var (
	colorTheme = []color.RGBA{
		color.RGBA{255, 245, 249, 255},
		color.RGBA{232, 70, 134, 255},
		color.RGBA{232, 70, 186, 255},
		color.RGBA{232, 70, 81, 255},
	}
	key  string
	keys []string
)

func init() {
	h := md5.New()
	io.WriteString(h, "hello")
	key = fmt.Sprintf("%x", h.Sum(nil)[:])
	io.WriteString(h, "hello2")
	key2 := fmt.Sprintf("%x", h.Sum(nil)[:])
	io.WriteString(h, "hello3")
	key3 := fmt.Sprintf("%x", h.Sum(nil)[:])
	io.WriteString(h, "hello4")
	key4 := fmt.Sprintf("%x", h.Sum(nil)[:])
	io.WriteString(h, "hello5")
	key5 := fmt.Sprintf("%x", h.Sum(nil)[:])
	io.WriteString(h, "hello6")
	key6 := fmt.Sprintf("%x", h.Sum(nil)[:])
	io.WriteString(h, "hello7")
	key7 := fmt.Sprintf("%x", h.Sum(nil)[:])
	io.WriteString(h, "hello8")
	key8 := fmt.Sprintf("%x", h.Sum(nil)[:])
	io.WriteString(h, "hello9")
	key9 := fmt.Sprintf("%x", h.Sum(nil)[:])

	keys = []string{key, key2, key3, key4, key5, key6, key7, key8, key9}

}

func TestSpaceInvaders(t *testing.T) {

	for _, k := range keys {
		rec := httptest.NewRecorder()
		SpaceInvaders(rec, k, colorTheme, 100)
		if rec.Code != http.StatusOK {
			t.Errorf("returned %v. Expected %v.", rec.Code, http.StatusOK)
		}
	}

}