Loading extract/colors_test.go +69 −2 Original line number Diff line number Diff line Loading @@ -9,14 +9,81 @@ import ( tgColors "github.com/taironas/tinygraphs/colors" ) func TestColors(t *testing.T) { colorMap := tgColors.MapOfColorThemes() tests := []struct { title string url string colors []color.RGBA }{ { "test wrong input", "http://www.tg.c?colors=foo&colors=bar", colorMap["base"], }, { "test no input", "http://www.tg.c", colorMap["base"], }, { "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}, }, }, { "test good input with theme", "http://www.tg.c?theme=frogideas", colorMap["frogideas"][0:2], }, { "test good input with theme and num color", "http://www.tg.c?theme=frogideas&numcolors=4", colorMap["frogideas"], }, { "test bad theme", "http://www.tg.c?theme=bad", colorMap["base"], }, } for _, test := range tests { t.Log(test.title) r := &http.Request{Method: "GET"} r.URL, _ = url.Parse(test.url) colors := Colors(r) 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]) } } } } 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 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", Loading Loading
extract/colors_test.go +69 −2 Original line number Diff line number Diff line Loading @@ -9,14 +9,81 @@ import ( tgColors "github.com/taironas/tinygraphs/colors" ) func TestColors(t *testing.T) { colorMap := tgColors.MapOfColorThemes() tests := []struct { title string url string colors []color.RGBA }{ { "test wrong input", "http://www.tg.c?colors=foo&colors=bar", colorMap["base"], }, { "test no input", "http://www.tg.c", colorMap["base"], }, { "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}, }, }, { "test good input with theme", "http://www.tg.c?theme=frogideas", colorMap["frogideas"][0:2], }, { "test good input with theme and num color", "http://www.tg.c?theme=frogideas&numcolors=4", colorMap["frogideas"], }, { "test bad theme", "http://www.tg.c?theme=bad", colorMap["base"], }, } for _, test := range tests { t.Log(test.title) r := &http.Request{Method: "GET"} r.URL, _ = url.Parse(test.url) colors := Colors(r) 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]) } } } } 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 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", Loading