Commit | Line | Data |
c0b91998 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More tests => 7; |
7 | |
8 | BEGIN { |
9 | use_ok('Algorithm::C3'); |
10 | } |
11 | |
12 | =pod |
13 | |
14 | This example is take from: http://www.python.org/2.3/mro.html |
15 | |
16 | "My first example" |
17 | class O: pass |
18 | class F(O): pass |
19 | class E(O): pass |
20 | class D(O): pass |
21 | class C(D,F): pass |
22 | class B(D,E): pass |
23 | class A(B,C): pass |
24 | |
25 | |
26 | 6 |
27 | --- |
28 | Level 3 | O | (more general) |
29 | / --- \ |
30 | / | \ | |
31 | / | \ | |
32 | / | \ | |
33 | --- --- --- | |
34 | Level 2 3 | D | 4| E | | F | 5 | |
35 | --- --- --- | |
36 | \ \ _ / | | |
37 | \ / \ _ | | |
38 | \ / \ | | |
39 | --- --- | |
40 | Level 1 1 | B | | C | 2 | |
41 | --- --- | |
42 | \ / | |
43 | \ / \ / |
44 | --- |
45 | Level 0 0 | A | (more specialized) |
46 | --- |
47 | |
48 | =cut |
49 | |
50 | { |
51 | package Test::O; |
52 | |
53 | sub supers { |
54 | no strict 'refs'; |
55 | @{$_[0] . '::ISA'}; |
56 | } |
57 | |
58 | package Test::F; |
59 | use base 'Test::O'; |
60 | |
61 | package Test::E; |
62 | use base 'Test::O'; |
63 | |
64 | package Test::D; |
65 | use base 'Test::O'; |
66 | |
67 | package Test::C; |
68 | use base ('Test::D', 'Test::F'); |
69 | |
70 | package Test::B; |
71 | use base ('Test::D', 'Test::E'); |
72 | |
73 | package Test::A; |
74 | use base ('Test::B', 'Test::C'); |
75 | } |
76 | |
77 | is_deeply( |
78 | [ Algorithm::C3::merge('Test::F', 'supers') ], |
79 | [ qw(Test::F Test::O) ], |
80 | '... got the right C3 merge order for Test::F'); |
81 | |
82 | is_deeply( |
83 | [ Algorithm::C3::merge('Test::E', 'supers') ], |
84 | [ qw(Test::E Test::O) ], |
85 | '... got the right C3 merge order for Test::E'); |
86 | |
87 | is_deeply( |
88 | [ Algorithm::C3::merge('Test::D', 'supers') ], |
89 | [ qw(Test::D Test::O) ], |
90 | '... got the right C3 merge order for Test::D'); |
91 | |
92 | is_deeply( |
93 | [ Algorithm::C3::merge('Test::C', 'supers') ], |
94 | [ qw(Test::C Test::D Test::F Test::O) ], |
95 | '... got the right C3 merge order for Test::C'); |
96 | |
97 | is_deeply( |
98 | [ Algorithm::C3::merge('Test::B', 'supers') ], |
99 | [ qw(Test::B Test::D Test::E Test::O) ], |
100 | '... got the right C3 merge order for Test::B'); |
101 | |
102 | is_deeply( |
103 | [ Algorithm::C3::merge('Test::A', 'supers') ], |
104 | [ qw(Test::A Test::B Test::C Test::D Test::E Test::F Test::O) ], |
105 | '... got the right C3 merge order for Test::A'); |
106 | |
107 | |