Debian Codegraph @

t/tsp.t

raw
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 $year = (localtime())[5] + 1900;
11 my $lastyear = $year - 1;
12 my $quoter = Finance::Quote->new();
13
14 my @symbols = qw/C F G I S L2030 L2035 L2040 L2045 L2050 L2055 L2060 L2065 LINCOME/;
15
16 plan tests => 12*(1+$#symbols)+3;
17
18 my %quotes = $quoter->tsp( @symbols, "BOGUS" );
19 ok(%quotes);
20
21 foreach my $symbol (@symbols) {
22 ok($quotes{$symbol, "success" }, "$symbol success");
23 ok(substr($quotes{$symbol, "isodate"}, 0, 4) == $year
24 || substr($quotes{$symbol, "isodate"}, 0, 4) == $lastyear);
25 ok(substr($quotes{$symbol, "date"}, 6, 4) == $year
26 || substr($quotes{$symbol, "date"}, 6, 4) == $lastyear);
27 ok($quotes{$symbol,"last"} > 0);
28 ok($quotes{$symbol,"currency"});
29 ok(!defined($quotes{"c","exchange"}) );
30 }
31
32 ok( !$quotes{"BOGUS","success"});
33
34 %quotes = $quoter->fetch("tsp", @symbols);
35 ok(%quotes);
36
37 foreach my $symbol (@symbols) {
38 ok($quotes{$symbol, "success" }, "$symbol success");
39 ok(substr($quotes{$symbol, "isodate"}, 0, 4) == $year
40 || substr($quotes{$symbol, "isodate"}, 0, 4) == $lastyear);
41 ok(substr($quotes{$symbol, "date"}, 6, 4) == $year
42 || substr($quotes{$symbol, "date"}, 6, 4) == $lastyear);
43 ok($quotes{$symbol,"last"} > 0);
44 ok($quotes{$symbol,"currency"});
45 ok(!defined($quotes{"c","exchange"}) );
46 }
47