Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Here's the test script (as if you cared) that I'm using on this sucka:
package Sort::Test::LOH_test; use strict; use base qw(Test::Unit::TestCase); my @SAMPLE_DATA = ( {ID => "a1 a", F_NAME => "asd b1 b", L_NAME => "ggfsdf +c1 c", STREET => "5", ADDRESS => "2", CITY => "f1 f"}, {ID => "a2 b", F_NAME => "zxczxc b2 c", L_NAME => "sdvwevc +2 d", STREET => "2", ADDRESS => "9", CITY => "f2 a"}, {ID => "a3 c", F_NAME => "cdaer b3 d", L_NAME => "sdfwbbf + c3 e", STREET => "4", ADDRESS => "045", CITY => "f3 b"}, {ID => "a4 d", F_NAME => "aaaa asdafsdf b4 e", L_NAME => "asdferw +v c6 b", STREET => "4", ADDRESS => "1.3", CITY => "f4 c"}, {ID => "a5 e", F_NAME => "vdasdvqd43 b5 f", L_NAME => "aaaaa c +5 a", STREET => "1", ADDRESS => "9", CITY => "f5 d"}, {ID => "a6 f", F_NAME => "eee ecasd b6 a", L_NAME => "asdferw +v c6 b", STREET => "6", ADDRESS => "8.8", CITY => "f6 e"} ); my @WACKY_DATA = ( {ID => "a1 a", NAMES => ["BOB", "ELLEN"], STREET => "5", + ADDRESS => "2", CITY => "f1 f"}, {ID => "a2 b", NAMES => ["SUE", "ROB"], STREET => [@SAMPLE_DAT +A], ADDRESS => "9", CITY => "f2 a"}, {ID => "a3 c", NAMES => ["JOHN", "JANE"], STREET => "4", + ADDRESS => "045", CITY => "f3 b"}, {ID => "a4 d", NAMES => ["LOUIS", "ELLA"], STREET => "4", + ADDRESS => "1.3", CITY => "f4 c"}, {ID => "a5 e", NAMES => ["RICK", "MARK"], STREET => "1", + ADDRESS => "9", CITY => "f5 d"}, {ID => "a6 f", NAMES => ["IGNATZ", "CRAZY"],STREET => "6", + ADDRESS => "8.8", CITY => "f6 e"} ); sub test_lohsorter { my $self = shift; my $lohSorter = Sort::LOH->new(\@SAMPLE_DATA); my @sorted = $lohSorter->sortMe(["L_NAME", "F_NAME"]); $self->assert($sorted[0]{CITY} eq "f5 d", "Test ALPHA on L_NAME"); $self->assert($sorted[2]{CITY} eq "f6 e"); $self->assert($sorted[5]{CITY} eq "f2 a"); @sorted = $lohSorter->sortMe(["-L_NAME", "F_NAME"], "Test inverted + prime ALPHA with sub not inverted on L_NAME"); $self->assert($sorted[4]{CITY} eq "f6 e"); @sorted = $lohSorter->sortMe(["STREET n"]); $self->assert($sorted[1]{CITY} eq "f2 a", "Test ALPHA on STREET"); @sorted = $lohSorter->sortMe(["-STREET n"]); $self->assert($sorted[1]{CITY} eq "f1 f", "Test inverted ALPHA on +STREET"); @sorted = $lohSorter->sortMe(["ADDRESS"]); $self->assert($sorted[0]{CITY} eq "f3 b", "Test ALPHA on ADDRESS") +; # Test one row to make sure that all the fields are intact. $self->assert($sorted[1]{ID} eq "a4 d"); $self->assert($sorted[1]{F_NAME} eq "aaaa asdafsdf b4 e"); $self->assert($sorted[1]{L_NAME} eq "asdferwv c6 b"); $self->assert($sorted[1]{STREET} eq "4"); $self->assert($sorted[1]{ADDRESS} eq "1.3"); $self->assert($sorted[1]{CITY} eq "f4 c"); $self->assert($sorted[2]{CITY} eq "f1 f"); $self->assert($sorted[3]{CITY} eq "f6 e"); $self->assert($sorted[4]{CITY} eq "f2 a"); $self->assert($sorted[5]{CITY} eq "f5 d"); @sorted = $lohSorter->sortMe(["-ADDRESS n"]); $self->assert($sorted[0]{CITY} eq "f3 b", "Test inverted NUMERIC o +n ADDRESS"); $self->assert($sorted[3]{CITY} eq "f6 e"); $self->assert($sorted[4]{CITY} eq "f1 f"); $self->assert($sorted[5]{CITY} eq "f4 c"); } sub test_factory { my $self = shift; my @sorted = Sort::LOH->static(["L_NAME", "F_NAME"], \@SAMPLE_DATA +); $self->assert($sorted[0]{CITY} eq "f5 d", "Test of factory method +with ALPHA on L_NAME"); $self->assert($sorted[2]{CITY} eq "f6 e"); $self->assert($sorted[5]{CITY} eq "f2 a"); } sub test_wacky_data { my $self = shift; my $sorter = Sort::LOH->new(\@WACKY_DATA); my @sorted = $sorter->sortMe(["-ID", "F_NAME"]); $self->assert($sorted[0]{CITY} eq "f6 e", "Wacky data test with re +verse ALPHA on ID and bad field call."); } 1;
()-()
 \"/
  `                                                     

In reply to Re: Sort::LOH by ignatz
in thread Sort::LOH by ignatz

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 examining the Monastery: (4)
As of 2024-04-25 08:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found