Commit a7487497 authored by santiaago's avatar santiaago
Browse files

add test for hexalines #55

parent 363a9e2f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ func Hexa(w http.ResponseWriter, r *http.Request) {
	io.WriteString(h, key)
	key = fmt.Sprintf("%x", h.Sum(nil)[:])

	lines := int(extract.Hexalines(r))
	lines := extract.Hexalines(r)
	colors := extract.Colors(r)

	write.ImageSVG(w)
+2 −2
Original line number Diff line number Diff line
@@ -52,12 +52,12 @@ func Theme(r *http.Request) string {

// Hexalines return the value of the hexalines parameter in the http.Request.
// possible values: 6 or 8. Default value : 6
func Hexalines(r *http.Request) int64 {
func Hexalines(r *http.Request) int {
	s := strings.ToLower(r.FormValue("hexalines"))
	if len(s) > 0 {
		if n, err := strconv.ParseInt(s, 0, 64); err == nil {
			if n%6 == 0 || n%4 == 0 {
				return n
				return int(n)
			}
		}
	}
+22 −0
Original line number Diff line number Diff line
@@ -76,3 +76,25 @@ func TestTheme(t *testing.T) {
		}
	}
}

func TestHexalines(t *testing.T) {
	tests := []struct {
		title     string
		url       string
		hexalines int
	}{
		{"test wrong input", "http://www.tg.c?hexalines=h", 6},
		{"test no input", "http://www.tg.c", 6},
		{"test good input jpeg", "http://www.tg.c?hexalines=4", 4},
	}

	for _, test := range tests {
		t.Log(test.title)
		r := &http.Request{Method: "GET"}
		r.URL, _ = url.Parse(test.url)
		x := Hexalines(r)
		if x != test.hexalines {
			t.Errorf("expected %d got %d", test.hexalines, x)
		}
	}
}