2016-07-04 10:57:54 -07:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use Test::More;
|
|
|
|
use Test::Deep;
|
|
|
|
use DDG::Test::Goodie;
|
|
|
|
|
2016-07-04 11:28:09 -07:00
|
|
|
zci answer_type => "rgb_color";
|
2016-07-05 01:29:42 -07:00
|
|
|
zci is_cached => 0;
|
2016-07-04 10:57:54 -07:00
|
|
|
|
2016-07-05 03:45:40 -07:00
|
|
|
###################
|
|
|
|
# Test Builders #
|
|
|
|
###################
|
|
|
|
|
|
|
|
my %test_builders = (
|
|
|
|
mix => \&build_answer_mix,
|
|
|
|
random => \&build_answer_random,
|
2016-07-05 06:42:12 -07:00
|
|
|
reverse => \&build_answer_reverse,
|
2016-07-05 03:45:40 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
my $color_re = qr/^#\p{XDigit}{6}$/i;
|
|
|
|
|
2016-07-05 06:42:12 -07:00
|
|
|
sub build_standard_builder {
|
|
|
|
my $subtitle_prefix = shift;
|
|
|
|
return sub {
|
|
|
|
my %params = @_;
|
|
|
|
return (
|
|
|
|
text_answer => $params{result_color}->{hex},
|
|
|
|
data => {
|
|
|
|
subtitle_prefix => $subtitle_prefix,
|
|
|
|
%params,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-07-05 03:45:40 -07:00
|
|
|
sub build_answer_mix {
|
2016-07-06 03:36:39 -07:00
|
|
|
my %params = @_;
|
|
|
|
my $inps = $params{input_colors};
|
|
|
|
do {
|
|
|
|
my $i = 0;
|
2016-07-06 03:52:51 -07:00
|
|
|
map { $inps->[$i] = { amount => 0.5, %{$_} }; $i++ }
|
2016-07-06 03:36:39 -07:00
|
|
|
@{$params{input_colors}}
|
|
|
|
};
|
|
|
|
$params{input_colors} = $inps;
|
|
|
|
|
|
|
|
build_standard_builder('Mix ')->(%params);
|
2016-07-05 03:45:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
sub build_answer_random {
|
2016-07-05 04:28:40 -07:00
|
|
|
my %params = @_;
|
2016-07-05 03:45:40 -07:00
|
|
|
return (
|
|
|
|
text_answer => re($color_re),
|
2016-07-05 04:28:40 -07:00
|
|
|
data => {
|
2016-07-05 04:56:04 -07:00
|
|
|
result_color => superhashof({
|
|
|
|
hex => re($color_re)
|
|
|
|
}),
|
2016-07-05 04:28:40 -07:00
|
|
|
subtitle_prefix => 'Random color between ',
|
|
|
|
%params,
|
2016-07-05 03:45:40 -07:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2016-07-04 10:57:54 -07:00
|
|
|
|
2016-07-05 06:42:12 -07:00
|
|
|
sub build_answer_reverse {
|
2016-07-05 07:09:50 -07:00
|
|
|
build_standard_builder('(RGB) Opposite color of ')->(@_);
|
2016-07-05 06:42:12 -07:00
|
|
|
}
|
|
|
|
|
2016-07-05 03:45:40 -07:00
|
|
|
sub build_structured_answer {
|
|
|
|
my ($type, %test_params) = @_;
|
|
|
|
my $builder = $test_builders{$type};
|
|
|
|
my %answer = $builder->(%test_params);
|
2016-07-05 01:29:42 -07:00
|
|
|
|
|
|
|
return $answer{text_answer},
|
2016-07-04 10:57:54 -07:00
|
|
|
structured_answer => {
|
|
|
|
|
2016-07-05 01:29:42 -07:00
|
|
|
data => $answer{data},
|
2016-07-04 10:57:54 -07:00
|
|
|
|
|
|
|
templates => {
|
2016-07-05 01:52:14 -07:00
|
|
|
group => "text",
|
|
|
|
options => {
|
2016-07-05 04:28:40 -07:00
|
|
|
title_content => 'DDH.rgb_color.title_content',
|
|
|
|
subtitle_content => 'DDH.rgb_color.sub_list',
|
2016-07-05 01:52:14 -07:00
|
|
|
},
|
2016-07-04 10:57:54 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
sub build_test { test_zci(build_structured_answer(@_)) }
|
|
|
|
|
2016-07-05 03:45:40 -07:00
|
|
|
################
|
|
|
|
# Test Cases #
|
|
|
|
################
|
|
|
|
|
2016-07-05 04:56:04 -07:00
|
|
|
my $black = {
|
|
|
|
hex => '#000000',
|
|
|
|
name => 'black',
|
|
|
|
};
|
|
|
|
|
2016-07-06 03:52:51 -07:00
|
|
|
my $black_9prt = { %$black, amount => 0.9 };
|
2016-07-06 03:36:39 -07:00
|
|
|
|
2016-07-05 04:56:04 -07:00
|
|
|
my $white = {
|
|
|
|
hex => '#ffffff',
|
|
|
|
name => 'white',
|
|
|
|
};
|
|
|
|
|
2016-07-06 03:52:51 -07:00
|
|
|
my $white_1prt = { %$white, amount => 0.1 };
|
2016-07-06 03:36:39 -07:00
|
|
|
|
2016-07-05 04:56:04 -07:00
|
|
|
my $grey = {
|
|
|
|
hex => '#7f7f7f',
|
2016-07-05 10:55:32 -07:00
|
|
|
name => 'grey50',
|
2016-07-05 04:56:04 -07:00
|
|
|
};
|
|
|
|
|
2016-07-06 03:36:39 -07:00
|
|
|
my $black_9_white_1 = {
|
|
|
|
hex => '#191919',
|
|
|
|
name => '',
|
|
|
|
};
|
|
|
|
|
2016-07-05 05:55:17 -07:00
|
|
|
my $pink = {
|
|
|
|
hex => '#ffc0cb',
|
|
|
|
name => 'pink',
|
|
|
|
};
|
|
|
|
|
|
|
|
my $blue = {
|
|
|
|
hex => '#0000ff',
|
|
|
|
name => 'blue',
|
|
|
|
};
|
|
|
|
|
2016-07-05 10:55:32 -07:00
|
|
|
my $blue1 = {
|
|
|
|
hex => '#0000ff',
|
|
|
|
name => 'blue1',
|
|
|
|
};
|
|
|
|
|
2016-07-05 05:55:17 -07:00
|
|
|
my $orange = {
|
|
|
|
hex => '#ffa500',
|
|
|
|
name => 'orange',
|
|
|
|
};
|
|
|
|
|
|
|
|
my $bluish_orange = {
|
|
|
|
hex => '#7f527f',
|
|
|
|
name => '',
|
|
|
|
};
|
|
|
|
|
|
|
|
my $pinkish_blue = {
|
|
|
|
hex => '#7f60e5',
|
|
|
|
name => '',
|
|
|
|
};
|
|
|
|
|
2016-07-05 06:42:12 -07:00
|
|
|
my $yellow = {
|
|
|
|
hex => '#ffff00',
|
|
|
|
name => 'yellow',
|
|
|
|
};
|
|
|
|
|
2016-07-05 10:55:32 -07:00
|
|
|
my $dark_spring_yellow = {
|
|
|
|
hex => '#669900',
|
|
|
|
name => 'darkspringyellow',
|
|
|
|
};
|
|
|
|
|
|
|
|
my $light_violet_blue = {
|
|
|
|
hex => '#9966ff',
|
|
|
|
name => 'lightvioletblue',
|
|
|
|
};
|
|
|
|
|
2016-07-05 04:03:59 -07:00
|
|
|
my $tc_mix_black_white = build_test('mix',
|
2016-07-05 04:56:04 -07:00
|
|
|
input_colors => [$black, $white],
|
|
|
|
result_color => $grey,
|
2016-07-05 03:49:19 -07:00
|
|
|
);
|
|
|
|
|
2016-07-06 03:36:39 -07:00
|
|
|
my $tc_mix_black_white_prt_9_1 = build_test('mix',
|
|
|
|
input_colors => [$black_9prt, $white_1prt],
|
|
|
|
result_color => $black_9_white_1,
|
|
|
|
);
|
|
|
|
|
2016-07-05 05:55:17 -07:00
|
|
|
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,
|
|
|
|
);
|
|
|
|
|
2016-07-05 04:28:40 -07:00
|
|
|
my $tc_random_black_white = build_test('random',
|
2016-07-05 04:56:04 -07:00
|
|
|
input_colors => [$black, $white],
|
2016-07-05 04:28:40 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
my $tc_random_white_black = build_test('random',
|
2016-07-05 04:56:04 -07:00
|
|
|
input_colors => [$white, $black],
|
2016-07-05 04:28:40 -07:00
|
|
|
);
|
|
|
|
|
2016-07-05 06:42:12 -07:00
|
|
|
my $tc_opp_white = build_test('reverse',
|
|
|
|
input_colors => [$white],
|
|
|
|
result_color => $black,
|
|
|
|
);
|
|
|
|
|
|
|
|
my $tc_opp_blue = build_test('reverse',
|
|
|
|
input_colors => [$blue],
|
|
|
|
result_color => $yellow,
|
|
|
|
);
|
|
|
|
|
2016-07-05 10:55:32 -07:00
|
|
|
my $tc_opp_blue1 = build_test('reverse',
|
|
|
|
input_colors => [$blue1],
|
|
|
|
result_color => $yellow,
|
|
|
|
);
|
|
|
|
|
|
|
|
my $tc_opp_dsy = build_test('reverse',
|
|
|
|
input_colors => [$dark_spring_yellow],
|
|
|
|
result_color => $light_violet_blue,
|
|
|
|
);
|
|
|
|
|
2016-07-04 10:57:54 -07:00
|
|
|
ddg_goodie_test(
|
2016-07-05 00:52:33 -07:00
|
|
|
[qw( DDG::Goodie::RgbColor )],
|
2016-07-05 01:29:42 -07:00
|
|
|
# Random colors
|
2016-07-05 04:28:40 -07:00
|
|
|
'random color' => $tc_random_black_white,
|
|
|
|
'rand color' => $tc_random_black_white,
|
|
|
|
# # With bounds
|
|
|
|
'random color between white and black' => $tc_random_white_black,
|
|
|
|
# # # W/o 'and'
|
|
|
|
'random color between black white' => $tc_random_black_white,
|
2016-07-05 01:38:04 -07:00
|
|
|
# Using 'colour'
|
2016-07-05 04:28:40 -07:00
|
|
|
'random colour' => $tc_random_black_white,
|
2016-07-05 07:26:22 -07:00
|
|
|
# Plural (even though it isn't)
|
|
|
|
'random colors' => $tc_random_black_white,
|
2016-07-05 03:45:40 -07:00
|
|
|
# Mixing colors
|
2016-07-05 08:11:11 -07:00
|
|
|
'mix 000000 ffffff' => $tc_mix_black_white,
|
|
|
|
'black and white mixed' => $tc_mix_black_white,
|
2016-07-05 13:23:39 -07:00
|
|
|
'mix black with white' => $tc_mix_black_white,
|
2016-07-06 03:36:39 -07:00
|
|
|
# # With amounts
|
|
|
|
'mix 9 parts black with 1 part white' => $tc_mix_black_white_prt_9_1,
|
|
|
|
# # # Division by zero
|
|
|
|
'mix 0 parts black with 0 parts white' => undef,
|
2016-07-05 03:49:19 -07:00
|
|
|
# # With leading '#'
|
2016-07-05 04:03:59 -07:00
|
|
|
'mix #000000 #ffffff' => $tc_mix_black_white,
|
2016-07-05 03:50:31 -07:00
|
|
|
# # 'and'
|
2016-07-05 04:03:59 -07:00
|
|
|
'mix 000000 and ffffff' => $tc_mix_black_white,
|
|
|
|
# # Using names
|
|
|
|
'mix black and white' => $tc_mix_black_white,
|
2016-07-05 06:42:12 -07:00
|
|
|
# Reversing colors
|
2016-07-05 07:21:36 -07:00
|
|
|
'opposite of white' => $tc_opp_white,
|
|
|
|
'complementary color of white' => $tc_opp_white,
|
|
|
|
'complement white' => $tc_opp_white,
|
|
|
|
'opposite color for white' => $tc_opp_white,
|
2016-07-05 10:55:32 -07:00
|
|
|
# Advanced colors (non-WWW)
|
|
|
|
'opposite of darkspringyellow' => $tc_opp_dsy,
|
|
|
|
'opposite of dark spring-yellow' => $tc_opp_dsy,
|
|
|
|
'opposite of blue1' => $tc_opp_blue1,
|
2016-07-05 05:55:17 -07:00
|
|
|
# Sample queries (from checking query suggestions)
|
|
|
|
'mix pink and blue what color do you get' => $tc_mix_pink_blue,
|
|
|
|
'what do you get if you mix blue and orange' => $tc_mix_blue_orange,
|
2016-07-05 06:42:12 -07:00
|
|
|
"what's opposite of blue on the color wheel" => $tc_opp_blue,
|
2016-07-05 13:31:17 -07:00
|
|
|
'mixing blue and orange makes what color' => $tc_mix_blue_orange,
|
2016-07-05 13:34:23 -07:00
|
|
|
'mixing blue and orange makes what' => $tc_mix_blue_orange,
|
2016-07-05 03:25:25 -07:00
|
|
|
# Invalid queries
|
|
|
|
'color' => undef,
|
|
|
|
'color ffffff' => undef,
|
|
|
|
'color picker' => undef,
|
|
|
|
'color picker ffffff' => undef,
|
2016-07-05 05:48:06 -07:00
|
|
|
'mix' => undef,
|
|
|
|
# # From sample queries
|
2016-07-05 06:03:23 -07:00
|
|
|
'random color names' => undef,
|
|
|
|
'mix colors to make black' => undef,
|
|
|
|
'how to mix concrete' => undef,
|
|
|
|
'blue and gold dress' => undef,
|
|
|
|
'opposite of blue raining jane lyrics' => undef,
|
|
|
|
'pictures of blue rain' => undef,
|
|
|
|
'blue hex color' => undef,
|
2016-07-05 07:21:36 -07:00
|
|
|
'complement girl' => undef,
|
2016-07-05 08:11:11 -07:00
|
|
|
'red and blue mixed up spiderman action figure' => undef,
|
|
|
|
'red and blue mixed pitbulls' => undef,
|
2016-07-05 06:03:23 -07:00
|
|
|
# # With potential to trigger in the future
|
2016-07-05 06:42:12 -07:00
|
|
|
'blue and gold' => undef,
|
2016-07-05 05:48:06 -07:00
|
|
|
|
2016-07-04 10:57:54 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
done_testing;
|