CC: | RSAVAGE [...] cpan.org |
Subject: | Parse::Taxonomy::MaterializedPath::adjacentify() miscalculates parent IDs |
Date: | Sun, 11 Oct 2015 14:09:15 -0400 |
To: | bug-Parse-Taxonomy [...] rt.cpan.org |
From: | James E Keenan <jkeen [...] verizon.net> |
Parse::Taxonomy::MaterializedPath::adjacentify() is not calculating
parent IDs correctly when the values of second- and third-level leaf
columns repeat under different non-leaf nodes.
Example:
#####
use strict;
use warnings;
use Test::More qw(no_plan);
{
note("Test same second- and third-level leaf fields");
my @input_columns = ( qw| path letter_vendor_id is_actionable | );
my @data_records = (
["|alpha", 1, 0],
["|alpha|able", 1, 0],
["|alpha|able|Agnes", 1, 1],
["|alpha|able|Agnew", 1, 1],
["|alpha|baker", 1, 0],
["|alpha|baker|Agnes", 1, 1],
["|alpha|baker|Agnew", 1, 1],
["|beta", 1, 0],
["|beta|able", 1, 0],
["|beta|able|Agnes", 1, 1],
["|beta|able|Agnew", 1, 1],
["|beta|baker", 1, 0],
["|beta|baker|Agnes", 1, 1],
["|beta|baker|Agnew", 1, 1],
);
my $obj = Parse::Taxonomy::MaterializedPath->new( {
components => {
fields => \@input_columns,
data_records => \@data_records,
}
} );
ok(defined $obj, "'new()' returned defined value");
isa_ok($obj, 'Parse::Taxonomy::MaterializedPath');
my %expected_parents = (
1 => '',
2 => 1,
3 => 2,
4 => 2,
5 => 1,
6 => 5,
7 => 5,
8 => '',
9 => 8,
10 => 9,
11 => 9,
12 => 8,
13 => 12,
14 => 12,
);
my $adjacentified = $obj->adjacentify();
ok($adjacentified, "'adjacentify() returned true value");
my %observed_parents = map { $_->{id} => $_->{parent_id } }
@{$adjacentified};
is_deeply(\%observed_parents, \%expected_parents, "Got expected
parent_ids");
}
#####
t/005-adjacentify.t ..
# Test same second- and third-level leaf fields
ok 1 - 'new()' returned defined value
ok 2 - An object of class 'Parse::Taxonomy::MaterializedPath' isa
'Parse::Taxonomy::MaterializedPath'
ok 3 - 'adjacentify() returned true value
not ok 4 - Got expected parent_ids
# Failed test 'Got expected
parent_ids'Parse::Taxonomy::MaterializedPath::adjacentify() is not
calculating parent IDs correctly when the values of second- and
third-level leaf columns repeat under different non-leaf nodes.
Example:
#####
use strict;
use warnings;
use Test::More qw(no_plan);
{
note("Test same second- and third-level leaf fields");
my @input_columns = ( qw| path letter_vendor_id is_actionable | );
my @data_records = (
["|alpha", 1, 0],
["|alpha|able", 1, 0],
["|alpha|able|Agnes", 1, 1],
["|alpha|able|Agnew", 1, 1],
["|alpha|baker", 1, 0],
["|alpha|baker|Agnes", 1, 1],
["|alpha|baker|Agnew", 1, 1],
["|beta", 1, 0],
["|beta|able", 1, 0],
["|beta|able|Agnes", 1, 1],
["|beta|able|Agnew", 1, 1],
["|beta|baker", 1, 0],
["|beta|baker|Agnes", 1, 1],
["|beta|baker|Agnew", 1, 1],
);
my $obj = Parse::Taxonomy::MaterializedPath->new( {
components => {
fields => \@input_columns,
data_records => \@data_records,
}
} );
ok(defined $obj, "'new()' returned defined value");
isa_ok($obj, 'Parse::Taxonomy::MaterializedPath');
my %expected_parents = (
1 => '',
2 => 1,
3 => 2,
4 => 2,
5 => 1,
6 => 5,
7 => 5,
8 => '',
9 => 8,
10 => 9,
11 => 9,
12 => 8,
13 => 12,
14 => 12,
);
my $adjacentified = $obj->adjacentify();
ok($adjacentified, "'adjacentify() returned true value");
my %observed_parents = map { $_->{id} => $_->{parent_id } }
@{$adjacentified};
is_deeply(\%observed_parents, \%expected_parents, "Got expected
parent_ids");
}
#####
t/005-adjacentify.t ..
# Test same second- and third-level leaf fields
ok 1 - 'new()' returned defined value
ok 2 - An object of class 'Parse::Taxonomy::MaterializedPath' isa
'Parse::Taxonomy::MaterializedPath'
ok 3 - 'adjacentify() returned true value
not ok 4 - Got expected parent_ids
# Failed test 'Got expected parent_ids'
# at t/005-adjacentify.t line 293.
# Structures begin differing at:
# $got->{9} = '6'
# $expected->{9} = '8'
1..4
# Looks like you failed 1 test of 4.
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/4 subtests
Test Summary Report
-------------------
t/005-adjacentify.t (Wstat: 256 Tests: 4 Failed: 1)
Failed test: 4
Non-zero exit status: 1
Files=1, Tests=4, 0 wallclock secs ( 0.02 usr 0.00 sys + 0.03 cusr
0.00 csys = 0.05 CPU)
Result: FAIL
# at t/005-adjacentify.t line 293.
# Structures begin differing at:
# $got->{9} = '6'
# $expected->{9} = '8'
1..4
# Looks like you failed 1 test of 4.
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/4 subtests
Test Summary Report
-------------------
t/005-adjacentify.t (Wstat: 256 Tests: 4 Failed: 1)
Failed test: 4
Non-zero exit status: 1
Files=1, Tests=4, 0 wallclock secs ( 0.02 usr 0.00 sys + 0.03 cusr
0.00 csys = 0.05 CPU)
Result: FAIL