Skip to content
Browse files

Added (ohms) text to resistors Goodie. Removed bold.

  • Loading branch information...
1 parent 0d66557 commit 11155d9bf604484d34c863867fecca85b13ff283 Joe Walnes committed with nospampleasemam
Showing with 46 additions and 45 deletions.
  1. +3 −2 lib/DDG/Goodie/ResistorColors.pm
  2. +43 −43 t/ResistorColors.t
View
5 lib/DDG/Goodie/ResistorColors.pm
@@ -113,8 +113,9 @@ sub format_value {
sub render {
my ($value, $digits) = @_;
my $formatted_value = format_value($value);
- my $text = "$formatted_value\x{2126} resistor colors:";
- my $html = "<b>$formatted_value&#x2126; resistor colors:</b>";
+ my $ohms = $formatted_value eq '1' ? 'ohm' : 'ohms';
+ my $text = "$formatted_value\x{2126} ($ohms) resistor colors:";
+ my $html = "$formatted_value&#x2126; ($ohms) resistor colors:";
foreach my $digit (@$digits) {
if (exists $digits_to_colors{$digit}) {
View
86 t/ResistorColors.t
@@ -14,62 +14,62 @@ ddg_goodie_test(
)],
# Check trigger kicks in.
- "330 ohms" => test_zci("330\x{2126} resistor colors: orange orange black black", html => qr/./),
- "330 ohm" => test_zci("330\x{2126} resistor colors: orange orange black black", html => qr/./),
- "330 \x{2126}" => test_zci("330\x{2126} resistor colors: orange orange black black", html => qr/./),
- "330ohms" => test_zci("330\x{2126} resistor colors: orange orange black black", html => qr/./),
- "330ohm" => test_zci("330\x{2126} resistor colors: orange orange black black", html => qr/./),
- "330\x{2126}" => test_zci("330\x{2126} resistor colors: orange orange black black", html => qr/./),
+ "330 ohms" => test_zci("330\x{2126} (ohms) resistor colors: orange orange black black", html => qr/./),
+ "330 ohm" => test_zci("330\x{2126} (ohms) resistor colors: orange orange black black", html => qr/./),
+ "330 \x{2126}" => test_zci("330\x{2126} (ohms) resistor colors: orange orange black black", html => qr/./),
+ "330ohms" => test_zci("330\x{2126} (ohms) resistor colors: orange orange black black", html => qr/./),
+ "330ohm" => test_zci("330\x{2126} (ohms) resistor colors: orange orange black black", html => qr/./),
+ "330\x{2126}" => test_zci("330\x{2126} (ohms) resistor colors: orange orange black black", html => qr/./),
# Various multipliers
- "472000 ohms" => test_zci("472K\x{2126} resistor colors: yellow purple red orange", html => qr/./),
- "400000 ohms" => test_zci("400K\x{2126} resistor colors: yellow black black orange", html => qr/./),
- "12300 ohms" => test_zci("12.3K\x{2126} resistor colors: brown red orange red", html => qr/./),
+ "472000 ohms" => test_zci("472K\x{2126} (ohms) resistor colors: yellow purple red orange", html => qr/./),
+ "400000 ohms" => test_zci("400K\x{2126} (ohms) resistor colors: yellow black black orange", html => qr/./),
+ "12300 ohms" => test_zci("12.3K\x{2126} (ohms) resistor colors: brown red orange red", html => qr/./),
# Rounding
- "1.2345 ohms" => test_zci("1.23\x{2126} resistor colors: brown red orange silver", html => qr/./),
- "1.2355 ohms" => test_zci("1.24\x{2126} resistor colors: brown red yellow silver", html => qr/./),
- "12.345 ohms" => test_zci("12.3\x{2126} resistor colors: brown red orange gold", html => qr/./),
- "12.355 ohms" => test_zci("12.4\x{2126} resistor colors: brown red yellow gold", html => qr/./),
- "123.45 ohms" => test_zci("123\x{2126} resistor colors: brown red orange black", html => qr/./),
- "123.55 ohms" => test_zci("124\x{2126} resistor colors: brown red yellow black", html => qr/./),
- "1234.5 ohms" => test_zci("1.23K\x{2126} resistor colors: brown red orange brown", html => qr/./),
- "1235.5 ohms" => test_zci("1.24K\x{2126} resistor colors: brown red yellow brown", html => qr/./),
- "12345 ohms" => test_zci("12.3K\x{2126} resistor colors: brown red orange red", html => qr/./),
- "12355 ohms" => test_zci("12.4K\x{2126} resistor colors: brown red yellow red", html => qr/./),
- "123450 ohms" => test_zci("123K\x{2126} resistor colors: brown red orange orange", html => qr/./),
- "123550 ohms" => test_zci("124K\x{2126} resistor colors: brown red yellow orange", html => qr/./),
- "1234500 ohms" => test_zci("1.23M\x{2126} resistor colors: brown red orange yellow", html => qr/./),
- "1235500 ohms" => test_zci("1.24M\x{2126} resistor colors: brown red yellow yellow", html => qr/./),
- "12345000 ohms" => test_zci("12.3M\x{2126} resistor colors: brown red orange green", html => qr/./),
- "12355000 ohms" => test_zci("12.4M\x{2126} resistor colors: brown red yellow green", html => qr/./),
- "123450000 ohms" => test_zci("123M\x{2126} resistor colors: brown red orange blue", html => qr/./),
- "123550000 ohms" => test_zci("124M\x{2126} resistor colors: brown red yellow blue", html => qr/./),
- "1234500000 ohms" => test_zci("1230M\x{2126} resistor colors: brown red orange purple", html => qr/./),
- "1235500000 ohms" => test_zci("1240M\x{2126} resistor colors: brown red yellow purple", html => qr/./),
+ "1.2345 ohms" => test_zci("1.23\x{2126} (ohms) resistor colors: brown red orange silver", html => qr/./),
+ "1.2355 ohms" => test_zci("1.24\x{2126} (ohms) resistor colors: brown red yellow silver", html => qr/./),
+ "12.345 ohms" => test_zci("12.3\x{2126} (ohms) resistor colors: brown red orange gold", html => qr/./),
+ "12.355 ohms" => test_zci("12.4\x{2126} (ohms) resistor colors: brown red yellow gold", html => qr/./),
+ "123.45 ohms" => test_zci("123\x{2126} (ohms) resistor colors: brown red orange black", html => qr/./),
+ "123.55 ohms" => test_zci("124\x{2126} (ohms) resistor colors: brown red yellow black", html => qr/./),
+ "1234.5 ohms" => test_zci("1.23K\x{2126} (ohms) resistor colors: brown red orange brown", html => qr/./),
+ "1235.5 ohms" => test_zci("1.24K\x{2126} (ohms) resistor colors: brown red yellow brown", html => qr/./),
+ "12345 ohms" => test_zci("12.3K\x{2126} (ohms) resistor colors: brown red orange red", html => qr/./),
+ "12355 ohms" => test_zci("12.4K\x{2126} (ohms) resistor colors: brown red yellow red", html => qr/./),
+ "123450 ohms" => test_zci("123K\x{2126} (ohms) resistor colors: brown red orange orange", html => qr/./),
+ "123550 ohms" => test_zci("124K\x{2126} (ohms) resistor colors: brown red yellow orange", html => qr/./),
+ "1234500 ohms" => test_zci("1.23M\x{2126} (ohms) resistor colors: brown red orange yellow", html => qr/./),
+ "1235500 ohms" => test_zci("1.24M\x{2126} (ohms) resistor colors: brown red yellow yellow", html => qr/./),
+ "12345000 ohms" => test_zci("12.3M\x{2126} (ohms) resistor colors: brown red orange green", html => qr/./),
+ "12355000 ohms" => test_zci("12.4M\x{2126} (ohms) resistor colors: brown red yellow green", html => qr/./),
+ "123450000 ohms" => test_zci("123M\x{2126} (ohms) resistor colors: brown red orange blue", html => qr/./),
+ "123550000 ohms" => test_zci("124M\x{2126} (ohms) resistor colors: brown red yellow blue", html => qr/./),
+ "1234500000 ohms" => test_zci("1230M\x{2126} (ohms) resistor colors: brown red orange purple", html => qr/./),
+ "1235500000 ohms" => test_zci("1240M\x{2126} (ohms) resistor colors: brown red yellow purple", html => qr/./),
# kilo and mega multipliers
- "27kohm" => test_zci("27K\x{2126} resistor colors: red purple black red", html => qr/./),
- "27Kohm" => test_zci("27K\x{2126} resistor colors: red purple black red", html => qr/./),
- "27 K ohm" => test_zci("27K\x{2126} resistor colors: red purple black red", html => qr/./),
- "4K2 ohm" => test_zci("4.2K\x{2126} resistor colors: yellow red black brown", html => qr/./),
- "4.2K ohm" => test_zci("4.2K\x{2126} resistor colors: yellow red black brown", html => qr/./),
+ "27kohm" => test_zci("27K\x{2126} (ohms) resistor colors: red purple black red", html => qr/./),
+ "27Kohm" => test_zci("27K\x{2126} (ohms) resistor colors: red purple black red", html => qr/./),
+ "27 K ohm" => test_zci("27K\x{2126} (ohms) resistor colors: red purple black red", html => qr/./),
+ "4K2 ohm" => test_zci("4.2K\x{2126} (ohms) resistor colors: yellow red black brown", html => qr/./),
+ "4.2K ohm" => test_zci("4.2K\x{2126} (ohms) resistor colors: yellow red black brown", html => qr/./),
# Decimal points
- "2.9ohm" => test_zci("2.9\x{2126} resistor colors: red white black silver", html => qr/./),
+ "2.9ohm" => test_zci("2.9\x{2126} (ohms) resistor colors: red white black silver", html => qr/./),
# Negative multipliers
- "1 ohm" => test_zci("1\x{2126} resistor colors: brown black black silver", html => qr/./),
- "29 ohms" => test_zci("29\x{2126} resistor colors: red white black gold", html => qr/./),
+ "1 ohm" => test_zci("1\x{2126} (ohm) resistor colors: brown black black silver", html => qr/./),
+ "29 ohms" => test_zci("29\x{2126} (ohms) resistor colors: red white black gold", html => qr/./),
# Zero special case
- "0 ohms" => test_zci("0\x{2126} resistor colors: black black black black", html => qr/./),
+ "0 ohms" => test_zci("0\x{2126} (ohms) resistor colors: black black black black", html => qr/./),
# Range
- "999000M ohms" => test_zci("999000M\x{2126} resistor colors: white white white white", html => qr/./),
+ "999000M ohms" => test_zci("999000M\x{2126} (ohms) resistor colors: white white white white", html => qr/./),
"999500M ohms" => undef,
- "1.1 ohms" => test_zci("1.1\x{2126} resistor colors: brown brown black silver", html => qr/./),
- "1 ohms" => test_zci("1\x{2126} resistor colors: brown black black silver", html => qr/./),
+ "1.1 ohms" => test_zci("1.1\x{2126} (ohms) resistor colors: brown brown black silver", html => qr/./),
+ "1 ohms" => test_zci("1\x{2126} (ohm) resistor colors: brown black black silver", html => qr/./),
"0.9 ohms" => undef,
"-10 ohms" => undef,
@@ -80,8 +80,8 @@ ddg_goodie_test(
"ohm ma darling" => undef,
# Check the HTML. Just once.
- "1.58m ohm" => test_zci("1.58M\x{2126} resistor colors: brown green gray yellow", html =>
- "<b>1.58M&#x2126; resistor colors:</b> "
+ "1.58m ohm" => test_zci("1.58M\x{2126} (ohms) resistor colors: brown green gray yellow", html =>
+ "1.58M&#x2126; (ohms) resistor colors: "
. "<span style='display:inline-block;background-color:#964b00;"
. "color:#fff;border:1px solid #c8c8c8;margin-top:-1px;padding:0px 4px;border-radius:4px;"
. "-webkit-border-radius:4px;-moz-border-radius:4px;'>brown</span> "

0 comments on commit 11155d9

Please sign in to comment.
Something went wrong with that request. Please try again.