#!/usr/bin/perl -w use strict; sub compare { my $testsDiff = [[[68,208,59], [216,251,177]], [[255,0,0], [0,75,0]], [[176,16,0], [39,9,197]], [[0,51,242], [172,26,255]], [[114,12,182], [157,0,10]], [[6,36,21], [88,31,0]], [[159,89,1], [0,131,0]], [[221,179,111], [125,212,130]], [[85,85,85], [0,0,0]], [[154,117,252], [253,79,185]], [[199,3,247], [110,16,252]], [[136,2,8], [16,11,11]], [[42,34,160], [0,4,13]], [[135,12,80], [44,47,99]], [[47,31,24], [143,3,66]], [[111,250,44], [228,230,10]], [[162,252,157], [215,236,89]], [[228,230,10], [111,250,44]], [[215,236,89], [162,252,157]], [[64,32,251], [160,72,228]], [[50,214,70], [226,238,190]], [[163,16,39], [38,0,7]], [[77,0,231], [190,43,237]], [[172,206,0], [255,255,239]], [[174,173,219], [227,253,205]], [[226,213,221], [244,134,201]]]; my $testsSame = [[[11,246,168], [79,243,160]], [[0,75,242], [9,19,222]], [[1,39,0], [16,8,46]], [[6,214,120], [60,248,135]], [[203,249,6], [249,251,147], [240,221,45]], [[64,32,251], [128,79,253]], [[95,6,220], [160,72,228]], [[118,216,147], [150,184,88]], [[0,125,0], [53,79,41]], [[227,255,157], [158,234,52]], [[75,154,229], [75,164,170], [1,184,206]], [[224,23,21], [240,77,18], [186,35,36]], [[186,41,198], [218,50,254], [198,74,178]], [[254,7,207], [218,50,254]], [[0,18,196], [87,1,251]], [[255,115,204], [199,98,175], [236,145,254], [255,66,230], [233,47,155]], [[199,98,175], [202,1,235], [236,145,254], [255,66,230], [233,47,155]], [[0,119,23], [85,98,70]], [[95,6,220], [128,79,253]], [[64,64,64], [128,128,128]], [[2,255,229], [139,248,217]], [[230,223,254], [191,214,214]], [[36,58,173], [13,1,224], [34,0,154], [4,5,93]], [[182,0,1], [218,26,2], [202,0,48]], [[2,254,113], [0,253,5]], [[54,22,41], [32,24,0], [3,0,10]], [[180,0,251], [159,47,252]], [[86,12,92], [102,23,129]]]; foreach my $test (@$testsDiff, @$testsSame) { foreach my $color (@$test) { $color = { 'red' => $color->[0], 'green' => $color->[1], 'blue' => $color->[2], }; } } foreach my $test (@$testsDiff) { my $master = shift @$test; foreach (@$test) { die if colorsAreSimilar($master, $_); } } foreach my $test (@$testsSame) { my $master = shift @$test; foreach (@$test) { die unless colorsAreSimilar($master, $_); } } print "pass\n"; } # ======================================================================== use color; sub colorsAreSimilar { return color::similar(@_); } # ======================================================================== compare();