zeroclickinfo-goodies/t/Uptime.t

177 lines
7.3 KiB
Perl
Raw Normal View History

2014-11-07 14:47:36 -08:00
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Test::Deep;
2014-11-07 14:47:36 -08:00
use DDG::Test::Goodie;
zci answer_type => "uptime";
zci is_cached => 1;
2015-07-16 01:28:41 -07:00
sub build_structure {
2015-07-17 07:19:41 -07:00
my ($title, $subtitle, $percentage, $data, $keys) = @_;
2015-07-16 01:28:41 -07:00
return {
templates => {
group => "list",
options => {
content => "record"
}
},
data => {
2015-07-17 07:19:41 -07:00
title => $title,
subtitle => $subtitle,
2015-07-16 01:28:41 -07:00
record_data => $data,
2015-07-17 07:19:41 -07:00
record_keys => $keys
2015-07-16 01:28:41 -07:00
}
}
}
2015-07-17 07:19:41 -07:00
sub build_list_structure {
my ($percentage, $data) = @_;
return build_structure(
"Implied downtimes for $percentage uptime",
undef,
$percentage,
$data,
["daily", "monthly", "yearly"]
);
}
2015-07-16 01:28:41 -07:00
sub build_text_structure {
my ($percentage) = @_;
2015-07-17 07:19:41 -07:00
return build_structure(
"No downtime or less than a second during a year",
"Implied downtimes for $percentage uptime",
$percentage,
undef,
undef
);
2015-07-16 01:28:41 -07:00
}
2014-11-07 14:47:36 -08:00
ddg_goodie_test(
[qw( DDG::Goodie::Uptime )],
2015-07-16 01:28:41 -07:00
'uptime 99%' => test_zci("Implied downtimes for 99% uptime\n".
"Daily: 14 minutes and 24 seconds\n".
"Monthly: 7 hours and 18 minutes\n".
"Annually: 3 days and 16 hours",
2015-07-17 07:19:41 -07:00
structured_answer => build_list_structure("99%",{
2015-07-16 01:28:41 -07:00
"daily" => "14 minutes and 24 seconds",
"monthly" => "7 hours and 18 minutes",
"yearly" => "3 days and 16 hours"
})),
2014-11-07 14:47:36 -08:00
# Alternate trigger
2015-07-16 01:28:41 -07:00
'uptime of 99%' => test_zci("Implied downtimes for 99% uptime\n".
"Daily: 14 minutes and 24 seconds\n".
"Monthly: 7 hours and 18 minutes\n".
"Annually: 3 days and 16 hours",
2015-07-17 07:19:41 -07:00
structured_answer => build_list_structure("99%",{
2015-07-16 01:28:41 -07:00
"daily" => "14 minutes and 24 seconds",
"monthly" => "7 hours and 18 minutes",
"yearly" => "3 days and 16 hours"
})),
2014-11-07 14:47:36 -08:00
2014-11-09 05:56:28 -08:00
# Startend trigger
2015-07-16 01:28:41 -07:00
'99% uptime' => test_zci("Implied downtimes for 99% uptime\n".
"Daily: 14 minutes and 24 seconds\n".
"Monthly: 7 hours and 18 minutes\n".
"Annually: 3 days and 16 hours",
2015-07-17 07:19:41 -07:00
structured_answer => build_list_structure("99%",{
2015-07-16 01:28:41 -07:00
"daily" => "14 minutes and 24 seconds",
"monthly" => "7 hours and 18 minutes",
"yearly" => "3 days and 16 hours"
})),
2014-11-09 05:56:28 -08:00
2014-11-07 14:47:36 -08:00
# Decimal separator
2015-07-16 01:28:41 -07:00
'uptime 99,99%' => test_zci("Implied downtimes for 99,99% uptime\n".
"Daily: 8 seconds\n".
"Monthly: 4 minutes and 22 seconds\n".
"Annually: 52 minutes and 35 seconds",
2015-07-17 07:19:41 -07:00
structured_answer => build_list_structure("99,99%",{
2015-07-16 01:28:41 -07:00
"daily" => "8 seconds",
"monthly" => "4 minutes and 22 seconds",
"yearly" => "52 minutes and 35 seconds"
})),
'uptime 99.99%' => test_zci("Implied downtimes for 99.99% uptime\n".
"Daily: 8 seconds\n".
"Monthly: 4 minutes and 22 seconds\n".
"Annually: 52 minutes and 35 seconds",
2015-07-17 07:19:41 -07:00
structured_answer => build_list_structure("99.99%",{
2015-07-16 01:28:41 -07:00
"daily" => "8 seconds",
"monthly" => "4 minutes and 22 seconds",
"yearly" => "52 minutes and 35 seconds"
})),
2014-11-07 14:47:36 -08:00
# Grouping allowed on input
2015-07-16 01:28:41 -07:00
'uptime 99.999 999 999%' => test_zci("Implied downtimes for 99.999999999% uptime\n".
"No downtime or less than a second during a year",
structured_answer => build_text_structure("99.999999999%")),
2014-11-07 14:47:36 -08:00
# Less than 100% uptime but close to no downtime
2015-07-16 01:28:41 -07:00
'uptime 99.999999999%' => test_zci("Implied downtimes for 99.999999999% uptime\n".
"No downtime or less than a second during a year",
structured_answer => build_text_structure("99.999999999%")),
2014-11-07 14:47:36 -08:00
# Some parts (but not all) are below 1 second
2015-07-16 01:28:41 -07:00
'uptime 99.9999%' => test_zci("Implied downtimes for 99.9999% uptime\n".
"Daily: less than one second\n".
"Monthly: 2 seconds\n".
"Annually: 31 seconds",
2015-07-17 07:19:41 -07:00
structured_answer => build_list_structure("99.9999%",{
2015-07-16 01:28:41 -07:00
"daily" => "less than one second",
"monthly" => "2 seconds",
"yearly" => "31 seconds"
})),
'uptime 99.99999%' => test_zci("Implied downtimes for 99.99999% uptime\n".
"Daily: less than one second\n".
"Monthly: less than one second\n".
"Annually: 3 seconds",
2015-07-17 07:19:41 -07:00
structured_answer => build_list_structure("99.99999%",{
2015-07-16 01:28:41 -07:00
"daily" => "less than one second",
"monthly" => "less than one second",
"yearly" => "3 seconds"
})),
2015-07-19 09:14:10 -07:00
# Lower limit
'uptime 0%' => test_zci("Implied downtimes for 0% uptime\n".
"Daily: 1 day\n".
"Monthly: 30 days and 10 hours\n".
"Annually: 1 year and 6 hours",
structured_answer => build_list_structure("0%",{
"daily" => "1 day",
"monthly" => "30 days and 10 hours",
"yearly" => "1 year and 6 hours"
})),
'uptime 000%' => test_zci("Implied downtimes for 000% uptime\n".
"Daily: 1 day\n".
"Monthly: 30 days and 10 hours\n".
"Annually: 1 year and 6 hours",
structured_answer => build_list_structure("000%",{
"daily" => "1 day",
"monthly" => "30 days and 10 hours",
"yearly" => "1 year and 6 hours"
})),
2014-11-07 14:47:36 -08:00
# Outside range
'uptime 101%' => undef,
'uptime 100.00000000000000000000000000001%' => undef,
'uptime -10%' => undef,
'uptime -0.00000000000000000000000000001%' => undef,
# Upper limit 100% is not allowed as it would return a tautology
'uptime 100%' => undef,
'uptime 100.00%' => undef,
# Misc bad queries
2014-11-09 05:59:46 -08:00
'uptime 99.99.99%' => undef,
2014-11-07 14:47:36 -08:00
'uptime 99.99' => undef,
'uptime ninety-nine' => undef,
2014-11-09 05:08:23 -08:00
'up time 99%' => undef,
'up time 99%%' => undef
2014-11-07 14:47:36 -08:00
);
2016-05-16 06:18:04 -07:00
done_testing;