| 1 |
#!/usr/bin/perl -w |
| 2 |
|
| 3 |
use utf8; |
| 4 |
use open ":std", ":encoding(UTF-8)"; |
| 5 |
|
| 6 |
use strict; |
| 7 |
use Test::More; |
| 8 |
use DateTime; |
| 9 |
use Finance::Quote; |
| 10 |
|
| 11 |
if (not $ENV{ONLINE_TEST}) { |
| 12 |
plan skip_all => 'Set $ENV{ONLINE_TEST} to run this test'; |
| 13 |
} |
| 14 |
|
| 15 |
plan tests => 9 * 2; |
| 16 |
|
| 17 |
# Find out today |
| 18 |
my $calcDay = DateTime->now(); |
| 19 |
my $year = $calcDay->year(); |
| 20 |
my $month = $calcDay->month(); |
| 21 |
my $day = $calcDay->day(); |
| 22 |
|
| 23 |
# Test Morningstar JP functions. |
| 24 |
|
| 25 |
my $q = Finance::Quote->new(); |
| 26 |
my %valid = ( "2009100101" => "HSBC インド・インフラ株式オープン", |
| 27 |
"2002013108" => "HSBC チャイナオープン"); |
| 28 |
|
| 29 |
my @funds = keys %valid; |
| 30 |
my %info = $q->morningstarjp(@funds); |
| 31 |
ok(%info); |
| 32 |
|
| 33 |
# Check that the symbol/name, date, currency and nav defined for all of the funds. |
| 34 |
foreach my $fund (@funds) |
| 35 |
{ |
| 36 |
|
| 37 |
# NAV date should be within 10 days of today, but we will allow +- 1 day |
| 38 |
# on top of that for running tests outside of Asia/Tokyo timezone |
| 39 |
my $fndyear = substr( $info{ $fund, "isodate" }, 0, 4 ); |
| 40 |
my $fndmonth = substr( $info{ $fund, "isodate" }, 5, 2 ); |
| 41 |
my $fndday = substr( $info{ $fund, "isodate" }, 8, 2 ); |
| 42 |
|
| 43 |
my $fnd = DateTime->new(year=>$fndyear,month=>$fndmonth,day=>$fndday); |
| 44 |
my $deltadays = $calcDay->subtract_datetime($fnd)->in_units('days'); |
| 45 |
|
| 46 |
cmp_ok( $deltadays,'<=', 11, 'not more than 11 days before today' ); |
| 47 |
cmp_ok( $deltadays,'>=', -1, 'not more than 1 day in the future' ); |
| 48 |
|
| 49 |
cmp_ok( $info{ $fund, 'currency' }, 'eq', 'JPY', 'currency' ); |
| 50 |
cmp_ok( $info{ $fund, 'method' }, 'eq', 'MorningstarJP', 'method' ); |
| 51 |
cmp_ok( $info{ $fund, 'name' }, 'eq', $valid{$fund}, 'name' ); |
| 52 |
cmp_ok( $info{ $fund, "nav" }, '>', 0, 'nav' ); |
| 53 |
ok( $info{ $fund, "success" }, 'success' ); |
| 54 |
cmp_ok( $info{ $fund, 'symbol' }, 'eq', $fund, 'symbol' ); |
| 55 |
} |
| 56 |
|
| 57 |
# Check that a bogus symbol returns no-success. |
| 58 |
ok( !$info{ "BOGUS", "success" } ); |