| 1 |
#!/usr/bin/perl -w |
| 2 |
use strict; |
| 3 |
use Test::More; |
| 4 |
use Finance::Quote; |
| 5 |
|
| 6 |
if ( not $ENV{"ONLINE_TEST"} ) { |
| 7 |
plan skip_all => 'Set $ENV{ONLINE_TEST} to run this test'; |
| 8 |
} |
| 9 |
|
| 10 |
my $q = Finance::Quote->new('Fool'); |
| 11 |
my $year = (localtime())[5] + 1900; |
| 12 |
my $lastyear = $year - 1; |
| 13 |
|
| 14 |
my @symbols = qw/MSFT AMZN GOOG CSCO INTC PEP BRK.A SEB NVR BKNG/; |
| 15 |
|
| 16 |
plan tests => 8*(1+$#symbols)+2; |
| 17 |
|
| 18 |
my %quotes = $q->fool(@symbols, "BOGUS"); |
| 19 |
ok(%quotes, "Successful quote retrieval"); |
| 20 |
|
| 21 |
foreach my $symbol (@symbols) { |
| 22 |
ok($quotes{$symbol, "symbol"} eq $symbol, "$symbol defined"); |
| 23 |
ok($quotes{$symbol, "success"}, "$symbol success"); |
| 24 |
ok($quotes{$symbol, "open"} > 0, "$symbol returned open"); |
| 25 |
ok($quotes{$symbol, "volume"} >= 0, "$symbol returned volume"); |
| 26 |
ok($quotes{$symbol, "last"} > 0, "$symbol returned last"); |
| 27 |
ok($quotes{$symbol, "currency"} eq 'USD', "$symbol returned currency"); |
| 28 |
ok(substr($quotes{$symbol, "isodate"}, 0, 4) == $year |
| 29 |
|| substr($quotes{$symbol, "isodate"}, 0, 4) == $lastyear, "$symbol returned valid isodate"); |
| 30 |
ok(substr($quotes{$symbol, "date"}, 6, 4) == $year |
| 31 |
||substr($quotes{$symbol, "date"}, 6, 4) == $lastyear, "$symbol returned valid date"); |
| 32 |
} |
| 33 |
|
| 34 |
ok((!$quotes{"BOGUS", "success"}),'BOGUS failed as expected'); |
| 35 |
|