Created
March 2, 2016 18:06
-
-
Save awwaiid/8e584f7be258593ae2a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ok 1 - Simple 1 works | |
ok 2 - Real simple 2 works | |
not ok 3 - We have prepended values! | |
# Failed test 'We have prepended values!' | |
# at roman-mark.pl line 35. | |
# got: 'IIII' | |
# expected: 'IV' | |
ok 4 - We have Vs | |
ok 5 - seventeen and stuff | |
not ok 6 - nineteen and stuff | |
# Failed test 'nineteen and stuff' | |
# at roman-mark.pl line 38. | |
# got: 'XVIIII' | |
# expected: 'XIX' | |
ok 7 - twenty and stuff | |
not ok 8 - fourty and stuff | |
# Failed test 'fourty and stuff' | |
# at roman-mark.pl line 40. | |
# got: 'XXXX' | |
# expected: 'XL' | |
not ok 9 - fourty one | |
# Failed test 'fourty one' | |
# at roman-mark.pl line 41. | |
# got: 'XXXXI' | |
# expected: 'XLI' | |
not ok 10 - Fourty NINE | |
# Failed test 'Fourty NINE' | |
# at roman-mark.pl line 42. | |
# got: 'XXXXVIIII' | |
# expected: 'XLIX' | |
not ok 11 - NINETY YO | |
# Failed test 'NINETY YO' | |
# at roman-mark.pl line 43. | |
# got: 'LXXXX' | |
# expected: 'XC' | |
not ok 12 - NINETY NINE YO | |
# Failed test 'NINETY NINE YO' | |
# at roman-mark.pl line 44. | |
# got: 'LXXXXVIIII' | |
# expected: 'XCIX' | |
1..12 | |
# Looks like you failed 7 tests of 12. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v5.20; | |
use Test::More; | |
sub to_roman { | |
my ($num) = @_; | |
my $output = q{}; | |
my %conv = ( | |
M => 1000, | |
D => 500, | |
C => 100, | |
L => 50, | |
X => 10, | |
V => 5, | |
I => 1, | |
); | |
my @lets = sort { $conv{$b} <=> $conv{$a} } keys %conv; | |
for my $let (@lets) { | |
# warn "num=$num let=$let\n"; | |
while (($num - $conv{$let}) >= 0) { | |
# warn "num=$num\n"; | |
$output .= $let; | |
$num -= $conv{$let}; | |
} | |
} | |
return $output; | |
} | |
# for my $n (1..100) { | |
# say to_roman($n); | |
# } | |
is to_roman(1), "I", "Simple 1 works"; | |
is to_roman(2), "II", "Real simple 2 works"; | |
is to_roman(4), "IV", "We have prepended values!"; | |
is to_roman(5), "V", "We have Vs"; | |
is to_roman(17), "XVII", "seventeen and stuff"; | |
is to_roman(19), "XIX", "nineteen and stuff"; | |
is to_roman(20), "XX", "twenty and stuff"; | |
is to_roman(40), "XL", "fourty and stuff"; | |
is to_roman(41), "XLI", "fourty one"; | |
is to_roman(49), "XLIX", "Fourty NINE"; | |
is to_roman(90), "XC", "NINETY YO"; | |
is to_roman(99), "XCIX", "NINETY NINE YO"; | |
done_testing; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment