initial commit
[urisagit/Sort-Maker.git] / t / init_code.t
CommitLineData
7468c584 1#!/usr/local/bin/perl -sw
2
3use strict ;
4
5use lib 't' ;
6use lib '..' ;
7require 'common.pm' ;
8
9my @sort_styles = qw( ST GRT ) ;
10
11my @string_keys = map rand_alpha( 4, 8 ), 1 .. 10 ;
12my @number_keys = map int rand_number( 100, 10000 ), 1 .. 10 ;
13
14my $sort_tests = [
15
16 {
17 skip => 0,
18 source => 0,
19 name => 'init_code',
20 sizes => [400, 1000],
21 gen => sub { rand_choice( @string_keys ) . ':' .
22 rand_choice( @number_keys ) },
23 gold => sub {
24 ($a =~ /^(\w+)/)[0] cmp ($b =~ /^(\w+)/)[0]
25 ||
26 ($a =~ /(\d+$)/)[0] <=> ($b =~ /(\d+$)/)[0]
27 },
28 args => {
29 init_code => [
30 init_code => 'my( $str, $num ) ;',
31 string =>
32 'do{( $str, $num ) = /^(\w+):(\d+)$/; $str}',
33 number => '$num',
34 ],
35 no_init => [
36 string => '/^(\w+)/',
37 number => '/(\d+)$/'
38 ],
39 },
40 },
41 {
42 skip => 0,
43 source => 0,
44 name => 'deep init_code',
45 sizes => [400, 1000],
46 gen => sub { [[{'a' => rand_choice( @string_keys ) . ':' .
47 rand_choice( @number_keys )}]] },
48 gold => sub {
49 ($a->[0][0]{a} =~ /^(\w+)/)[0] cmp
50 ($b->[0][0]{a} =~ /^(\w+)/)[0]
51 ||
52 ($a->[0][0]{a} =~ /(\d+$)/)[0] <=>
53 ($b->[0][0]{a} =~ /(\d+$)/)[0]
54 },
55 args => {
56 init_code => [
57 init_code => 'my( $str, $num ) ;',
58 string => 'do{( $str, $num ) =
59 $_->[0][0]{a} =~ /^(\w+):(\d+)$/; $str}',
60 number => '$num',
61 ],
62 no_init => [
63 string => '$_->[0][0]{a} =~ /^(\w+)/',
64 number => '$_->[0][0]{a} =~ /(\d+$)/',
65 ],
66 },
67 },
68] ;
69
70common_driver( $sort_tests, \@sort_styles ) ;
71
72exit ;