1#!/usr/bin/perl
2use strict;
3use warnings;
4use Test::Simple tests => 10;
5use Graph::SocialMap;
6use Graph::Writer::GraphViz;
7use IO::All;
8
9my $relation = {
10    1357 => [qw/Marry Rose Autrijus/],
11    3579 => [qw/Marry Peacock/],
12    2468 => [qw/Joan/],
13    4680 => [qw/Rose Joan/],
14    OSSF => [qw/Gugod Autrijus/],
15    GGYY => [qw/Gugod Autrijus Joan Peacock/],
16    1234 => [qw/Tifa Dora Charlee Angie/],
17    5555 => [qw/A B C D E F G H I J K/],
18};
19
20my $gsm = Graph::SocialMap->new(relation => $relation);
21my $writer = Graph::Writer::GraphViz->new(-format=>'dot');
22$writer->write_graph($gsm->type3,'t/graphtest2.dot');
23ok(-f 't/graphtest2.dot');
24unlink('t/graphtest2.dot');
25
26my $adjm = $gsm->type3_adj_matrix;
27ok($adjm->{Rose}->{Marry} == 1);
28
29ok(cmp_hashes($adjm->{Angie},{Tifa=>1,Dora=>1,Charlee=>1}));
30ok(cmp_hashes($adjm->{Charlee},{Tifa=>1,Dora=>1}));
31ok(cmp_hashes($adjm->{Dora},{Tifa=>1}));
32ok(cmp_hashes($adjm->{Marry},{}));
33ok(cmp_hashes($adjm->{Gugod},{}));
34ok(cmp_hashes($adjm->{Joan},{Rose => 1, Gugod => 1, Autrijus => 1}));
35ok(cmp_hashes($adjm->{Autrijus},{Marry=>1,Rose=>1,Gugod=>1}));
36ok(cmp_hashes($adjm->{Peacock} ,{Marry=>1,Gugod=>1,Autrijus=>1,Joan=>1}));
37
38sub cmp_hashes {
39    my ($h1,$h2) = @_;
40    return 0 unless (keys %$h1 == keys %$h2);
41    for (keys %$h1) {
42	return 0 if($h1->{$_} ne $h2->{$_});
43    }
44    return 1;
45}
46