This repository was archived by the owner on Mar 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgreadfolls.t
executable file
·102 lines (72 loc) · 3.08 KB
/
greadfolls.t
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
#!/usr/bin/perl -w
# Test cases realized:
# [x] get friends and followees
# [x] get friends only
# [x] get followees only
# [ ] get only friends who are authors
# [ ] get only followees who are authors
# [x] discard threshold
# [ ] check member attributees
use diagnostics; # More debugging info
use warnings;
use strict;
use FindBin;
use local::lib "$FindBin::Bin/../lib/local/";
use lib "$FindBin::Bin/../lib/";
use lib "$FindBin::Bin/../t/";
use Test::More qw( no_plan );
use List::MoreUtils qw( duplicates );
use_ok( 'Goodscrapes' );
require( 'config.pl' );
# We should never use caching during real tests:
# We need to test against the most up-to-date markup from Goodreads.com
# Having no cache during development is annoying, tho.
# So we leave a small window:
gsetopt( cache_days => 1 );
# Access to member lists needs some privileges:
glogin( usermail => get_gooduser_mail(),
userpass => get_gooduser_pass() );
my $userid = '2';
my $discard_threshold = 3;
my %friends;
my %followees;
my %all;
my %discarded_friends;
my %discarded_followees;
greadfolls( from_user_id => $userid,
rh_into => \%friends,
incl_followees => 0,
incl_friends => 1,
incl_authors => 1 );
greadfolls( from_user_id => $userid,
rh_into => \%followees,
incl_followees => 1,
incl_friends => 0,
incl_authors => 1 );
greadfolls( from_user_id => $userid,
rh_into => \%all,
incl_followees => 1,
incl_friends => 1,
incl_authors => 1 );
greadfolls( from_user_id => $userid,
rh_into => \%discarded_friends,
discard_threshold => $discard_threshold,
incl_followees => 0,
incl_friends => 1,
incl_authors => 1 );
greadfolls( from_user_id => $userid,
rh_into => \%discarded_followees,
discard_threshold => $discard_threshold,
incl_followees => 1,
incl_friends => 0,
incl_authors => 1 );
ok( exists $friends{1}, "Member $userid and Otis Chandler are friends" );
ok( exists $followees{21269}, "Member $userid is following Guy Kawasaki (author)" );
ok( exists $friends{1} && exists $followees{21269}, "Member $userid is friends with Otis Chandler and is following Guy Kawasaki (author)" );
ok( !%discarded_friends, "No friends returned if there are more than $discard_threshold" );
ok( !%discarded_followees, "No followees returned if there are more than $discard_threshold" );
my @kfriends = keys %friends;
my @kfollowees = keys %followees;
my @kall = keys %all;
ok( !duplicates(( @kfriends, @kfollowees )), 'Friends and followees lists expected to be exclusive' );
is( scalar(@kall), scalar(duplicates(( @kfriends, @kfollowees, @kall ))), 'Friends and followees in all-list expected' );