Skip to content

Commit

Permalink
Merge pull request #11 from davorg/9-ids-do-not-have-to-be-numbers
Browse files Browse the repository at this point in the history
9 ids do not have to be numbers
  • Loading branch information
davorg committed May 24, 2023
2 parents 126952c + 3a6958f commit 48d5c33
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions Changes.md
Expand Up @@ -5,6 +5,7 @@
### Fixed

- Pod error
- IDs no longer need to be numbers

## [0.1.2] - 2023-05-23

Expand Down
10 changes: 5 additions & 5 deletions lib/Genealogy/Relationship.pm
Expand Up @@ -46,7 +46,7 @@ person.
=item * id
This method should return a unique identifier for the current person.
The identifier should be a number.
The identifier can be a string or a number.
=item * gender
Expand Down Expand Up @@ -157,14 +157,14 @@ sub most_recent_common_ancestor {
my ($person1, $person2) = @_;

# Are they the same person?
return $person1 if $person1->id == $person2->id;
return $person1 if $person1->id eq $person2->id;

my @ancestors1 = ($person1, $self->get_ancestors($person1));
my @ancestors2 = ($person2, $self->get_ancestors($person2));

for my $anc1 (@ancestors1) {
for my $anc2 (@ancestors2) {
return $anc1 if $anc1->id == $anc2->id;
return $anc1 if $anc1->id eq $anc2->id;
}
}

Expand Down Expand Up @@ -304,14 +304,14 @@ sub get_relationship_coords {
my ($person1, $person2) = @_;

# If the two people are the same person, then return (0, 0).
return (0, 0) if $person1->id == $person2->id;
return (0, 0) if $person1->id eq $person2->id;

my @ancestors1 = ($person1, $self->get_ancestors($person1));
my @ancestors2 = ($person2, $self->get_ancestors($person2));

for my $i (0 .. $#ancestors1) {
for my $j (0 .. $#ancestors2) {
return ($i, $j) if $ancestors1[$i]->id == $ancestors2[$j]->id;
return ($i, $j) if $ancestors1[$i]->id eq $ancestors2[$j]->id;
}
}

Expand Down
12 changes: 6 additions & 6 deletions t/02-ancestors.t
Expand Up @@ -9,36 +9,36 @@ use lib "$Bin/lib";
use TestPerson;

my $grandfather = TestPerson->new(
id => 1,
id => 'p1',
name => 'Grandfather',
gender => 'm',
);
my $father = TestPerson->new(
id => 2,
id => 'p2',
name => 'Father',
parent => $grandfather,
gender => 'm',
);
my $son = TestPerson->new(
id => 3,
id => 'p3',
name => 'Son',
parent => $father,
gender => 'm',
);
my $uncle = TestPerson->new(
id => 4,
id => 'p4',
name => 'Uncle',
parent => $grandfather,
gender => 'm',
);
my $cousin = TestPerson->new(
id => 5,
id => 'p5',
name => 'Cousin',
parent => $uncle,
gender => 'f',
);
my $unrelated_woman = TestPerson->new(
id => 6,
id => 'p6',
name => 'Unrelated woman',
gender => 'f',
);
Expand Down
2 changes: 1 addition & 1 deletion t/lib/TestPerson.pm
Expand Up @@ -4,7 +4,7 @@ use Types::Standard qw[Str Int InstanceOf Enum];

has id => (
is => 'ro',
isa => Int,
isa => Str,
);

has name => (
Expand Down

0 comments on commit 48d5c33

Please sign in to comment.