Small optimisations, by Brandon Black
[p5sagit/p5-mst-13.2.git] / t / mro / complex_dfs.t
1 #!./perl
2
3 use strict;
4 use warnings;
5 BEGIN {
6     unless (-d 'blib') {
7         chdir 't' if -d 't';
8         @INC = '../lib';
9     }
10 }
11
12 use Test::More tests => 11;
13
14 =pod
15
16 This example is taken from: http://rt.cpan.org/Public/Bug/Display.html?id=20879
17
18                ---     ---     ---
19 Level 5     8 | A | 9 | B | A | C |    (More General)
20                ---     ---     ---       V
21                   \     |     /          |
22                    \    |    /           |
23                     \   |   /            |
24                      \  |  /             |
25                        ---               |
26 Level 4             7 | D |              |
27                        ---               |
28                       /   \              |
29                      /     \             |
30                   ---       ---          |
31 Level 3        4 | G |   6 | E |         |
32                   ---       ---          |
33                    |         |           |
34                    |         |           |
35                   ---       ---          |
36 Level 2        3 | H |   5 | F |         |
37                   ---       ---          |
38                       \   /  |           |
39                        \ /   |           |
40                         \    |           |
41                        / \   |           |
42                       /   \  |           |
43                   ---       ---          |
44 Level 1        1 | J |   2 | I |         |
45                   ---       ---          |
46                     \       /            |
47                      \     /             |
48                        ---               v
49 Level 0             0 | K |            (More Specialized)
50                        ---
51
52
53 0123456789A
54 KJIHGFEDABC
55
56 =cut
57
58 {
59     package Test::A; use mro 'dfs';
60
61     package Test::B; use mro 'dfs';
62
63     package Test::C; use mro 'dfs';
64
65     package Test::D; use mro 'dfs';
66     use base qw/Test::A Test::B Test::C/;
67
68     package Test::E; use mro 'dfs';
69     use base qw/Test::D/;
70
71     package Test::F; use mro 'dfs';
72     use base qw/Test::E/;
73
74     package Test::G; use mro 'dfs';
75     use base qw/Test::D/;
76
77     package Test::H; use mro 'dfs';
78     use base qw/Test::G/;
79
80     package Test::I; use mro 'dfs';
81     use base qw/Test::H Test::F/;
82
83     package Test::J; use mro 'dfs';
84     use base qw/Test::F/;
85
86     package Test::K; use mro 'dfs';
87     use base qw/Test::J Test::I/;
88 }
89
90 is_deeply(
91     mro::get_linear_isa('Test::A'),
92     [ qw(Test::A) ],
93     '... got the right DFS merge order for Test::A');
94
95 is_deeply(
96     mro::get_linear_isa('Test::B'),
97     [ qw(Test::B) ],
98     '... got the right DFS merge order for Test::B');
99
100 is_deeply(
101     mro::get_linear_isa('Test::C'),
102     [ qw(Test::C) ],
103     '... got the right DFS merge order for Test::C');
104
105 is_deeply(
106     mro::get_linear_isa('Test::D'),
107     [ qw(Test::D Test::A Test::B Test::C) ],
108     '... got the right DFS merge order for Test::D');
109
110 is_deeply(
111     mro::get_linear_isa('Test::E'),
112     [ qw(Test::E Test::D Test::A Test::B Test::C) ],
113     '... got the right DFS merge order for Test::E');
114
115 is_deeply(
116     mro::get_linear_isa('Test::F'),
117     [ qw(Test::F Test::E Test::D Test::A Test::B Test::C) ],
118     '... got the right DFS merge order for Test::F');
119
120 is_deeply(
121     mro::get_linear_isa('Test::G'),
122     [ qw(Test::G Test::D Test::A Test::B Test::C) ],
123     '... got the right DFS merge order for Test::G');
124
125 is_deeply(
126     mro::get_linear_isa('Test::H'),
127     [ qw(Test::H Test::G Test::D Test::A Test::B Test::C) ],
128     '... got the right DFS merge order for Test::H');
129
130 is_deeply(
131     mro::get_linear_isa('Test::I'),
132     [ qw(Test::I Test::H Test::G Test::D Test::A Test::B Test::C Test::F Test::E) ],
133     '... got the right DFS merge order for Test::I');
134
135 is_deeply(
136     mro::get_linear_isa('Test::J'),
137     [ qw(Test::J Test::F Test::E Test::D Test::A Test::B Test::C) ],
138     '... got the right DFS merge order for Test::J');
139
140 is_deeply(
141     mro::get_linear_isa('Test::K'),
142     [ qw(Test::K Test::J Test::F Test::E Test::D Test::A Test::B Test::C Test::I Test::H Test::G) ],
143     '... got the right DFS merge order for Test::K');