summaryrefslogtreecommitdiff
path: root/t/test.pl
diff options
context:
space:
mode:
authorBrad Gilbert <b2gills@gmail.com>2012-09-16 14:06:59 -0500
committerFather Chrysostomos <sprout@cpan.org>2012-09-25 14:35:12 -0700
commitf6e25e605fbd478eb79575b48accf888d57494e5 (patch)
tree21552ded1866f52ff641452d444ee3bf219a4110 /t/test.pl
parent48e9c5d48f9e8a882c41665cd4c18fb237fc00ac (diff)
downloadperl-f6e25e605fbd478eb79575b48accf888d57494e5.tar.gz
Add _num_to_alpha() to test.pl
Also added testing for _num_to_alpha()
Diffstat (limited to 't/test.pl')
-rw-r--r--t/test.pl26
1 files changed, 26 insertions, 0 deletions
diff --git a/t/test.pl b/t/test.pl
index 65e23484a4..da480d3ecf 100644
--- a/t/test.pl
+++ b/t/test.pl
@@ -762,8 +762,34 @@ sub unlink_all {
$count;
}
+# _num_to_alpha - Returns a string of letters representing a positive integer.
+# Arguments :
+# number to convert
+
+# returns undef if the number is negative
+
+# _num_to_alpha( 0) eq 'A';
+# _num_to_alpha( 1) eq 'B';
+# _num_to_alpha(25) eq 'Z';
+# _num_to_alpha(26) eq 'AA';
+# _num_to_alpha(27) eq 'AB';
+
my @letters = qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z);
+# Avoid ++ -- ranges split negative numbers
+sub _num_to_alpha{
+ my($num) = @_;
+ return unless $num >= 0;
+ my $alpha = '';
+ while( 1 ){
+ $alpha = $letters[ $num % 26 ] . $alpha;
+ $num = int( $num / 26 );
+ last if $num == 0;
+ $num = $num - 1;
+ }
+ return $alpha;
+}
+
my %tmpfiles;
END { unlink_all keys %tmpfiles }