Commit | Line | Data |
afe3f8e0 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More tests => 12; |
7 | |
8 | BEGIN { |
9 | use_ok('Algorithm::C3'); |
10 | } |
11 | |
12 | =pod |
13 | |
14 | This example is taken from: http://rt.cpan.org/Public/Bug/Display.html?id=20879 |
15 | |
16 | --- --- --- |
17 | Level 5 8 | A | 9 | B | A | C | (More General) |
18 | --- --- --- V |
19 | \ | / | |
20 | \ | / | |
21 | \ | / | |
22 | \ | / | |
23 | --- | |
24 | Level 4 7 | D | | |
25 | --- | |
26 | / \ | |
27 | / \ | |
28 | --- --- | |
29 | Level 3 4 | G | 6 | E | | |
30 | --- --- | |
31 | | | | |
32 | | | | |
33 | --- --- | |
34 | Level 2 3 | H | 5 | F | | |
35 | --- --- | |
36 | \ / | | |
37 | \ / | | |
38 | \ | | |
39 | / \ | | |
40 | / \ | | |
41 | --- --- | |
42 | Level 1 1 | J | 2 | I | | |
43 | --- --- | |
44 | \ / | |
45 | \ / | |
46 | --- v |
47 | Level 0 0 | K | (More Specialized) |
48 | --- |
49 | |
50 | |
51 | 0123456789A |
52 | KJIHGFEDABC |
53 | |
54 | =cut |
55 | |
56 | my $foo = { |
57 | k => [qw(j i)], |
58 | j => [qw(f)], |
59 | i => [qw(h f)], |
60 | h => [qw(g)], |
61 | g => [qw(d)], |
62 | f => [qw(e)], |
63 | e => [qw(d)], |
64 | d => [qw(a b c)], |
65 | c => [], |
66 | b => [], |
67 | a => [], |
68 | }; |
69 | |
70 | sub supers { |
71 | return @{ $foo->{ $_[0] } }; |
72 | } |
73 | |
74 | is_deeply( |
75 | [ Algorithm::C3::merge('a', \&supers) ], |
76 | [ qw(a) ], |
77 | '... got the right C3 merge order for a'); |
78 | |
79 | is_deeply( |
80 | [ Algorithm::C3::merge('b', \&supers) ], |
81 | [ qw(b) ], |
82 | '... got the right C3 merge order for b'); |
83 | |
84 | is_deeply( |
85 | [ Algorithm::C3::merge('c', \&supers) ], |
86 | [ qw(c) ], |
87 | '... got the right C3 merge order for c'); |
88 | |
89 | is_deeply( |
90 | [ Algorithm::C3::merge('d', \&supers) ], |
91 | [ qw(d a b c) ], |
92 | '... got the right C3 merge order for d'); |
93 | |
94 | is_deeply( |
95 | [ Algorithm::C3::merge('e', \&supers) ], |
96 | [ qw(e d a b c) ], |
97 | '... got the right C3 merge order for e'); |
98 | |
99 | is_deeply( |
100 | [ Algorithm::C3::merge('f', \&supers) ], |
101 | [ qw(f e d a b c) ], |
102 | '... got the right C3 merge order for f'); |
103 | |
104 | is_deeply( |
105 | [ Algorithm::C3::merge('g', \&supers) ], |
106 | [ qw(g d a b c) ], |
107 | '... got the right C3 merge order for g'); |
108 | |
109 | is_deeply( |
110 | [ Algorithm::C3::merge('h', \&supers) ], |
111 | [ qw(h g d a b c) ], |
112 | '... got the right C3 merge order for h'); |
113 | |
114 | is_deeply( |
115 | [ Algorithm::C3::merge('i', \&supers) ], |
116 | [ qw(i h g f e d a b c) ], |
117 | '... got the right C3 merge order for i'); |
118 | |
119 | is_deeply( |
120 | [ Algorithm::C3::merge('j', \&supers) ], |
121 | [ qw(j f e d a b c) ], |
122 | '... got the right C3 merge order for j'); |
123 | |
124 | is_deeply( |
125 | [ Algorithm::C3::merge('k', \&supers) ], |
126 | [ qw(k j i h g f e d a b c) ], |
127 | '... got the right C3 merge order for k'); |