root/lang/perl/Log-Analyze/trunk/t/02_count_multistage.t @ 17777

Revision 17777, 2.1 kB (checked in by miki, 6 years ago)

import Log::Analyze

Line 
1use strict;
2use warnings;
3use Log::Analyze;
4use File::Spec;
5use Test::More tests => 2;
6
7my $logfile = File::Spec->catfile( 't', 'data', 'log.txt' );
8my $analyzer = Log::Analyze->new;
9
10open( LOG, $logfile );
11while (<LOG>) {
12    chomp;
13    my @f = split( /\t/, $_ );
14
15    $f[0] =~ /\[(\d\d)\/Aug\/2008:(\d\d):(\d\d):(\d\d)/;
16    my $date = $1;
17    my $hour = $2;
18    my $min  = $3;
19    my $sec  = $4;
20
21    $analyzer->analyze( [ $date, $hour ], "count" );
22}
23close(LOG);
24
25{
26    my $tree = $analyzer->tree;
27    my $correct = tree_correct_data();
28    is_deeply( $tree, $correct, "tree is deeply matched" );
29}
30
31{
32    my $matrix = $analyzer->matrix;
33    my $correct = matrix_correct_data();
34    is_deeply( $matrix, $correct, "matrix is deeply matched" );
35}
36
37sub tree_correct_data {
38    my $data = {
39        '11' => {
40            '01' => 9,
41            '05' => 2,
42            '04' => 6,
43            '02' => 4,
44            '07' => 17,
45            '03' => 7,
46            '08' => 20,
47            '00' => 14,
48            '06' => 9
49        },
50        '10' => {
51            '11' => 25,
52            '21' => 24,
53            '17' => 15,
54            '12' => 17,
55            '20' => 17,
56            '15' => 20,
57            '14' => 25,
58            '22' => 30,
59            '18' => 21,
60            '23' => 25,
61            '19' => 16,
62            '10' => 26,
63            '13' => 21,
64            '16' => 17,
65            '09' => 16
66        }
67    };
68    return $data;
69}
70
71sub matrix_correct_data {
72    my $data = [
73        [ '10', '09', 16 ],
74        [ '10', '10', 26 ],
75        [ '10', '11', 25 ],
76        [ '10', '12', 17 ],
77        [ '10', '13', 21 ],
78        [ '10', '14', 25 ],
79        [ '10', '15', 20 ],
80        [ '10', '16', 17 ],
81        [ '10', '17', 15 ],
82        [ '10', '18', 21 ],
83        [ '10', '19', 16 ],
84        [ '10', '20', 17 ],
85        [ '10', '21', 24 ],
86        [ '10', '22', 30 ],
87        [ '10', '23', 25 ],
88        [ '11', '00', 14 ],
89        [ '11', '01', 9 ],
90        [ '11', '02', 4 ],
91        [ '11', '03', 7 ],
92        [ '11', '04', 6 ],
93        [ '11', '05', 2 ],
94        [ '11', '06', 9 ],
95        [ '11', '07', 17 ],
96        [ '11', '08', 20 ]
97    ];
98    return $data;
99}
Note: See TracBrowser for help on using the browser.