ec0b7b8ca7a9 — Duncan Ross Palmer 1 year, 2 months ago
Do randChar
2 files changed, 25 insertions(+), 9 deletions(-)

M bin/raw2c
M t/raw2c.pl
M bin/raw2c +8 -9
@@ 34,6 34,7 @@ 
 package Main;
 use strict;
 use warnings;
+use English qw(-no_match_vars);
 use POSIX qw(EXIT_SUCCESS);
 
 sub new {

          
@@ 63,7 64,14 @@ sub title {
 	return;
 }
 
+sub randChar {
+	my $validChars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_';
+	my $randOffset = int(rand(length($validChars)));
+	return substr($validChars, $randOffset, 1);
+}
+
 sub main {
+	srand($PID);
 	return EXIT_SUCCESS;
 }
 

          
@@ 282,15 290,6 @@ exit(Main->new->main()) unless (caller()
 #	return buffer;
 #}
 
-#static char randChar() {
-
-#	const char validchars[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
-#	int randoffset;
-
-#	randoffset = rand() % sizeof(validchars);
-#	return validchars[randoffset];
-#}
-
 #static void makeSource(struct FileOrDir *pIn, struct FileOrDir *pOut) {
 
 #	unsigned long int counter = 0UL;

          
M t/raw2c.pl +17 -0
@@ 37,6 37,23 @@ sub testStrings {
 	return EXIT_SUCCESS;
 }
 
+sub testRandChar {
+	#my ($self) = @_;
+	plan tests => 1;
+
+	my $sut = Main->new();
+
+	my %chars = ( );
+	do {
+		my $char = $sut->randChar();
+		$chars{$char} = $char if ($char eq '0' || $char eq 'q' || $char eq 'Z' || $char eq '_');
+	} while (scalar(keys(%chars)) < 4);
+
+	cmp_ok(scalar(keys(%chars)), '==', 4, 'randChar');
+
+	return EXIT_SUCCESS;
+}
+
 package main;
 use strict;
 use warnings;