Update tests and fix logic for new front-end

master
Ben Moon 2016-07-08 10:29:38 +01:00
parent 7ef7792978
commit 772e6c8542
2 changed files with 88 additions and 77 deletions

View File

@ -46,7 +46,7 @@ my @dicts = Color::Library->dictionaries(qw(
www www
)); ));
my @dict_colors = map { $_->colors } @dicts; my @dict_colors = map { $_->colors } @dicts;
my %colors = map { (lc $_->title) =~ s/-/ /gr => $_, lc $_->name => $_ } @dict_colors; my %colors = map { (lc $_->title =~ s/-/ /gr) => $_, lc $_->name => $_ } @dict_colors;
my @color_descs = sort { length $b <=> length $a } keys %colors; my @color_descs = sort { length $b <=> length $a } keys %colors;
my %hex_to_color = map { $_->hex => $_ } @dict_colors; my %hex_to_color = map { $_->hex => $_ } @dict_colors;
@ -75,8 +75,11 @@ my $white = Color::Library->color('white');
sub normalize_color { sub normalize_color {
my $color = shift; my $color = shift;
return $color if ref $color eq 'Color::Library::Color';
$color =~ s/-/ /g; $color =~ s/-/ /g;
return $colors{$color} if exists $colors{$color}; return $colors{$color} if exists $colors{$color};
$color =~ s/ //g;
return $colors{$color} if exists $colors{$color};
$color =~ s/^#//gr; $color =~ s/^#//gr;
} }
@ -103,16 +106,18 @@ sub normalize_color_for_template {
$color = delete $color_s->{color}; $color = delete $color_s->{color};
%additional = %$color_s; %additional = %$color_s;
} }
$color = normalize_color($color);
my $name = ''; my $name = '';
my $hex;
if (ref $color eq 'Color::Library::Color') { if (ref $color eq 'Color::Library::Color') {
$name = $color->name; $name = $color->name;
$hex = $color->hex;
} else { } else {
$color = normalize_color($color);
$name = common_name($color); $name = common_name($color);
$hex = $color =~ s/^#//r;
} }
$color = Convert::Color->new("rgb8:$color"); $color = Convert::Color->new("rgb8:$hex");
my @rgb = $color->as_rgb8->rgb8; my @rgb = $color->as_rgb8->rgb8;
my $hex = $color->as_rgb8->hex;
my $hex_disp = 'Hex: #' . uc $hex; my $hex_disp = 'Hex: #' . uc $hex;
my $rgb_disp = 'RGB(' . join(', ', @rgb) . ')'; my $rgb_disp = 'RGB(' . join(', ', @rgb) . ')';
my $hsl = $color->as_hsl; my $hsl = $color->as_hsl;

View File

@ -20,7 +20,7 @@ my %test_builders = (
tint => \&build_answer_tint, tint => \&build_answer_tint,
); );
my $color_re = qr/^#\p{XDigit}{6}$/i; my $color_re = qr/^\p{XDigit}{6}$/i;
sub build_standard_builder { sub build_standard_builder {
my $subtitle_prefix = shift; my $subtitle_prefix = shift;
@ -94,8 +94,7 @@ sub build_structured_answer {
templates => { templates => {
group => "text", group => "text",
options => { options => {
title_content => 'DDH.rgb_color.title_content', content => 'DDH.rgb_color.content',
subtitle_content => 'DDH.rgb_color.sub_list',
}, },
} }
}; };
@ -108,8 +107,12 @@ sub build_test { test_zci(build_structured_answer(@_)) }
################ ################
my $black = { my $black = {
hex => '#000000', hex => '000000',
name => 'black', name => 'black',
cmyb_disp => 'CMYB(0%, 0%, 0%, 100%)',
hex_disp => 'Hex: #000000',
hslc_disp => 'HSL(0, 0%, 0%)',
rgb_disp => 'RGB(0, 0, 0)',
}; };
my $black_9prt = { %$black, amount => 0.9 }; my $black_9prt = { %$black, amount => 0.9 };
@ -117,8 +120,12 @@ my $black_9prt = { %$black, amount => 0.9 };
my $black_1prt = { %$black, amount => 1 }; my $black_1prt = { %$black, amount => 1 };
my $white = { my $white = {
hex => '#ffffff', hex => 'ffffff',
name => 'white', name => 'white',
cmyb_disp => 'CMYB(0%, 0%, 0%, 0%)',
hex_disp => 'Hex: #FFFFFF',
hslc_disp => 'HSL(0, 0%, 100%)',
rgb_disp => 'RGB(255, 255, 255)',
}; };
my $white_1prt = { %$white, amount => 0.1 }; my $white_1prt = { %$white, amount => 0.1 };
@ -126,68 +133,77 @@ my $white_1prt = { %$white, amount => 0.1 };
my $white_0prt = { %$white, amount => 0 }; my $white_0prt = { %$white, amount => 0 };
my $grey = { my $grey = {
hex => '#7f7f7f', hex => '7f7f7f',
name => 'grey50', name => 'grey50',
cmyb_disp => 'CMYB(0%, 0%, 0%, 50%)',
hex_disp => 'Hex: #7F7F7F',
hslc_disp => 'HSL(0, 0%, 50%)',
rgb_disp => 'RGB(127, 127, 127)',
}; };
my $black_9_white_1 = { my $black_9_white_1 = {
hex => '#191919', hex => '191919',
name => '', name => '',
}; cmyb_disp => 'CMYB(0%, 0%, 0%, 90%)',
hex_disp => 'Hex: #191919',
my $pink = { hslc_disp => 'HSL(0, 0%, 10%)',
hex => '#ffc0cb', rgb_disp => 'RGB(25, 25, 25)',
name => 'pink',
}; };
my $blue = { my $blue = {
hex => '#0000ff', hex => '0000ff',
name => 'blue', name => 'blue',
cmyb_disp => 'CMYB(100%, 100%, 0%, 0%)',
hex_disp => 'Hex: #0000FF',
hslc_disp => 'HSL(240, 100%, 50%)',
rgb_disp => 'RGB(0, 0, 255)',
}; };
my $blue1 = { my $blue1 = { %$blue, name => 'blue1' };
hex => '#0000ff',
name => 'blue1',
};
my $orange = {
hex => '#ffa500',
name => 'orange',
};
my $bluish_orange = {
hex => '#7f527f',
name => '',
};
my $pinkish_blue = {
hex => '#7f60e5',
name => '',
};
my $yellow = { my $yellow = {
hex => '#ffff00', hex => 'ffff00',
name => 'yellow', name => 'yellow',
cmyb_disp => 'CMYB(0%, 0%, 100%, 0%)',
hex_disp => 'Hex: #FFFF00',
hslc_disp => 'HSL(60, 100%, 50%)',
rgb_disp => 'RGB(255, 255, 0)',
}; };
my $dark_spring_yellow = { my $dark_spring_yellow = {
hex => '#669900', hex => '669900',
name => 'darkspringyellow', name => 'darkspringyellow',
cmyb_disp => 'CMYB(33%, 0%, 100%, 40%)',
hex_disp => 'Hex: #669900',
hslc_disp => 'HSL(80, 100%, 30%)',
rgb_disp => 'RGB(102, 153, 0)',
}; };
my $light_violet_blue = { my $light_violet_blue = {
hex => '#9966ff', hex => '9966ff',
name => 'lightvioletblue', name => 'lightvioletblue',
cmyb_disp => 'CMYB(40%, 60%, 0%, 0%)',
hex_disp => 'Hex: #9966FF',
hslc_disp => 'HSL(260, 100%, 70%)',
rgb_disp => 'RGB(153, 102, 255)',
}; };
my $sap_green = { my $sap_green = {
hex => '#bdda57', hex => 'bdda57',
name => 'sapgreen', name => 'sapgreen',
cmyb_disp => 'CMYB(13%, 0%, 60%, 15%)',
hex_disp => 'Hex: #BDDA57',
hslc_disp => 'HSL(73, 64%, 60%)',
rgb_disp => 'RGB(189, 218, 87)',
}; };
my $sap_green_opp = { my $sap_green_opp = {
hex => '#4225a8', hex => '4225a8',
name => '', name => '',
cmyb_disp => 'CMYB(61%, 78%, 0%, 34%)',
hex_disp => 'Hex: #4225A8',
hslc_disp => 'HSL(253, 64%, 40%)',
rgb_disp => 'RGB(66, 37, 168)',
}; };
my $tc_mix_black_white = build_test('mix', my $tc_mix_black_white = build_test('mix',
@ -205,16 +221,6 @@ my $tc_mix_black_white_1_0 = build_test('mix',
result_color => $black, result_color => $black,
); );
my $tc_mix_pink_blue = build_test('mix',
input_colors => [$pink, $blue],
result_color => $pinkish_blue,
);
my $tc_mix_blue_orange = build_test('mix',
input_colors => [$blue, $orange],
result_color => $bluish_orange,
);
my $tc_random_black_white = build_test('random', my $tc_random_black_white = build_test('random',
input_colors => [$black, $white], input_colors => [$black, $white],
); );
@ -313,12 +319,12 @@ ddg_goodie_test(
'opposite of sap-green' => $tc_opp_sg, 'opposite of sap-green' => $tc_opp_sg,
'opposite of sap green' => $tc_opp_sg, 'opposite of sap green' => $tc_opp_sg,
# Sample queries (from checking query suggestions) # Sample queries (from checking query suggestions)
'mix pink and blue what color do you get' => $tc_mix_pink_blue, 'mix black and white what color do you get' => $tc_mix_black_white,
'what do you get if you mix blue and orange' => $tc_mix_blue_orange, 'what do you get if you mix black and white' => $tc_mix_black_white,
"what's opposite of blue on the color wheel" => $tc_opp_blue, "what's opposite of blue on the color wheel" => $tc_opp_blue,
'mixing blue and orange makes what color' => $tc_mix_blue_orange, 'mixing black and white makes what color' => $tc_mix_black_white,
'mixing blue and orange makes what' => $tc_mix_blue_orange, 'mixing black and white makes what' => $tc_mix_black_white,
'blue mixed with orange' => $tc_mix_blue_orange, 'black mixed with white' => $tc_mix_black_white,
'black tinted with white' => $tc_tint_black_white, 'black tinted with white' => $tc_tint_black_white,
# Invalid queries # Invalid queries
'color' => undef, 'color' => undef,
@ -327,18 +333,18 @@ ddg_goodie_test(
'color picker ffffff' => undef, 'color picker ffffff' => undef,
'mix' => undef, 'mix' => undef,
# # From sample queries # # From sample queries
'random color names' => undef, 'random color names' => undef,
'mix colors to make black' => undef, 'mix colors to make black' => undef,
'how to mix concrete' => undef, 'how to mix concrete' => undef,
'blue and gold dress' => undef, 'blue and gold dress' => undef,
'opposite of blue raining jane lyrics' => undef, 'opposite of blue raining jane lyrics' => undef,
'pictures of blue rain' => undef, 'pictures of blue rain' => undef,
'blue hex color' => undef, 'blue hex color' => undef,
'complement girl' => undef, 'complement girl' => undef,
'red and blue mixed up spiderman action figure' => undef, 'red and blue mixed up spiderman action figure' => undef,
'red and blue mixed pitbulls' => undef, 'red and blue mixed pitbulls' => undef,
'red + blue light' => undef, 'red + blue light' => undef,
'red + blue bedding' => undef, 'red + blue bedding' => undef,
# # With potential to trigger in the future # # With potential to trigger in the future
'blue and gold' => undef, 'blue and gold' => undef,