| 1 | #!/usr/bin/perl -w |
| 2 | |
| 3 | use utf8scip-perl cpan Finance-Quote 1.70 utf8/; |
| 4 | use openscip-perl cpan Finance-Quote 1.70 open/ ":std", ":encoding(UTF-8)"; |
| 5 | |
| 6 | use strictscip-perl cpan Finance-Quote 1.70 strict/; |
| 7 | use Test::Morescip-perl cpan Finance-Quote 1.70 Test/More/; |
| 8 | use DateTimescip-perl cpan Finance-Quote 1.70 DateTime/; |
| 9 | use Finance::Quotescip-perl cpan Finance-Quote 1.70 Finance/Quote/; |
| 10 | |
| 11 | if (not $ENVscip-perl cpan Finance-Quote 1.70 main/`%ENV`.{ONLINE_TEST}) { |
| 12 | planscip-perl cpan Finance-Quote 1.70 main/plan(). skip_all => 'Set $ENV{ONLINE_TEST} to run this test'; |
| 13 | } |
| 14 | |
| 15 | planscip-perl cpan Finance-Quote 1.70 main/plan(). tests => 9 * 2; |
| 16 | |
| 17 | # Find out today |
| 18 | my $calcDay = DateTime->nowscip-perl cpan Finance-Quote 1.70 DateTime/now().(); |
| 19 | my $year = $calcDay->yearscip-perl cpan Finance-Quote 1.70 DateTime/year().(); |
| 20 | my $month = $calcDay->monthscip-perl cpan Finance-Quote 1.70 DateTime/month().(); |
| 21 | my $day = $calcDay->dayscip-perl cpan Finance-Quote 1.70 DateTime/day().(); |
| 22 | |
| 23 | # Test Morningstar JP functions. |
| 24 | |
| 25 | my $q = Finance::Quote->newscip-perl cpan Finance-Quote 1.70 Finance/Quote/new().(); |
| 26 | my %valid = ( "2009100101" => "HSBC インド・インフラ株式オープン", |
| 27 | "2002013108" => "HSBC チャイナオープン"); |
| 28 | |
| 29 | my @funds = keysscip-perl cpan Finance-Quote 1.70 main/keys(). %valid; |
| 30 | my %info = $q->morningstarjpscip-perl cpan Finance-Quote 1.70 Finance/Quote/morningstarjp().(@funds); |
| 31 | okscip-perl cpan Finance-Quote 1.70 main/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 = substrscip-perl cpan Finance-Quote 1.70 main/substr().( $info{ $fund, "isodate" }, 0, 4 ); |
| 40 | my $fndmonth = substrscip-perl cpan Finance-Quote 1.70 main/substr().( $info{ $fund, "isodate" }, 5, 2 ); |
| 41 | my $fndday = substrscip-perl cpan Finance-Quote 1.70 main/substr().( $info{ $fund, "isodate" }, 8, 2 ); |
| 42 | |
| 43 | my $fnd = DateTime->newscip-perl cpan Finance-Quote 1.70 DateTime/new().(year=>$fndyear,month=>$fndmonth,day=>$fndday); |
| 44 | my $deltadays = $calcDay->subtract_datetimescip-perl cpan Finance-Quote 1.70 DateTime/subtract_datetime().($fnd)->in_unitsscip-perl cpan Finance-Quote 1.70 main/in_units().('days'); |
| 45 | |
| 46 | cmp_okscip-perl cpan Finance-Quote 1.70 main/cmp_ok().( $deltadays,'<=', 11, 'not more than 11 days before today' ); |
| 47 | cmp_okscip-perl cpan Finance-Quote 1.70 main/cmp_ok().( $deltadays,'>=', -1, 'not more than 1 day in the future' ); |
| 48 | |
| 49 | cmp_okscip-perl cpan Finance-Quote 1.70 main/cmp_ok().( $info{ $fund, 'currency' }, 'eq', 'JPY', 'currency' ); |
| 50 | cmp_okscip-perl cpan Finance-Quote 1.70 main/cmp_ok().( $info{ $fund, 'method' }, 'eq', 'MorningstarJP', 'method' ); |
| 51 | cmp_okscip-perl cpan Finance-Quote 1.70 main/cmp_ok().( $info{ $fund, 'name' }, 'eq', $valid{$fund}, 'name' ); |
| 52 | cmp_okscip-perl cpan Finance-Quote 1.70 main/cmp_ok().( $info{ $fund, "nav" }, '>', 0, 'nav' ); |
| 53 | okscip-perl cpan Finance-Quote 1.70 main/ok().( $info{ $fund, "success" }, 'success' ); |
| 54 | cmp_okscip-perl cpan Finance-Quote 1.70 main/cmp_ok().( $info{ $fund, 'symbol' }, 'eq', $fund, 'symbol' ); |
| 55 | } |
| 56 | |
| 57 | # Check that a bogus symbol returns no-success. |
| 58 | okscip-perl cpan Finance-Quote 1.70 main/ok().( !$info{ "BOGUS", "success" } ); |