Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I think the time has finally come where I add another set of tests to the Games::QuizTaker module to test a function that is completely untested in the current framework. Oddly enough, the function in question is the "test" function which prints out the questions of the quiz and waits for the input of an answer, which it then checks and reports back as to whether it is correct or incorrect.

Since this entire function is an interactive one, how would I go about implementing a decent test to cover this part of the module? As always, I'm merely looking for suggestions/alternatives. The test function of the module is below:
sub test{ my $self=shift; my $Answer_Sep=$self->get_AnswerDelimiter; my $Max=$self->get_MaxQuestions; my ($answer,$key,$line,$question_answer); my $question_number=1; my $number_correct=0; my $asep=qq"\\$Answer_Sep"; system(($^O eq "MSWin32"?'cls':'clear')); print"\n"; while($question_number<=$Max){ $key=shift @Randoms; print"Question Number $question_number\n"; foreach $line(@{$$questions{$key}}){ print wrap("","","$line\n"); } print"Your Answer: "; $answer=<STDIN>; chomp($answer); $answer=uc($answer); $question_answer=$Test_Answers{$key}; chomp($question_answer); $question_answer=uc $question_answer; my $ln=length($question_answer); if($ln>1){ if($question_answer!~/$Answer_Sep/){ warn"Answer_Delimiter doesn't match internally"; } if($Answer_Sep eq " "){ }else{ $question_answer=~s/$asep/ /; } $question_answer=$self->answer_sort($question_answer); $answer=$self->answer_sort($answer); } # print "My Answer: $answer\n"; # print "Test Answer: $question_answer\n"; if("$answer" eq "$question_answer"){ print"That is correct!!\n\n"; $question_number++; $number_correct++; }else{ print"That is incorrect!!\n"; print"The correct answer is $question_answer.\n\n"; $question_number++; } } my $Final=$self->get_Score; if(defined $Final){ $self->Final($number_correct,$Max); return; }else{ return; } }

TStanley
--------
People sleep peaceably in their beds at night only because rough men stand ready to do violence on their behalf. -- George Orwell

In reply to Writing a module test by TStanley

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-23 15:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found