]> git.donarmstrong.com Git - deb_pkgs/libstatistics-r-perl.git/blob - t/06-get-set.t
Import Upstream version 0.24
[deb_pkgs/libstatistics-r-perl.git] / t / 06-get-set.t
1 #! perl
2
3 use strict;
4 use warnings;
5 use Test::More;
6 use Statistics::R;
7
8 plan tests => 86;
9
10
11 my ($R, $input, $output);
12
13
14 ok $R = Statistics::R->new();
15
16
17 $input = undef;
18 ok $R->set('x', $input), 'undef';
19 is $R->get('x'), undef;
20
21
22 $input = 123;
23 ok $R->set('x', $input);
24 ok $output = $R->get('x'), 'integer';
25 is ref($output), '';
26 is $output, 123;
27
28
29 # R default number of digits is 7
30 $input = 0.93945768644;
31 ok $R->set('x', $input), 'real number';
32 ok $output = $R->get('x');
33 is ref($output), '';
34 is $output, sprintf("%.7f", $input);
35
36
37 $input = "apocalypse";
38 ok $R->set('x', $input), 'string';
39 ok $output = $R->get('x');
40 is ref($output), '';
41 is $output, "apocalypse";
42
43
44 $input = "a string";
45 ok $R->set('x', $input), 'string with witespace';
46 ok $output = $R->get('x');
47 is ref($output), '';
48 is $output, "a string";
49
50
51 $input = 'gi|57116681|ref|NC_000962.2|';
52 ok $R->set('x', $input), 'number-containing string';
53 ok $output = $R->get('x');
54 is ref($output), '';
55 is $output, 'gi|57116681|ref|NC_000962.2|';
56
57
58 # Mixed arrays are considered as string arrays by R, thus there is no digit limit
59 $input = [123, "a string", 'two strings', 0.93945768644];
60 ok $R->set('x', $input), 'mixed array';
61 ok $output = $R->get('x');
62 is ref($output), 'ARRAY';
63 is $$output[0], 123;
64 is $$output[1], "a string";
65 is $$output[2], "two strings";
66 is $$output[3], 0.93945768644;
67
68
69 # RT bug #71988
70 $input = [ q{statistics-r-0.22}, "abc 123 xyz", 'gi|57116681|ref|NC_000962.2|'];
71 ok $R->set('x', $input), 'array of number-containing strings';
72 ok $output = $R->get('x');
73 is ref($output), 'ARRAY';
74 is $$output[0], q{statistics-r-0.22};
75 is $$output[1], "abc 123 xyz";
76 is $$output[2], 'gi|57116681|ref|NC_000962.2|';
77
78
79 $input = [123,142,147,153,145,151,165,129,133,150,142,154,131,146,151,136,147,156,141,155,147,165,168,146,148,146,142,145,161,157,154,137,130,161,130,156,140,145,154];
80 ok $R->set('x', $input), 'large array of integers';
81 ok $output = $R->get('x');
82 is ref($output), 'ARRAY';
83 for (my $i = 0; $i < scalar @$input; $i++) {
84     is $$output[$i], $$input[$i];
85 }
86
87
88 $input = [1, 2, 3];
89 ok $R->set('x', $input), 'data frame';
90 is $R->run(q`a <- data.frame(first=x)`), '';
91 ok $output = $R->get('a$first');
92 is ref($output), 'ARRAY';
93 is $$output[0], 1;
94 is $$output[1], 2;
95 is $$output[2], 3;
96
97
98 ok $R->stop();
99