Upload code

This commit is contained in:
nxshock 2017-06-23 19:18:15 +05:00
parent b055be1d8e
commit 602c4b0993
6 changed files with 227 additions and 1 deletions

41
comparators_test.go Normal file
View file

@ -0,0 +1,41 @@
package colorcrop
import (
"image/color"
"reflect"
"runtime"
"testing"
)
func TestColorComparators(t *testing.T) {
type In struct {
color1 color.Color
color2 color.Color
}
comparators := []comparator{CmpSquareRGBComponentsDiff, CmpRGBComponentsDiff}
tests := []struct {
in In
out float64
commentary string
}{
{in: In{color.RGBA{0, 0, 0, 255}, color.RGBA{255, 255, 255, 255}},
out: 1.00,
commentary: "Difference between black and white colors"},
{in: In{color.RGBA{255, 255, 255, 255}, color.RGBA{255, 255, 255, 255}},
out: 0.00,
commentary: "Difference between same colors"},
{in: In{color.RGBA{255, 255, 255, 0}, color.RGBA{255, 255, 255, 255}},
out: 0.00,
commentary: "Difference between same colors with different transparency"},
}
for _, comparator := range comparators {
for _, test := range tests {
if CmpSquareRGBComponentsDiff(test.in.color2, test.in.color1) != test.out {
t.Errorf("%s: %s: expected %.2f, got %.2f", runtime.FuncForPC(reflect.ValueOf(comparator).Pointer()).Name(), test.commentary, test.out, CmpSquareRGBComponentsDiff(test.in.color2, test.in.color1))
}
}
}
}