File: tsx.t

package info (click to toggle)
libfinance-quote-perl 1.35-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,432 kB
  • ctags: 394
  • sloc: perl: 8,716; makefile: 2
file content (49 lines) | stat: -rwxr-xr-x 1,020 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl -w
use strict;
use Test::More;
use Data::Dumper;
use Finance::Quote;

if (not $ENV{ONLINE_TEST}) {
    plan skip_all => 'Set $ENV{ONLINE_TEST} to run this test';
}

plan tests => 26 ;

# Test TSX functions.

my $q      = Finance::Quote->new();
my @stocks = ("NT", "BCE", "AER");

my %regexps = (
	NT  => qr/\bNortel\b/,
	BCE => qr/\b(BCE|Bell)\b/,
	AER => qr/\bAeroplan\b/,
);


my %quotes = $q->fetch("tsx", @stocks);
ok(%quotes);

foreach my $stock (@stocks) {

	my $name = $quotes{$stock, "name"};
	print "#Testing $stock: $name\n";

	my $regexp = $regexps{$stock};
	ok($name =~ /$regexp/i);

	ok($quotes{$stock, "exchange"} eq 'T');
	ok($quotes{$stock, "method"} eq 'tsx');

	ok($quotes{$stock, "last"} > 0);
	ok($quotes{$stock, "net"} =~ /^-?\d+\.\d+$/);
	ok($quotes{$stock, "p_change"} =~ /^-?\d+\.\d+$/);
	ok($quotes{$stock, "success"});
	ok($quotes{$stock, "volume"} >= 0);
}


# Check that a bogus stock returns no-success.
%quotes = $q->fetch("tsx", "BOGUS");
ok(! $quotes{"BOGUS","success"});