Changeset 343

Show
Ignore:
Timestamp:
10/15/07 00:43:35 (2 years ago)
Author:
eevee
Message:

Pokemon search test is now useful and passes. Since the fake context/request turned out to be unnecessary, I have removed them.

Location:
veekun/trunk/t
Files:
3 removed
1 modified

Legend:

Unmodified
Added
Removed
  • veekun/trunk/t/dex-search.t

    r337 r343  
    55use lib 'lib'; 
    66 
    7 use Test::Simple 'no_plan'; 
     7use Test::More tests => 34; 
    88 
    99BEGIN { $ENV{CATALYST_DEBUG} = 0; } 
    10 use Vee; 
     10BEGIN { use_ok 'Catalyst::Test', 'Vee' } 
     11BEGIN { use_ok 'Vee::Controller::Dex::Search' } 
    1112 
    12 my @results = do_search( name => 'eon' ); 
    13 use Data::Dumper; $Data::Dumper::Maxdepth = 3; warn Dumper(\@results); 
    14 warn $results[0]->name; 
    15 warn $results[0]->has_column_loaded('name'); 
     13sub search_ok; 
    1614 
    17 ok 1; 
     15### Simple search tests; these get slightly more complex as they go on, and in 
     16### general I tried to keep the resultset small so it's easy to verify manually 
    1817 
     18ok request('/dex/pokemon/search')->is_success, "Pokemon search page loads"; 
    1919 
     20search_ok { name => 'eon' }, 
     21    [qw/ 5 134 135 136 196 197 352 395 456 457 470 471 /], 
     22    "Name substring"; 
    2023 
    21 sub do_search { 
    22     my %params = @_; 
     24search_ok { ability => 'Drizzle' }, 
     25    [qw/ 382 /], 
     26    "Only Kyogre has Drizzle"; 
     27 
     28search_ok { color => 'black', habitat => 'urban' }, 
     29    [qw/ 197 353 354 /], 
     30    "Black urban Pokemon"; 
     31 
     32search_ok { name => 'eon', evo_stage => 'base' }, 
     33    [qw/ 352 456 /], 
     34    "The only baseform *eon*s are Kecleon and Finneon"; 
     35 
     36search_ok { name => 'char', evo_stage => 'final' }, 
     37    [qw/ 6 /], 
     38    "The only final form *char* is Charizard"; 
     39 
     40# Gender dropdown had a few problems at one point, so I gave it several tests 
     41search_ok { gender => 254, generation => 0 }, 
     42    [qw/ 29 30 31 113 115 124 /], 
     43    "Female-onlys in RBY"; 
     44 
     45search_ok { name => 'voltorb', gender => 'not255' }, 
     46    [qw/ /], 
     47    "Voltorb isn't returned by 'any gender'"; 
     48 
     49search_ok { name => 'eevee', gender => 255 }, 
     50    [qw/ /], 
     51    "Eevee isn't returned by 'no gender'"; 
     52 
     53# Likewise with the breeding; that's gone wrong several times 
     54search_ok { breed_mode => 'and', breed => [1, 2], evo_stage => 'base' }, 
     55    [qw/ 7 79 131 158 258 /], 
     56    "Families that are Monster/Water 1"; 
     57 
     58search_ok { breed_mode => 'and', breed => [13, 13] }, 
     59    [qw/ 132 /], 
     60    "Only Ditto is in the Ditto/Ditto group's'"; 
     61 
     62search_ok { breed_mode => 'and', breed => [13, 0] }, 
     63    [qw/ 132 /], 
     64    "Ditto is also returned when searching for Ditto and n/a"; 
     65 
     66search_ok { breed_mode => 'and', breed => [13, 5] }, 
     67    [qw/ /], 
     68    "...but not when searching for Ditto and any other group"; 
     69 
     70search_ok { 
     71        breed_mode => 'or', 
     72        breed      => [9, 11], 
     73        evo_stage  => 'base', 
     74        generation => 0, 
     75    }, 
     76    [qw/ 72 88 90 92 98 109 120 138 140 /], 
     77    "RBY families that are Water 3 *or* Indeterminate"; 
     78 
     79search_ok { generation => 2, basedex => 3 }, 
     80    [qw/ 265 266 267 268 269 278 279 298 307 308 315 339 340 349 350 358 /], 
     81    "Pokemon from GSC that appear in DP"; 
     82 
     83# Types are another common problem area 
     84search_ok { name => 'eon', type_mode => 'any', type => [qw/ fire /] }, 
     85    [qw/ 5 136 /], 
     86    "Fire *eon*s"; 
     87 
     88search_ok { name => 'eon', type_mode => 'any', type => [qw/ fire water /] }, 
     89    [qw/ 5 134 136 395 456 457 /], 
     90    "Fire or water *eon*s"; 
     91 
     92search_ok { name => 'eon', type_mode => 'any', type => [qw/ fire water electric /] }, 
     93    [qw/ 5 134 135 136 395 456 457 /], 
     94    "Fire or water or electric *eon*s"; 
     95 
     96search_ok { type_mode => 'all', type => [qw/ bug dragon /] }, 
     97    [qw/ /], 
     98    "Bug/dragon Pokemon"; 
     99 
     100search_ok { type_mode => 'all', type => [qw/ ghost dragon /] }, 
     101    [qw/ 487 /], 
     102    "Ghost/dragon Pokemon"; 
     103 
     104search_ok { type_mode => 'all', type => [qw/ dragon ghost /] }, 
     105    [qw/ 487 /], 
     106    "Dragon/ghost Pokemon (i.e. order doesn't matter)"; 
     107 
     108search_ok { type_mode => 'all', type => [qw/ normal flying psychic /] }, 
     109    [qw/ /], 
     110    "Must have three types"; 
     111 
     112# Moves have a lot of possibilities; I just try a few here 
     113search_ok { move => 'judgment' }, 
     114    [qw/ 493 /], 
     115    "Learns Judgment"; 
     116 
     117search_ok { move => 'judgment', move_method => [qw/ egg machine tutor /] }, 
     118    [qw/ /], 
     119    "...by leveling up"; 
     120 
     121search_ok { move => 'judgment', move_version => [qw/ rb y gs c rusa frlg e /] }, 
     122    [qw/ /], 
     123    "...not in DP"; 
     124 
     125search_ok { move => [qw/ splash tackle /], move_version => 'rb' }, 
     126    [qw/ 129 /], 
     127    "Learns Splash and Tackle in RB"; 
     128 
     129# Similar for the stats; these all work the same so whatever 
     130search_ok { stat_hp_lb => 250 }, 
     131    [qw/ 113 242 /], 
     132    "HP stat of 250+"; 
     133 
     134# Height and weight had some rounding issues 
     135search_ok { generation => 1, height_lb => 16, height_ub => 16 }, 
     136    [qw/ 182 183 187 194 220 238 /], 
     137    "GSC Pokemon that are 16\" tall"; 
     138 
     139search_ok { height_lb => '0.2m', height_ub => '0.2m' }, 
     140    [qw/ 50 177 298 406 412 433 492 /], 
     141    "Pokemon that are 0.2m tall"; 
     142 
     143search_ok { height_lb => '20cm', height_ub => '20cm' }, 
     144    [qw/ 50 177 298 406 412 433 492 /], 
     145    "Pokemon that are 20cm tall (same as above)"; 
     146 
     147# Quick sorting checks 
     148search_ok { name => 'q', sort => 'stat_avg' }, 
     149    [qw/ 155 7 156 284 195 211 416 31 384 /], 
     150    "Sorting by average stat"; 
     151 
     152search_ok { name => 'q', sort => 'id', sort_desc => 'on' }, 
     153    [qw/ 416 384 284 211 195 156 155 31 7 /], 
     154    "Reverse sort by id"; 
     155 
     156sub search_ok { 
     157    my ($params, $expected, $test_name) = @_; 
     158 
     159    if (not $params->{sort}) { 
     160        # sort by id for simplicity 
     161        $params->{sort} = 'id'; 
     162        delete $params->{sort_desc}; 
     163    } 
     164 
    23165    my $context = Vee->prepare; 
    24     for my $key (keys %params) { 
    25         $context->req->params->{$key} = $params{$key}; 
    26     } 
     166    $context->req->params($params); 
    27167    Vee::Controller::Dex::Search->pokemon_search($context); 
    28     return @{ $context->stash->{results} || [] }; 
     168 
     169    my $pokemon_rows = $context->stash->{results} || []; 
     170    my @pokemon = map { $_->id } @$pokemon_rows; 
     171 
     172    is_deeply \@pokemon, $expected, $test_name; 
    29173}