File: 010_complex_merge_classless.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 (123 lines) | stat: -rw-r--r-- 3,247 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
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

my $foo = {
  k => [qw(j i)],
  j => [qw(f)],
  i => [qw(h f)],
  h => [qw(g)],
  g => [qw(d)],
  f => [qw(e)],
  e => [qw(d)],
  d => [qw(a b c)],
  c => [],
  b => [],
  a => [],
};

sub supers {
  return @{ $foo->{ $_[0] } };
}

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

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

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

is_deeply(
    [ Algorithm::C3::merge('d', \&supers) ],
    [ qw(d a b c) ],
    '... got the right C3 merge order for d');

is_deeply(
    [ Algorithm::C3::merge('e', \&supers) ],
    [ qw(e d a b c) ],
    '... got the right C3 merge order for e');

is_deeply(
    [ Algorithm::C3::merge('f', \&supers) ],
    [ qw(f e d a b c) ],
    '... got the right C3 merge order for f');

is_deeply(
    [ Algorithm::C3::merge('g', \&supers) ],
    [ qw(g d a b c) ],
    '... got the right C3 merge order for g');

is_deeply(
    [ Algorithm::C3::merge('h', \&supers) ],
    [ qw(h g d a b c) ],
    '... got the right C3 merge order for h');

is_deeply(
    [ Algorithm::C3::merge('i', \&supers) ],
    [ qw(i h g f e d a b c) ],
    '... got the right C3 merge order for i');

is_deeply(
    [ Algorithm::C3::merge('j', \&supers) ],
    [ qw(j f e d a b c) ],
    '... got the right C3 merge order for j');

is_deeply(
    [ Algorithm::C3::merge('k', \&supers) ],
    [ qw(k j i h g f e d a b c) ],
    '... got the right C3 merge order for k');