errors now return empty string per guidelines
parent
a4ad0b8f76
commit
fea97fdb74
|
@ -46,11 +46,6 @@ sub doConversion {
|
|||
my $result = '';
|
||||
my $hasErrors = 0;
|
||||
|
||||
my %errors = (
|
||||
'factor' => 'ERROR :: Cannot convert [QQQQQ] :: NaN.',
|
||||
'units' => 'ERROR :: Cannot convert [QQQQQ] :: Unknown units.',
|
||||
);
|
||||
|
||||
my @required = qw/1 3/; # 1 = fromUnits, 2 = toUnits
|
||||
|
||||
# add new units for conversion here.
|
||||
|
@ -138,24 +133,16 @@ sub doConversion {
|
|||
|
||||
if (!$found) {
|
||||
$hasErrors = 1;
|
||||
|
||||
#$result .= ($errors{'units'} =~ s/QQQQQ/$args[$required]/);
|
||||
$errors{'units'} =~ s/QQQQQ/$args[$required]/;
|
||||
$result .= $errors{'units'};
|
||||
|
||||
$result = '';
|
||||
}
|
||||
|
||||
$errors{'units'} = 'ERROR :: Cannot convert [QQQQQ] :: Unknown units.';
|
||||
}
|
||||
|
||||
# $args[0] must be a number:
|
||||
if ($hasErrors || !looks_like_number($args[0])) {
|
||||
if (!looks_like_number($args[0])) {
|
||||
# keeping errors in order:
|
||||
$errors{'factor'} =~ s/QQQQQ/$args[0]/;
|
||||
$result = ($errors{'factor'} . $result);
|
||||
$result = '';
|
||||
}
|
||||
|
||||
#$result =~ s/ERROR/\nERROR/g;
|
||||
}
|
||||
|
||||
else { # run the conversion:
|
||||
|
@ -187,8 +174,6 @@ sub doConversion {
|
|||
$result = "$origArgs[0] $origArgs[1] is $result $origArgs[3].";
|
||||
}
|
||||
|
||||
#$result =~ s/^\n//;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,37 +17,37 @@ ddg_goodie_test(
|
|||
# [ 1]: good $factor, bad $toUnits, bad $fromUnits
|
||||
'convert 12 pipes to tokes' =>
|
||||
test_zci(
|
||||
'ERROR :: Cannot convert [pipes] :: Unknown units.ERROR :: Cannot convert [tokes] :: Unknown units.',
|
||||
'',
|
||||
);
|
||||
|
||||
# [ 2]: good $factor, bad $toUnits, good $fromUnits
|
||||
'convert 0.99 dogs to ounces' =>
|
||||
test_zci(
|
||||
'ERROR :: Cannot convert [dogs] :: Unknown units.',
|
||||
'',
|
||||
);
|
||||
|
||||
# [ 3]: good $factor, good $toUnits, bad $fromUnits
|
||||
'convert 1 ton to kitty litter' =>
|
||||
test_zci(
|
||||
'ERROR :: Cannot convert [kitty] :: Unknown units.',
|
||||
'',
|
||||
);
|
||||
|
||||
# [ 4]: bad $factor, bad $toUnits, bad $fromUnits
|
||||
'convert bradley david to andersen' =>
|
||||
test_zci(
|
||||
'ERROR :: Cannot convert [bradley] :: NaN.ERROR :: Cannot convert [david] :: Unknown units.ERROR :: Cannot convert [andersen] :: Unknown units.',
|
||||
'',
|
||||
);
|
||||
|
||||
# [ 5]: bad $factor, bad $toUnits, good $fromUnits
|
||||
'convert ddg ducks to metric tons' =>
|
||||
test_zci(
|
||||
'ERROR :: Cannot convert [ddg] :: NaN.ERROR :: Cannot convert [ducks] :: Unknown units.',
|
||||
'',
|
||||
);
|
||||
|
||||
# [ 6]: bad $factor, good $toUnits, bad $fromUnits
|
||||
'convert soil grams to beans' =>
|
||||
test_zci(
|
||||
'ERROR :: Cannot convert [soil] :: NaN.ERROR :: Cannot convert [beans] :: Unknown units.',
|
||||
'',
|
||||
);
|
||||
|
||||
# and now a few success cases ... let's round it up to 10:
|
||||
|
|
Loading…
Reference in New Issue