Commit 9a36f78d authored by santiaago's avatar santiaago
Browse files

add test to draw/isogrids pkg

parent d48b8003
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
package isogrids

import (
	"image/color"
	"net/http"
	"net/http/httptest"
	"testing"

	tgColors "github.com/taironas/tinygraphs/colors"
)

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},
	}
)

func TestRandomGradientColor(t *testing.T) {

	rec := httptest.NewRecorder()
	gv := tgColors.GradientVector{0, 0, 1, 1}
	RandomGradientColor(rec, colorTheme, colorTheme[1:], gv, 10, 10, 10, float64(50))
	if rec.Code != http.StatusOK {
		t.Errorf("returned %v. Expected %v.", rec.Code, http.StatusOK)
	}

}
+30 −0
Original line number Diff line number Diff line
package isogrids

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

var (
	key string
)

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

func TestHexa(t *testing.T) {

	rec := httptest.NewRecorder()
	Hexa(rec, key, colorTheme, 10, 10)
	if rec.Code != http.StatusOK {
		t.Errorf("returned %v. Expected %v.", rec.Code, http.StatusOK)
	}

}
+17 −0
Original line number Diff line number Diff line
package isogrids

import (
	"net/http"
	"net/http/httptest"
	"testing"
)

func TestIsogrids(t *testing.T) {

	rec := httptest.NewRecorder()
	Isogrids(rec, key, colorTheme, 10, 10)
	if rec.Code != http.StatusOK {
		t.Errorf("returned %v. Expected %v.", rec.Code, http.StatusOK)
	}

}
+34 −0
Original line number Diff line number Diff line
package isogrids

import (
	"net/http"
	"net/http/httptest"
	"testing"
)

func TestDiagonals(t *testing.T) {

	rec := httptest.NewRecorder()
	Diagonals(rec, key, colorTheme[0], colorTheme[1], 10)
	if rec.Code != http.StatusOK {
		t.Errorf("returned %v. Expected %v.", rec.Code, http.StatusOK)
	}
}

func TestHalfDiagonals(t *testing.T) {

	rec := httptest.NewRecorder()
	HalfDiagonals(rec, key, colorTheme[0], colorTheme[1], 10)
	if rec.Code != http.StatusOK {
		t.Errorf("returned %v. Expected %v.", rec.Code, http.StatusOK)
	}
}

func TestSkeleton(t *testing.T) {

	rec := httptest.NewRecorder()
	Skeleton(rec, key, colorTheme[0], colorTheme[1], 10)
	if rec.Code != http.StatusOK {
		t.Errorf("returned %v. Expected %v.", rec.Code, http.StatusOK)
	}
}
+20 −0
Original line number Diff line number Diff line
package isogrids

import "testing"

func TestmirrorCoordinates(t *testing.T) {
	xs := []int{1, 2, 3}
	lines := 10
	fringeSize := 2
	offset := 1
	xsMirror := mirrorCoordinates(xs, lines, fringeSize, offset)
	expected := []int{20, 19, 18}
	if len(expected) != len(xsMirror) {
		t.Errorf("lengths are different")
	}
	for k, _ := range expected {
		if expected[k] != xsMirror[k] {
			t.Errorf("expected %v got %v", expected[k], xsMirror[k])
		}
	}
}