update gitignore
[gitmo/Algorithm-C3.git] / t / 010_complex_merge_classless.t
CommitLineData
afe3f8e0 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More tests => 12;
7
8BEGIN {
9 use_ok('Algorithm::C3');
10}
11
12=pod
13
14This example is taken from: http://rt.cpan.org/Public/Bug/Display.html?id=20879
15
16 --- --- ---
17Level 5 8 | A | 9 | B | A | C | (More General)
18 --- --- --- V
19 \ | / |
20 \ | / |
21 \ | / |
22 \ | / |
23 --- |
24Level 4 7 | D | |
25 --- |
26 / \ |
27 / \ |
28 --- --- |
29Level 3 4 | G | 6 | E | |
30 --- --- |
31 | | |
32 | | |
33 --- --- |
34Level 2 3 | H | 5 | F | |
35 --- --- |
36 \ / | |
37 \ / | |
38 \ | |
39 / \ | |
40 / \ | |
41 --- --- |
42Level 1 1 | J | 2 | I | |
43 --- --- |
44 \ / |
45 \ / |
46 --- v
47Level 0 0 | K | (More Specialized)
48 ---
49
50
510123456789A
52KJIHGFEDABC
53
54=cut
55
56my $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
70sub supers {
71 return @{ $foo->{ $_[0] } };
72}
73
74is_deeply(
75 [ Algorithm::C3::merge('a', \&supers) ],
76 [ qw(a) ],
77 '... got the right C3 merge order for a');
78
79is_deeply(
80 [ Algorithm::C3::merge('b', \&supers) ],
81 [ qw(b) ],
82 '... got the right C3 merge order for b');
83
84is_deeply(
85 [ Algorithm::C3::merge('c', \&supers) ],
86 [ qw(c) ],
87 '... got the right C3 merge order for c');
88
89is_deeply(
90 [ Algorithm::C3::merge('d', \&supers) ],
91 [ qw(d a b c) ],
92 '... got the right C3 merge order for d');
93
94is_deeply(
95 [ Algorithm::C3::merge('e', \&supers) ],
96 [ qw(e d a b c) ],
97 '... got the right C3 merge order for e');
98
99is_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
104is_deeply(
105 [ Algorithm::C3::merge('g', \&supers) ],
106 [ qw(g d a b c) ],
107 '... got the right C3 merge order for g');
108
109is_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
114is_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
119is_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
124is_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');