File: 002_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 (102 lines) | stat: -rw-r--r-- 2,809 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
use strict;
use warnings;

use Test::More tests => 6;

use Algorithm::C3;

=pod

This example is take from: http://www.python.org/2.3/mro.html

"My first example"
class O: pass
class F(O): pass
class E(O): pass
class D(O): pass
class C(D,F): pass
class B(D,E): pass
class A(B,C): pass


                              6
                             ---
    Level 3                 | O |                  (more general)
                          /  ---  \
                         /    |    \                      |
                        /     |     \                     |
                       /      |      \                    |
                      ---    ---    ---                   |
    Level 2        3 | D | 4| E |  | F | 5                |
                      ---    ---    ---                   |
                       \  \ _ /       |                   |
                        \    / \ _    |                   |
                         \  /      \  |                   |
                          ---      ---                    |
    Level 1            1 | B |    | C | 2                 |
                          ---      ---                    |
                            \      /                      |
                             \    /                      \ /
                              ---
    Level 0                0 | A |                (more specialized)
                              ---

=cut

{
    package Test::O;

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

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

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

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

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

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

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

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

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

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

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

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

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