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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.