File: 006_complex_merge.t

package info (click to toggle)
libalgorithm-c3-perl 0.11-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 180 kB
  • sloc: perl: 88; makefile: 2
file content (145 lines) | stat: -rw-r--r-- 4,227 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
use strict;
use warnings;

use Test::More tests => 11;

use Algorithm::C3;

=pod

This example is taken from: http://rt.cpan.org/Public/Bug/Display.html?id=20879

                   ---     ---     ---
    Level 5     8 | A | 9 | B | A | C |    (More General)
                   ---     ---     ---       V
                      \     |     /          |
                       \    |    /           |
                        \   |   /            |
                         \  |  /             |
                           ---               |
    Level 4             7 | D |              |
                           ---               |
                          /   \              |
                         /     \             |
                      ---       ---          |
    Level 3        4 | G |   6 | E |         |
                      ---       ---          |
                       |         |           |
                       |         |           |
                      ---       ---          |
    Level 2        3 | H |   5 | F |         |
                      ---       ---          |
                          \   /  |           |
                           \ /   |           |
                            \    |           |
                           / \   |           |
                          /   \  |           |
                      ---       ---          |
    Level 1        1 | J |   2 | I |         |
                      ---       ---          |
                        \       /            |
                         \     /             |
                           ---               v
    Level 0             0 | K |            (More Specialized)
                           ---


0123456789A
KJIHGFEDABC

=cut

{
    package Test::A;
    sub x { 1 }

    package Test::B;
    sub x { 1 }

    package Test::C;
    sub x { 1 }

    package Test::D;
    our @ISA = qw(Test::A Test::B Test::C);

    package Test::E;
    our @ISA = qw(Test::D);

    package Test::F;
    our @ISA = qw(Test::E);

    package Test::G;
    our @ISA = qw(Test::D);

    package Test::H;
    our @ISA = qw(Test::G);

    package Test::I;
    our @ISA = qw(Test::H Test::F);

    package Test::J;
    our @ISA = qw(Test::F);

    package Test::K;
    our @ISA = qw(Test::J Test::I);
}

sub supers {
    no strict 'refs';
    @{$_[0] . '::ISA'};
}

is_deeply(
    [ Algorithm::C3::merge('Test::A', \&supers) ],
    [ qw(Test::A) ],
    '... got the right C3 merge order for Test::A');

is_deeply(
    [ Algorithm::C3::merge('Test::B', \&supers) ],
    [ qw(Test::B) ],
    '... got the right C3 merge order for Test::B');

is_deeply(
    [ Algorithm::C3::merge('Test::C', \&supers) ],
    [ qw(Test::C) ],
    '... got the right C3 merge order for Test::C');

is_deeply(
    [ Algorithm::C3::merge('Test::D', \&supers) ],
    [ qw(Test::D Test::A Test::B Test::C) ],
    '... got the right C3 merge order for Test::D');

is_deeply(
    [ Algorithm::C3::merge('Test::E', \&supers) ],
    [ qw(Test::E Test::D Test::A Test::B Test::C) ],
    '... got the right C3 merge order for Test::E');

is_deeply(
    [ Algorithm::C3::merge('Test::F', \&supers) ],
    [ qw(Test::F Test::E Test::D Test::A Test::B Test::C) ],
    '... got the right C3 merge order for Test::F');

is_deeply(
    [ Algorithm::C3::merge('Test::G', \&supers) ],
    [ qw(Test::G Test::D Test::A Test::B Test::C) ],
    '... got the right C3 merge order for Test::G');

is_deeply(
    [ Algorithm::C3::merge('Test::H', \&supers) ],
    [ qw(Test::H Test::G Test::D Test::A Test::B Test::C) ],
    '... got the right C3 merge order for Test::H');

is_deeply(
    [ Algorithm::C3::merge('Test::I', \&supers) ],
    [ qw(Test::I Test::H Test::G Test::F Test::E Test::D Test::A Test::B Test::C) ],
    '... got the right C3 merge order for Test::I');

is_deeply(
    [ Algorithm::C3::merge('Test::J', \&supers) ],
    [ qw(Test::J Test::F Test::E Test::D Test::A Test::B Test::C) ],
    '... got the right C3 merge order for Test::J');

is_deeply(
    [ Algorithm::C3::merge('Test::K', \&supers) ],
    [ qw(Test::K Test::J Test::I Test::H Test::G Test::F Test::E Test::D Test::A Test::B Test::C) ],
    '... got the right C3 merge order for Test::K');