Commit 9569ef5a authored by santiaago's avatar santiaago
Browse files

add extract size tests. #55

parent 4d2a7e53
Loading
Loading
Loading
Loading

extract/colors_test.go

0 → 100644
+45 −0
Original line number Diff line number Diff line
package extract

import (
	"image/color"
	"net/http"
	"net/url"
	"testing"
)

func TestUserColors(t *testing.T) {
	tests := []struct {
		title  string
		url    string
		colors []color.RGBA
	}{
		{"test wrong input", "http://www.tg.c?colors=foo&colors=bar", []color.RGBA{}},
		{"test no input", "http://www.tg.c", []color.RGBA{}},
		{
			"test good input",
			"http://www.tg.c?colors=ffffff&colors=000000",
			[]color.RGBA{
				color.RGBA{255, 255, 255, 255},
				color.RGBA{0, 0, 0, 255},
			},
		},
	}

	for _, test := range tests {
		t.Log(test.title)
		r := &http.Request{Method: "GET"}
		r.URL, _ = url.Parse(test.url)
		colors, err := UserColors(r)
		if err != nil {
			t.Log(err)
		}
		if len(colors) != len(test.colors) {
			t.Errorf("expected %d array got %d", len(test.colors), len(colors))
		}
		for i := 0; i < len(test.colors); i++ {
			if test.colors[i] != colors[i] {
				t.Errorf("expected %+v array got %+v", test.colors[i], colors[i])
			}
		}
	}
}
+12 −34
Original line number Diff line number Diff line
package extract

import (
	"image/color"
	"net/http"
	"net/url"
	"testing"
)

func TestColors(t *testing.T) {
func TestSize(t *testing.T) {
	tests := []struct {
		title string
		url   string
		colors []color.RGBA
		size  int
	}{
		{
			"test wrong input",
			"http://www.tinygraphs.com/search?colors=foo&colors=bar",
			[]color.RGBA{},
		},
		{
			"test no input",
			"http://www.tinygraphs.com/search",
			[]color.RGBA{},
		},
		{
			"test good input",
			"http://www.tinygraphs.com/search?colors=ffffff&colors=000000",
			[]color.RGBA{
				color.RGBA{255, 255, 255, 255},
				color.RGBA{0, 0, 0, 255},
			},
		},
		{"test wrong input", "http://www.tg.c?size=foo", 240},
		{"test no input", "http://www.tg.c", 240},
		{"test good input", "http://www.tg.c?size=10", 10},
		{"test lower limit", "http://www.tg.c?size=0", 240},
		{"test higher limit", "http://www.tg.c?size=1001", 240},
	}

	for _, test := range tests {
		t.Log(test.title)
		r := &http.Request{Method: "GET"}
		r.URL, _ = url.Parse(test.url)
		colors, err := UserColors(r)
		if err != nil {
			t.Log(err)
		}
		if len(colors) != len(test.colors) {
			t.Errorf("expected %d array got %d", len(test.colors), len(colors))
		}
		for i := 0; i < len(test.colors); i++ {
			if test.colors[i] != colors[i] {
				t.Errorf("expected %+v array got %+v", test.colors[i], colors[i])
			}
		s := Size(r)
		if s != test.size {
			t.Errorf("expected %d  got %d", test.size, s)
		}
	}
}