Refactored Survey test suite diagnostics etc..

This commit is contained in:
Patrick Donelan 2009-05-17 08:15:59 +00:00
parent de47c22eff
commit 9cbd30c3d8
4 changed files with 355 additions and 78 deletions

View file

@ -22,7 +22,7 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
my $tests = 56;
my $tests = 57;
plan tests => $tests + 1;
#----------------------------------------------------------------------------
@ -71,6 +71,7 @@ SKIP: {
q{jump { if (value(n) == 5) { 1 } else { 0 } } target}, # if statement
q{jump { $q2 = 3; $avg = (value(n) + $q2) / 2; $avg == 4 } target}, # look ma, averages!
q{jump { $q2 = 3; avg(value(n), $q2) == 4 } target}, # look ma, built-in avg sub!
q{jump { round(3.456) == 3 && round(3.456, 2) == 3.46 } target}, # rounding
q{jump { value(n) == 5 } target; jump { value(n) == 5 } targetX}, # first jump wins
q{jump { value(n) == 0 } targetX; jump { value(n) == 5 } target}, # false jumps ignored
q{jump { min(3,5,2) == 2 } target}, # List::Util min

View file

@ -21,7 +21,7 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
plan tests => 34;
plan tests => 52;
my ( $s, $t1 );
@ -46,13 +46,12 @@ $s->surveyJSON_newObject( [] ); # S1
$s->surveyJSON_newObject( [] ); # S2
$s->surveyJSON_newObject( [] ); # S3
$s->surveyJSON_newObject( [] ); # S4
$s->surveyJSON_newObject( [] ); # S5
# Name the sections
$s->surveyJSON_update( [0], { variable => 'S0' } );
$s->surveyJSON_update( [1], { variable => 'S1' } );
$s->surveyJSON_update( [2], { variable => 'S2' } );
$s->surveyJSON_update( [3], { variable => 'S3' } );
$s->surveyJSON_update( [4], { variable => 'S4' } );
for my $sIndex (0..5) {
$s->surveyJSON_update( [$sIndex], { variable => "S$sIndex" } );
}
# ..and now some questions
$s->surveyJSON_newObject( [0] ); # S0Q0
@ -60,8 +59,8 @@ $s->surveyJSON_newObject( [1] ); # S1Q0
$s->surveyJSON_newObject( [2] ); # S2Q0
$s->surveyJSON_newObject( [3] ); # S3Q0
$s->surveyJSON_newObject( [3] ); # S3Q1
$s->surveyJSON_newObject( [3] ); # S3Q2
$s->surveyJSON_newObject( [4] ); # S4Q0
$s->surveyJSON_newObject( [4] ); # S4Q1
# Name the questions
$s->surveyJSON_update( [ 0, 0 ], { variable => 'S0Q0' } );
@ -69,16 +68,24 @@ $s->surveyJSON_update( [ 1, 0 ], { variable => 'S1Q0' } );
$s->surveyJSON_update( [ 2, 0 ], { variable => 'S2Q0' } );
$s->surveyJSON_update( [ 3, 0 ], { variable => 'S3Q0' } );
$s->surveyJSON_update( [ 3, 1 ], { variable => 'S3Q1' } );
$s->surveyJSON_update( [ 3, 2 ], { variable => 'S3Q2' } );
$s->surveyJSON_update( [ 4, 0 ], { variable => 'S4Q0' } );
$s->surveyJSON_update( [ 4, 1 ], { variable => 'S4Q1' } );
# Set additional options..
$s->surveyJSON_update( [ 0, 0 ], { questionType => 'Yes/No' } ); # S0Q0 is a Yes/No
$s->surveyJSON_update( [ 0, 0 ], { gotoExpression => q{ tag('tagged at S0Q0'); } } ); # S0Q0 tags data
$s->surveyJSON_update( [ 0, 0 ], { gotoExpression => q{ tag('tagged at S0Q0'); } } ); # S0Q0 tagged data
$s->surveyJSON_update( [ 1, 0 ], { questionType => 'Yes/No' } ); # S1Q0 is a Yes/No
$s->surveyJSON_update( [ 1, 0, 0 ], { goto => 'S3' } ); # S1Q0 answer 0 jumps to S3
$s->surveyJSON_update( [ 1, 0, 1 ], { gotoExpression => q{ tag('tagged at S1Q0'); } } );# S1Q0 answer 1 tags data
$s->surveyJSON_update( [ 1, 0, 1 ], { gotoExpression => q{ tag('tagged at S1Q0', 999); } } );# S1Q0 answer 1 tagged numeric data
$s->surveyJSON_update( [ 3 ], { gotoExpression => q{ jump { score(S3) == 0 } S5; } } ); # jump to S5 if all 3 questions answered as No
for my $qIndex (0..2) {
$s->surveyJSON_update( [ 3, $qIndex ], { questionType => 'Yes/No', required => 1 } );
$s->surveyJSON_update( [ 3, $qIndex, 1 ], { value => 0 } ); # Set 'No' score to 0
}
$s->surveyJSON_update( [ 4, 0 ], { questionType => 'Concern' } );
# And finally, persist the changes..
$s->persistSurveyJSON;
@ -87,14 +94,14 @@ cmp_deeply(
$s->responseJSON->surveyOrder, [
[ 0, 0, [ 0, 1 ] ], # S0Q0
[ 1, 0, [ 0, 1 ] ], # S1Q0
[ 2, 0, [] ], # S2Q0
[ 3, 0, [] ], # S3Q0
[ 3, 1, [] ], # S3Q1
[ 4, 0, [] ], # S4Q0
[ 4, 1, [] ], # S4Q1
[ 2, 0, [] ], # S2Q0
[ 3, 0, [ 0, 1 ] ], # S3Q0
[ 3, 1, [ 0, 1 ] ], # S3Q1
[ 3, 2, [ 0, 1 ] ], # S3Q2
[ 4, 0, [ 0 .. 10 ] ], # S4Q0
[ 5 ], # S5
], 'surveyOrder is correct'
);
cmp_deeply(
$s->responseJSON->surveyOrderIndexByVariableName,
{
@ -107,9 +114,10 @@ cmp_deeply(
'S3' => 3,
'S3Q0' => 3,
'S3Q1' => 4,
'S4' => 5,
'S4Q0' => 5,
'S4Q1' => 6,
'S3Q2' => 5,
'S4' => 6,
'S4Q0' => 6,
'S5' => 7,
},
'surveyOrderIndexByVariableName correct'
);
@ -140,8 +148,8 @@ $spec = <<END_SPEC;
END_SPEC
try_it( $t1, $spec, { tap => <<END_TAP } );
1..2
ok 1 - Page containing Section S0 Question S0Q0 jumps to S1
ok 2 - Page containing Section S0 Question S0Q0 jumps to S1Q0
ok 1 - Checking next on page containing Section S0 Question S0Q0
ok 2 - Checking next on page containing Section S0 Question S0Q0
END_TAP
# deliberately pass in a spec that will fail
@ -157,12 +165,31 @@ $spec = <<END_SPEC;
END_SPEC
try_it( $t1, $spec, { tap => <<END_TAP, fail => 1 } );
1..1
not ok 1 - Page containing Section S0 Question S0Q0 jumps to S2
not ok 1 - Checking next on page containing Section S0 Question S0Q0
# Compared next section/question
# got : 'S1' (<-- a section) and 'S1Q0' (<-- a question)
# expect : 'S2'
END_TAP
# also fails if we don't answer all required questions
$spec = <<END_SPEC;
[
{
"test" : {
"S3Q0" : "Yes",
"next" : "S4", # fails because we missed S3Q1 and S3Q2
}
}
]
END_SPEC
try_it( $t1, $spec, { tap => <<END_TAP, fail => 1 } );
1..1
not ok 1 - Checking next on page containing Section S3 Question S3Q0
# Compared next section/question
# got : 'S3' (<-- a section) and 'S3Q0' (<-- a question)
# expect : 'S4'
END_TAP
# now try it on a question that has branching, and doesn't start on the first page
$spec = <<END_SPEC;
[
@ -176,24 +203,75 @@ $spec = <<END_SPEC;
END_SPEC
try_it( $t1, $spec, { tap => <<END_TAP } );
1..1
ok 1 - Page containing Section S1 Question S1Q0 jumps to S3
ok 1 - Checking next on page containing Section S1 Question S1Q0
END_TAP
# Use tags..
# use our own description
$spec = <<END_SPEC;
[
{
"test" : {
"S1Q0" : "Yes",
"next" : "S3", # a goto jump
},
"name" : "my individual test label"
},
]
END_SPEC
try_it( $t1, $spec, { tap => <<END_TAP } );
1..1
ok 1 - my individual test label
END_TAP
## Use tagged..
$spec = <<END_SPEC;
[
{
"test" : {
"S0Q0" : "Yes",
"next" : "S1",
"tags" : [ "tagged at S0Q0" ], # and tagged correctly
"tagged" : [ "tagged at S0Q0" ], # and tagged correctly
}
},
]
END_SPEC
try_it( $t1, $spec, { tap => <<END_TAP } );
1..1
ok 1 - Page containing Section S0 Question S0Q0 jumps to S1 and tags data
ok 1 - Checking next and tagged on page containing Section S0 Question S0Q0
END_TAP
# Same but more verbose
$spec = <<END_SPEC;
[
{
"test" : {
"S0Q0" : "Yes",
"next" : "S1",
"tagged" : [ { "tagged at S0Q0" : 1 }, ], # and tagged correctly
}
},
]
END_SPEC
try_it( $t1, $spec, { tap => <<END_TAP } );
1..1
ok 1 - Checking next and tagged on page containing Section S0 Question S0Q0
END_TAP
# Also the same (uses hash instead of array)
$spec = <<END_SPEC;
[
{
"test" : {
"S0Q0" : "Yes",
"next" : "S1",
"tagged" : { "tagged at S0Q0" : 1 },
}
},
]
END_SPEC
try_it( $t1, $spec, { tap => <<END_TAP } );
1..1
ok 1 - Checking next and tagged on page containing Section S0 Question S0Q0
END_TAP
# Use setup..
@ -201,17 +279,17 @@ $spec = <<END_SPEC;
[
{
"test" : {
"setup" : { "S0Q0" : "Yes" }, # S0Q0 tags 'tagged at S0Q0'
"setup" : { "S0Q0" : "Yes" }, # S0Q0 tagged 'tagged at S0Q0'
"S1Q0" : "No",
"next" : "S2",
"tags" : [ "tagged at S0Q0" ], # tagged by setup step
"tagged" : [ "tagged at S0Q0" ], # tagged by setup step
}
},
]
END_SPEC
try_it( $t1, $spec, { tap => <<END_TAP } );
1..1
ok 1 - Page containing Section S1 Question S1Q0 jumps to S2 and tags data
ok 1 - Checking next and tagged on page containing Section S1 Question S1Q0
END_TAP
# Use nested setup..
@ -221,20 +299,39 @@ $spec = <<END_SPEC;
"test" : {
"setup" : {
"setup" : {
"S0Q0" : "Yes" # tags 'tagged at S0Q0'
"S0Q0" : "Yes" # tagged 'tagged at S0Q0'
},
"S1Q0" : "No", # tags 'tagged at S1Q0'
"S1Q0" : "No", # tagged 'tagged at S1Q0' with value 999
},
"S2Q0" : null,
"next" : "S3",
"tags" : [ "tagged at S0Q0", "tagged at S1Q0", ], # tagged by setup step
"tagged" : [ "tagged at S0Q0", { "tagged at S1Q0" : 999 }, ], # tagged by setup step
}
},
]
END_SPEC
try_it( $t1, $spec, { tap => <<END_TAP } );
1..1
ok 1 - Page containing Section S2 Question S2Q0 jumps to S3 and tags data
ok 1 - Checking next and tagged on page containing Section S2 Question S2Q0
END_TAP
# Use the score option
$spec = <<END_SPEC;
[
{
"test" : {
"S3Q0" : "n",
"S3Q1" : "y",
"S3Q2" : "y",
"next" : "S4",
"score" : { "S3" : 2 },
}
},
]
END_SPEC
try_it( $t1, $spec, { tap => <<END_TAP } );
1..1
ok 1 - Checking next and score on page containing Section S3 Question S3Q0
END_TAP
#########
@ -254,8 +351,8 @@ $spec = <<END_SPEC;
END_SPEC
try_it( $t1, $spec, { tap => <<END_TAP } );
1..2
ok 1 - S0Q0 mc answer 1 jumps to S1Q0
ok 2 - S0Q0 mc answer 2 jumps to S1
ok 1 - Checking next for S0Q0 mc answer 1
ok 2 - Checking next for S0Q0 mc answer 2
END_TAP
# try the same thing, but in a more verbose form
@ -272,18 +369,18 @@ $spec = <<END_SPEC;
END_SPEC
try_it( $t1, $spec, { tap => <<END_TAP } );
1..2
ok 1 - S0Q0 mc answer 1 jumps to S1Q0
ok 2 - S0Q0 mc answer 2 jumps to S1
ok 1 - Checking next for S0Q0 mc answer 1
ok 2 - Checking next for S0Q0 mc answer 2
END_TAP
# use the tags option
# use the tagged option
$spec = <<END_SPEC;
[
{
"test_mc" : [
"S0Q0", # test S0Q0
{ "next" : "S1Q0", # first answer falls through
"tags" : [ "tagged at S0Q0" ], # and tags data
"tagged" : [ "tagged at S0Q0" ], # and tagged data
},
{ "next" : "S1" }, # second answer falls through to the same place
]
@ -292,8 +389,8 @@ $spec = <<END_SPEC;
END_SPEC
try_it( $t1, $spec, { tap => <<END_TAP } );
1..2
ok 1 - S0Q0 mc answer 1 jumps to S1Q0 and tags correct
ok 2 - S0Q0 mc answer 2 jumps to S1
ok 1 - Checking next and tagged for S0Q0 mc answer 1
ok 2 - Checking next for S0Q0 mc answer 2
END_TAP
# And try one that does branching, and doesn't start on the first page
@ -303,7 +400,7 @@ $spec = <<END_SPEC;
"test_mc" : [
"S1Q0", # test S1Q0
{ "next" : "S3", # first answer jumps
"tags" : [ ], # nothing gets tagged
"tagged" : [ ], # nothing gets tagged
},
{ "next" : "S2" }, # second answer falls through
]
@ -312,8 +409,29 @@ $spec = <<END_SPEC;
END_SPEC
try_it( $t1, $spec, { tap => <<END_TAP } );
1..2
ok 1 - S1Q0 mc answer 1 jumps to S3 and tags correct
ok 2 - S1Q0 mc answer 2 jumps to S2
ok 1 - Checking next and tagged for S1Q0 mc answer 1
ok 2 - Checking next for S1Q0 mc answer 2
END_TAP
#########
# sequence
#########
$spec = <<END_SPEC;
[
{
"sequence" : {
"S1Q0" : { "recordedAnswer" : "desc", "score" : "cons" }, # This is a default Yes/No (score all 1)
"S4Q0" : { "recordedAnswer" : "asc" }, # Certainty scale, with recordedAnswer 0 .. 11
"S3Q0" : { "recordedAnswer" : "desc", "score" : "desc" }, # These 3 are yes/no questions where we have
"S3Q1" : { "recordedAnswer" : "desc", "score" : "desc" }, # ..set the score on the No answer to zero, hence
"S3Q2" : { "recordedAnswer" : "desc", "score" : "desc" }, # ..they are descending
}
}
]
END_SPEC
try_it( $t1, $spec, { tap => <<END_TAP } );
1..1
ok 1 - Valid sequences
END_TAP
use TAP::Parser;