Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

use Test::Simple 3

Status
Not open for further replies.

JohnLucania

Programmer
Oct 10, 2005
96
US
sub CheckSeq {
return scalar grep /[^abceABCE]/, @CheckChar;
}

For this, I tried both below. What is wrong with it?

ok( @CheckChar =~ /[^abceABCE]*@/, "sequence composition checks" );
ok( @CheckChar =~ /[^abceABCE]/, "sequence composition checks" );

grep(/abd|ABD/i, @CheckChar );

Also, how do you 'test' this one?

jl
 
What do you think you're checking for? What do you want to check for?
 
I like to check if @CheckChar contains 'a, b, c, e, A, B, C, or E' or not.

and, I like to check if @CheckChar contains words, abd or ABD.

It is checked with regexp though.

jl

 
and I like to check if certain words (i.e. abd, ABD) are showing up more than once.
 
Is @CheckChar a real array (are multiple elemnts stored in the array)? Or is just an array with only a single long scalar?

@arrray = qw(this is an array with multiple elements);
@array = ('This is an array with only one element');

 
@CheckChar contains a bulk of 'abce' i.e. 'aaabbbaceeeaaaabaababeeeaaaaacccccccceaaabababbbeeeeaacc. with no unique pattern.

jl
 
Do you mean these?

ok( @CheckChar = qw(abe), "sequence composition checks" );
ok( @CheckChar = ('a' 'b' 'c'), "single char checks" );

jl
 
I have never used Test::Simple so I don't know if you are using it correctly, maybe it will do what you want, but these checks seem easy to do "manually" anyway. When you say words do you mean patterns or sub strings or words?

patterns can be nearly anywhere in a string: (pattern abe in a string)

aftrbhhhhwwwe


sub strings are generally a small contiguous part of a larger string: (abe again):

fffabehhhh abecdf

words are seperated by boundaries, such as spaces or punctuation: (abe again)

this is a sentence with abe in it

so are you looking for patterns, sub strings, words or all?
 
I want to both.

// as a single char
if the array contains the strings (a, b, e) i.e. 'aftrbhhhhand
// as a word
if the array contains the words ('abe', 'ace', 'ada', ) i.e. fffabehhhh abecdf

jl
 
something along these lines maybe:

Code:
my $results = check(@CheckChar);
print $results;


sub check {
   my @CheckChar = @_; 
   my $word_flag = 0;
   my $char_flag = 0;
   my $results = '';
   for (@CheckChar) {
     $word_flag++ while /\babd\b/ig;
     $char_flag++ if /[abce]+/i;
   }
   if ($word_flag) {
      $results .= "Sequence 'abd' or 'ABD' was found $word_flag times.\n"
   }
   else {
      $results .= "No sequences 'abd' or 'ABD' were found.\n";
   }
   if ($char_flag) {
      $results .= "Characters 'abce' or 'ABCE' were found.\n";
   }
   else {
      $results .= "No characters 'abce' of 'ABCE' were found.\n";
   }
   return($results);
}


 
you say word but you mean sub string, so change this:

$word_flag++ while /\babd\b/ig;

to:

$word_flag++ while /(abd)/ig;
 
I think it would be great if I can use Test::Simple. Otherwise, you need to reinvent wheels. Of course, if Test::Simple can handle though....

jl
 
Test::Simple is used for automated regression tests during package installations. It is really not what you want here.

f

["]As soon as we started programming, we found to our surprise that it wasn't as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs.["]
--Maur
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top