diff --git a/.travis.yml b/.travis.yml index a2f9f9e..692faa3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,4 +11,4 @@ script: - $HOME/gopath/bin/goveralls -service=travis-ci notifications: - email: false \ No newline at end of file + email: false diff --git a/colorconverson_test.go b/colorconverson_test.go index 8ab4fd3..15ff1ec 100644 --- a/colorconverson_test.go +++ b/colorconverson_test.go @@ -8,21 +8,23 @@ import ( func TestColorToLAB(t *testing.T) { tests := []struct { - color color.Color - expectedL, expectedA, expectedB float64 - gotL, gotA, gotB float64 + color color.Color + expL, expA, expB 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, 255, 255}, expectedL: 32.30258667, expectedA: 79.19666179, expectedB: -107.86368104}, - {color: color.RGBA{0, 255, 0, 255}, expectedL: 87.73703347, expectedA: -86.18463650, expectedB: 83.18116475}, - {color: color.RGBA{255, 0, 0, 255}, expectedL: 53.23288179, expectedA: 80.10930953, expectedB: 67.22006831}, - {color: color.RGBA{255, 255, 255, 255}, expectedL: 100.00000000, expectedA: 0.00526050, expectedB: -0.01040818}, + {color: color.RGBA{0, 0, 0, 255}, expL: 0.0, expA: 0.0, expB: 0.0}, + {color: color.RGBA{0, 0, 255, 255}, expL: 32.30258667, expA: 79.19666179, expB: -107.86368104}, + {color: color.RGBA{0, 255, 0, 255}, expL: 87.73703347, expA: -86.18463650, expB: 83.18116475}, + {color: color.RGBA{255, 0, 0, 255}, expL: 53.23288179, expA: 80.10930953, expB: 67.22006831}, + {color: color.RGBA{255, 255, 255, 255}, expL: 100.00000000, expA: 0.00526050, expB: -0.01040818}, } for _, test := range tests { 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 { - 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) + if math.Abs(test.gotL-test.expL) > epsilon || math.Abs(test.gotA-test.expA) > epsilon || + 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) } } } diff --git a/colorcrop_test.go b/colorcrop_test.go index 31d617b..903b53a 100644 --- a/colorcrop_test.go +++ b/colorcrop_test.go @@ -56,7 +56,8 @@ func TestCropRectanle(t *testing.T) { } test.got = cropRectanle(image, color.RGBA{255, 255, 255, 255}, thresold, comparator) 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) test.gotWidth, test.gotHeight = getImageSize(newImage) 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) test.gotWidth, test.gotHeight = getImageSize(newImage) 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) } } } diff --git a/comparators_test.go b/comparators_test.go index b61f949..7bf988d 100644 --- a/comparators_test.go +++ b/comparators_test.go @@ -10,23 +10,24 @@ func TestLinearComparators(t *testing.T) { comparators := []comparator{CmpEuclidean, CmpRGBComponents} tests := []struct { - color1 color.Color - color2 color.Color - expected float64 - got float64 + color1 color.Color + color2 color.Color + exp 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{255, 255, 255, 255}, color2: color.RGBA{255, 255, 255, 255}, expected: 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{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, 0}, color2: color.RGBA{255, 255, 255, 255}, expected: 0.00}, // must ignore alpha channel + {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}, exp: 0.00}, // same 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}, exp: 1.00}, // different (white and black) colors + {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 _, test := range tests { test.got = comparator(test.color1, test.color2) - if math.Abs(test.got-test.expected) > epsilon { - t.Errorf("%v %v: expected %.8f, got %.8f", test.color1, test.color2, test.expected, test.got) + if math.Abs(test.got-test.exp) > epsilon { + 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) { type test struct { - color1 color.Color - color2 color.Color - expected float64 - got float64 + color1 color.Color + color2 color.Color + exp float64 + got float64 } 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{255, 255, 255, 255}, color2: color.RGBA{255, 255, 255, 255}, expected: 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{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, 0, 0, 255}, color2: color.RGBA{255, 255, 255, 255}, expected: 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, 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, 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}, exp: 0.00000000 / 149.95514755}, // same 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}, exp: 100.00000068 / 149.95514755}, // different (white and black) 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}, exp: 120.41559907 / 149.95514755}, // different (green 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 { test.got = CmpCIE76(test.color1, test.color2) - if math.Abs(test.got-test.expected) > epsilon { - t.Errorf("%v %v: expected %.8f, got %.8f", test.color1, test.color2, test.expected, test.got) + if math.Abs(test.got-test.exp) > epsilon { + 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 { test.got = min(test.x, test.y) 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 { test.got = max(test.x, test.y) 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) } } }