Some code reformat for removing long lines

This commit is contained in:
nxshock 2017-07-03 22:24:47 +05:00
parent c6b551bda9
commit 2882a3450f
4 changed files with 49 additions and 40 deletions

View file

@ -11,4 +11,4 @@ script:
- $HOME/gopath/bin/goveralls -service=travis-ci - $HOME/gopath/bin/goveralls -service=travis-ci
notifications: notifications:
email: false email: false

View file

@ -8,21 +8,23 @@ import (
func TestColorToLAB(t *testing.T) { func TestColorToLAB(t *testing.T) {
tests := []struct { tests := []struct {
color color.Color color color.Color
expectedL, expectedA, expectedB float64 expL, expA, expB float64
gotL, gotA, gotB float64 gotL, gotA, gotB float64
}{ }{
{color: color.RGBA{0, 0, 0, 255}, expectedL: 0.0, expectedA: 0.0, expectedB: 0.0}, {color: color.RGBA{0, 0, 0, 255}, expL: 0.0, expA: 0.0, expB: 0.0},
{color: color.RGBA{0, 0, 255, 255}, expectedL: 32.30258667, expectedA: 79.19666179, expectedB: -107.86368104}, {color: color.RGBA{0, 0, 255, 255}, expL: 32.30258667, expA: 79.19666179, expB: -107.86368104},
{color: color.RGBA{0, 255, 0, 255}, expectedL: 87.73703347, expectedA: -86.18463650, expectedB: 83.18116475}, {color: color.RGBA{0, 255, 0, 255}, expL: 87.73703347, expA: -86.18463650, expB: 83.18116475},
{color: color.RGBA{255, 0, 0, 255}, expectedL: 53.23288179, expectedA: 80.10930953, expectedB: 67.22006831}, {color: color.RGBA{255, 0, 0, 255}, expL: 53.23288179, expA: 80.10930953, expB: 67.22006831},
{color: color.RGBA{255, 255, 255, 255}, expectedL: 100.00000000, expectedA: 0.00526050, expectedB: -0.01040818}, {color: color.RGBA{255, 255, 255, 255}, expL: 100.00000000, expA: 0.00526050, expB: -0.01040818},
} }
for _, test := range tests { for _, test := range tests {
test.gotL, test.gotA, test.gotB = colorToLAB(test.color) test.gotL, test.gotA, test.gotB = colorToLAB(test.color)
if math.Abs(test.gotL-test.expectedL) > epsilon || math.Abs(test.gotA-test.expectedA) > epsilon || math.Abs(test.gotB-test.expectedB) > epsilon { if math.Abs(test.gotL-test.expL) > epsilon || math.Abs(test.gotA-test.expA) > epsilon ||
t.Errorf("%v: expected {%.8f, %.8f, %.8f}, got {%.8f, %.8f, %.8f}", test.color, test.expectedL, test.expectedA, test.expectedB, test.gotL, test.gotA, test.gotB) math.Abs(test.gotB-test.expB) > epsilon {
t.Errorf("%v: expected {%.8f, %.8f, %.8f}, got {%.8f, %.8f, %.8f}",
test.color, test.expL, test.expA, test.expB, test.gotL, test.gotA, test.gotB)
} }
} }
} }

View file

@ -56,7 +56,8 @@ func TestCropRectanle(t *testing.T) {
} }
test.got = cropRectanle(image, color.RGBA{255, 255, 255, 255}, thresold, comparator) test.got = cropRectanle(image, color.RGBA{255, 255, 255, 255}, thresold, comparator)
if !reflect.DeepEqual(test.expected, test.got) { if !reflect.DeepEqual(test.expected, test.got) {
t.Errorf("expected %v, got %v for comparator: %s, file: %s", test.expected, test.got, getFuncName(comparator), test.filename) t.Errorf("expected %v, got %v for comparator: %s, file: %s",
test.expected, test.got, getFuncName(comparator), test.filename)
} }
} }
} }
@ -106,7 +107,8 @@ func TestCropWithComparator(t *testing.T) {
newImage := CropWithComparator(image, color, thresold, comparator) newImage := CropWithComparator(image, color, thresold, comparator)
test.gotWidth, test.gotHeight = getImageSize(newImage) test.gotWidth, test.gotHeight = getImageSize(newImage)
if test.gotWidth != test.expectedWidth || test.gotHeight != test.expectedWidth { if test.gotWidth != test.expectedWidth || test.gotHeight != test.expectedWidth {
t.Errorf("expected {%d %d}, got {%d %d} for comparator: %s, file: %s", test.expectedWidth, test.expectedWidth, test.gotWidth, test.gotHeight, getFuncName(comparator), test.filename) t.Errorf("expected {%d %d}, got {%d %d} for comparator: %s, file: %s",
test.expectedWidth, test.expectedWidth, test.gotWidth, test.gotHeight, getFuncName(comparator), test.filename)
} }
} }
} }
@ -154,7 +156,8 @@ func TestCrop(t *testing.T) {
newImage := Crop(image, color, thresold) newImage := Crop(image, color, thresold)
test.gotWidth, test.gotHeight = getImageSize(newImage) test.gotWidth, test.gotHeight = getImageSize(newImage)
if test.gotWidth != test.expectedWidth || test.gotHeight != test.expectedWidth { if test.gotWidth != test.expectedWidth || test.gotHeight != test.expectedWidth {
t.Errorf("expected {%d %d}, got {%d %d} for file: %s", test.expectedWidth, test.expectedWidth, test.gotWidth, test.gotHeight, test.filename) t.Errorf("expected {%d %d}, got {%d %d} for file: %s",
test.expectedWidth, test.expectedWidth, test.gotWidth, test.gotHeight, test.filename)
} }
} }
} }

View file

@ -10,23 +10,24 @@ func TestLinearComparators(t *testing.T) {
comparators := []comparator{CmpEuclidean, CmpRGBComponents} comparators := []comparator{CmpEuclidean, CmpRGBComponents}
tests := []struct { tests := []struct {
color1 color.Color color1 color.Color
color2 color.Color color2 color.Color
expected float64 exp float64
got float64 got float64
}{ }{
{color1: color.RGBA{0, 0, 0, 255}, color2: color.RGBA{0, 0, 0, 255}, expected: 0.00}, // same black colors {color1: color.RGBA{0, 0, 0, 255}, color2: color.RGBA{0, 0, 0, 255}, exp: 0.00}, // same black colors
{color1: color.RGBA{255, 255, 255, 255}, color2: color.RGBA{255, 255, 255, 255}, expected: 0.00}, // same white colors {color1: color.RGBA{255, 255, 255, 255}, color2: color.RGBA{255, 255, 255, 255}, exp: 0.00}, // same white colors
{color1: color.RGBA{0, 0, 0, 255}, color2: color.RGBA{255, 255, 255, 255}, expected: 1.00}, // different (black and white) colors {color1: color.RGBA{0, 0, 0, 255}, color2: color.RGBA{255, 255, 255, 255}, exp: 1.00}, // different (black and white) colors
{color1: color.RGBA{255, 255, 255, 255}, color2: color.RGBA{0, 0, 0, 255}, expected: 1.00}, // different (white and black) colors {color1: color.RGBA{255, 255, 255, 255}, color2: color.RGBA{0, 0, 0, 255}, exp: 1.00}, // different (white and black) colors
{color1: color.RGBA{255, 255, 255, 0}, color2: color.RGBA{255, 255, 255, 255}, expected: 0.00}, // must ignore alpha channel {color1: color.RGBA{255, 255, 255, 0}, color2: color.RGBA{255, 255, 255, 255}, exp: 0.00}, // must ignore alpha channel
} }
for _, comparator := range comparators { for _, comparator := range comparators {
for _, test := range tests { for _, test := range tests {
test.got = comparator(test.color1, test.color2) test.got = comparator(test.color1, test.color2)
if math.Abs(test.got-test.expected) > epsilon { if math.Abs(test.got-test.exp) > epsilon {
t.Errorf("%v %v: expected %.8f, got %.8f", test.color1, test.color2, test.expected, test.got) t.Errorf("%v %v: expected %.8f, got %.8f",
test.color1, test.color2, test.exp, test.got)
} }
} }
} }
@ -34,26 +35,27 @@ func TestLinearComparators(t *testing.T) {
func TestCmpCIE76(t *testing.T) { func TestCmpCIE76(t *testing.T) {
type test struct { type test struct {
color1 color.Color color1 color.Color
color2 color.Color color2 color.Color
expected float64 exp float64
got float64 got float64
} }
tests := []test{ tests := []test{
{color1: color.RGBA{0, 0, 0, 255}, color2: color.RGBA{0, 0, 0, 255}, expected: 0.00000000 / 149.95514755}, // same black colors {color1: color.RGBA{0, 0, 0, 255}, color2: color.RGBA{0, 0, 0, 255}, exp: 0.00000000 / 149.95514755}, // same black colors
{color1: color.RGBA{255, 255, 255, 255}, color2: color.RGBA{255, 255, 255, 255}, expected: 0.00000000 / 149.95514755}, // same white colors {color1: color.RGBA{255, 255, 255, 255}, color2: color.RGBA{255, 255, 255, 255}, exp: 0.00000000 / 149.95514755}, // same white colors
{color1: color.RGBA{0, 0, 0, 255}, color2: color.RGBA{255, 255, 255, 255}, expected: 100.00000068 / 149.95514755}, // different (black and white) colors {color1: color.RGBA{0, 0, 0, 255}, color2: color.RGBA{255, 255, 255, 255}, exp: 100.00000068 / 149.95514755}, // different (black and white) colors
{color1: color.RGBA{255, 255, 255, 255}, color2: color.RGBA{0, 0, 0, 255}, expected: 100.00000068 / 149.95514755}, // different (white and black) colors {color1: color.RGBA{255, 255, 255, 255}, color2: color.RGBA{0, 0, 0, 255}, exp: 100.00000068 / 149.95514755}, // different (white and black) colors
{color1: color.RGBA{255, 0, 0, 255}, color2: color.RGBA{255, 255, 255, 255}, expected: 114.55897602 / 149.95514755}, // different (red and white) colors {color1: color.RGBA{255, 0, 0, 255}, color2: color.RGBA{255, 255, 255, 255}, exp: 114.55897602 / 149.95514755}, // different (red and white) colors
{color1: color.RGBA{0, 255, 0, 255}, color2: color.RGBA{255, 255, 255, 255}, expected: 120.41559907 / 149.95514755}, // different (green and white) colors {color1: color.RGBA{0, 255, 0, 255}, color2: color.RGBA{255, 255, 255, 255}, exp: 120.41559907 / 149.95514755}, // different (green and white) colors
{color1: color.RGBA{0, 0, 255, 255}, color2: color.RGBA{255, 255, 255, 255}, expected: 149.95514755 / 149.95514755}, // different (blue and white) colors {color1: color.RGBA{0, 0, 255, 255}, color2: color.RGBA{255, 255, 255, 255}, exp: 149.95514755 / 149.95514755}, // different (blue and white) colors
} }
for _, test := range tests { for _, test := range tests {
test.got = CmpCIE76(test.color1, test.color2) test.got = CmpCIE76(test.color1, test.color2)
if math.Abs(test.got-test.expected) > epsilon { if math.Abs(test.got-test.exp) > epsilon {
t.Errorf("%v %v: expected %.8f, got %.8f", test.color1, test.color2, test.expected, test.got) t.Errorf("%v %v: expected %.8f, got %.8f",
test.color1, test.color2, test.exp, test.got)
} }
} }
} }
@ -75,7 +77,8 @@ func TestMin(t *testing.T) {
for _, test := range tests { for _, test := range tests {
test.got = min(test.x, test.y) test.got = min(test.x, test.y)
if test.got != test.expected { if test.got != test.expected {
t.Errorf("min(%d, %d): expected %d, got %d", test.x, test.y, test.expected, test.got) t.Errorf("min(%d, %d): expected %d, got %d",
test.x, test.y, test.expected, test.got)
} }
} }
} }
@ -97,7 +100,8 @@ func TestMax(t *testing.T) {
for _, test := range tests { for _, test := range tests {
test.got = max(test.x, test.y) test.got = max(test.x, test.y)
if test.got != test.expected { if test.got != test.expected {
t.Errorf("max(%d, %d): expected %d, got %d", test.x, test.y, test.expected, test.got) t.Errorf("max(%d, %d): expected %d, got %d",
test.x, test.y, test.expected, test.got)
} }
} }
} }