rserve-client 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,43 @@
1
+ require File.dirname(__FILE__)+"/spec_helper.rb"
2
+ describe Rserve::Connection do
3
+ describe "opening and closing" do
4
+ it "should be open a connection and receive ID-String" do
5
+ @r=Rserve::Connection.new()
6
+ @r.get_server_version.should==103
7
+ @r.protocol.should=="QAP1"
8
+ @r.last_error.should=="OK"
9
+ @r.rt.should be_instance_of(Rserve::Talk)
10
+ end
11
+ it "should quit correctly" do
12
+ @r=Rserve::Connection.new
13
+ @r.should be_connected
14
+ @r.close.should be_true
15
+ @r.should_not be_connected
16
+ @r.close.should be_true
17
+ end
18
+ after do
19
+ @r.close if @r.connected?
20
+ end
21
+
22
+ end
23
+ describe "basic eval methods" do
24
+ before do
25
+ @r=Rserve::Connection.new
26
+ end
27
+ it "should eval_void correctly" do
28
+ @r.void_eval("x<-1").should be_true
29
+ end
30
+ it "should eval correctly" do
31
+ la=@r.eval("c(TRUE,TRUE,FALSE,FALSE)")
32
+ la.should be_instance_of(Rserve::REXP::Logical)
33
+ la.true?.should==[true,true,false,false]
34
+ end
35
+ it "should eval_void and eval correctly" do
36
+ @r.void_eval("x<-c(TRUE,FALSE)").should be_true
37
+ la=@r.eval("x")
38
+ la.should be_instance_of(Rserve::REXP::Logical)
39
+ la.true?.should==[true,false]
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,55 @@
1
+ require File.dirname(__FILE__)+"/spec_helper.rb"
2
+
3
+ describe Rserve::REXP::Double do
4
+ describe "initialization" do
5
+ it "should accept array as payload" do
6
+ payload=[1,2,3]
7
+ a=Rserve::REXP::Double.new(payload)
8
+ a.payload.should==payload.map(&:to_f)
9
+ end
10
+ it "should accept float as payload" do
11
+ payload=1.1
12
+ a=Rserve::REXP::Double.new(payload)
13
+ a.payload.should==[1.1]
14
+ end
15
+
16
+
17
+
18
+ end
19
+ describe "common methods" do
20
+ before do
21
+ @n=rand(10)+10
22
+ @payload=@n.times.map {rand(10).to_f}
23
+ @a=Rserve::REXP::Double.new(@payload)
24
+ end
25
+ subject {@a}
26
+ it "should return correct length of payload" do
27
+ @a.length.should==@n
28
+ end
29
+ it {should be_numeric}
30
+ it {should be_integer}
31
+ it "method as_integer should return payload as integers" do
32
+ @a.as_integers.should==@payload.map(&:to_i)
33
+ end
34
+ it "method as_doubles should return floats" do
35
+ @a.as_doubles.should==@payload
36
+ end
37
+ it "method as_strings should return strings" do
38
+ @a.as_strings.should==@payload.map(&:to_s)
39
+ end
40
+ it "method na? should return coherent answer" do
41
+ payload=[3,5,Rserve::REXP::Double::NA, 10,20]
42
+ a=Rserve::REXP::Double.new(payload)
43
+ a.na?(a.as_integers[0]).should be_false
44
+ a.na?(a.as_integers[2]).should be_true
45
+ a.na?.should==[false,false,true,false,false]
46
+ end
47
+ it "method to_debug_string and to_s returns a coherent response" do
48
+ @a.to_debug_string.size.should>0
49
+ @a.to_s.size.should>0
50
+
51
+ end
52
+ end
53
+
54
+
55
+ end
@@ -0,0 +1,55 @@
1
+ require File.dirname(__FILE__)+"/spec_helper.rb"
2
+
3
+ describe Rserve::REXP::Integer do
4
+ describe "initialization" do
5
+ it "should accept array as payload" do
6
+ payload=[1,2,3]
7
+ a=Rserve::REXP::Integer.new(payload)
8
+ a.payload.should==payload
9
+ end
10
+ it "should accept integer as payload" do
11
+ payload=1
12
+ a=Rserve::REXP::Integer.new(payload)
13
+ a.payload.should==[1]
14
+ end
15
+
16
+
17
+
18
+ end
19
+ describe "common methods" do
20
+ before do
21
+ @n=rand(10)+10
22
+ @payload=@n.times.map {rand(10)}
23
+ @a=Rserve::REXP::Integer.new(@payload)
24
+ end
25
+ subject {@a}
26
+ it "should return correct length of payload" do
27
+ @a.length.should==@n
28
+ end
29
+ it {should be_numeric}
30
+ it {should be_integer}
31
+ it "method as_integer should return payload" do
32
+ @a.as_integers.should==@payload
33
+ end
34
+ it "method as_doubles should return floats" do
35
+ @a.as_doubles.should==@payload.map(&:to_f)
36
+ end
37
+ it "method as_string should return string" do
38
+ @a.as_strings.should==@payload.map(&:to_s)
39
+ end
40
+ it "method is_NA should return coherent answer" do
41
+ payload=[3,5,Rserve::REXP::Integer::NA, 10,20]
42
+ a=Rserve::REXP::Integer.new(payload)
43
+ a.na?(a.as_integers[0]).should be_false
44
+ a.na?(a.as_integers[2]).should be_true
45
+ a.na?.should==[false,false,true,false,false]
46
+ end
47
+ it "method to_debug_string and to_s returns a coherent response" do
48
+ @a.to_debug_string.size.should>0
49
+ @a.to_s.size.should>0
50
+
51
+ end
52
+ end
53
+
54
+
55
+ end
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__)+"/spec_helper.rb"
2
+
3
+ describe Rserve::Packet do
4
+ it "should be ok if cmd isn't an error" do
5
+ packet=Rserve::Packet.new(Rserve::Protocol::RESP_OK,[1,2,3,4])
6
+ packet.should be_ok
7
+ packet.should_not be_error
8
+ end
9
+ it "should be error if cmd is an error" do
10
+ packet=Rserve::Packet.new(Rserve::Protocol::RESP_ERR,[1,2,3,4])
11
+ packet.should be_error
12
+ packet.should_not be_ok
13
+ end
14
+ it "method to_s should return coherent to_s" do
15
+ packet=Rserve::Packet.new(Rserve::Protocol::RESP_OK,[1,2,3,4])
16
+ packet.to_s.should match /Packet\[cmd=\d+,\s*len=\d,\s*con='.+',\s*status=.+\]/
17
+ end
18
+
19
+ end
@@ -0,0 +1,75 @@
1
+ require File.dirname(__FILE__)+"/spec_helper.rb"
2
+
3
+ describe Rserve::Protocol do
4
+ before do
5
+ @t=Object.new
6
+ @t.extend Rserve::Protocol
7
+ end
8
+ it "set_int method should set an integer correctly on an array of bytes" do
9
+ bytes=[0,0,0,0,0,0,0]
10
+ v=1000
11
+ @t.set_int(v, bytes, 2)
12
+ bytes.should==[0,0,232,3,0,0,0]
13
+ end
14
+ it "set_hdr method should set correctly the header for len<0xFFFFFF" do
15
+ bytes=[0]*8
16
+ cmd=Rserve::Protocol::CMD_login
17
+ len=0x123456
18
+ offset=0
19
+ expected=[cmd,0x56,0x34,0x12,0,0,0,0]
20
+
21
+ @t.set_hdr(cmd,len,bytes,offset)
22
+
23
+ bytes.should==expected
24
+ end
25
+ it "set_hdr method should set correctly the header for len>0xFFFFFF" do
26
+ bytes=[0]*8
27
+ cmd=Rserve::Protocol::CMD_login
28
+ len=0x12345678
29
+ offset=0
30
+ expected=[cmd|Rserve::Protocol::DT_LARGE,0x78,0x56,0x34,0x12,0,0,0]
31
+ @t.set_hdr(cmd,len,bytes,offset)
32
+ bytes.should==expected
33
+ end
34
+ it "new_hdr method should return a correct header for different lengths" do
35
+ cmd=Rserve::Protocol::CMD_login
36
+ len=0x123456
37
+ expected=[cmd,0x56,0x34,0x12]
38
+ @t.new_hdr(cmd,len).should==expected
39
+ len=0x12345678
40
+ expected=[cmd|Rserve::Protocol::DT_LARGE,0x78,0x56,0x34,0x12,0,0,0]
41
+ @t.new_hdr(cmd,len).should==expected
42
+ end
43
+ it "get_int method should return a correct integer for a given buffer" do
44
+ buffer=[0xFF,0x78,0x56,0x34,0x12]
45
+ expected=0x12345678
46
+ @t.get_int(buffer,1).should==expected
47
+
48
+ # Version with errors
49
+
50
+ buffer=[0xFF,0xFF78,0xFF56,0xFF34,0xFF12]
51
+ expected=0x12345678
52
+ @t.get_int(buffer,1).should==expected
53
+ end
54
+ it "get_len method should return correct length from a header" do
55
+ cmd=Rserve::Protocol::CMD_login
56
+ len=0x12345678
57
+ header=@t.new_hdr(cmd,len)
58
+ @t.get_len(header,0).should==len
59
+ end
60
+ it "get_long method should return correct long(32 bits) for a given buffer" do
61
+ buffer=[0xFF,0x78,0x56,0x34,0x12,0x78,0x56,0x34,0x12]
62
+ expected=0x1234567812345678
63
+ @t.get_long(buffer,1).should==expected
64
+
65
+ end
66
+ it "set_long method should set correct long(32 bits) for a given buffer" do
67
+ buffer=[0]*9
68
+ long=0x123456789ABCDF45
69
+
70
+ @t.set_long(long,buffer,1)
71
+ expected=[0x45,0xDF,0xBC,0x9A,0x78,0x56,0x34,0x12]
72
+ buffer.slice(1,8).should==expected
73
+ end
74
+
75
+ end
@@ -0,0 +1,44 @@
1
+ # encoding: UTF-8
2
+
3
+ require File.dirname(__FILE__)+"/spec_helper.rb"
4
+
5
+ describe Rserve::Protocol::REXPFactory do
6
+ before do
7
+ @r=Rserve::Connection.new
8
+ end
9
+ it "should process single logical" do
10
+ la=@r.eval("TRUE")
11
+ la.should be_instance_of(Rserve::REXP::Logical)
12
+ la.true?.should==[true]
13
+ end
14
+ it "should process logical vector" do
15
+ la=@r.eval("c(TRUE,FALSE,TRUE)")
16
+ la.should be_instance_of(Rserve::REXP::Logical)
17
+ la.true?.should==[true,false,true]
18
+ end
19
+ it "should process single double" do
20
+ la=@r.eval("1.5")
21
+ la.should be_instance_of(Rserve::REXP::Double)
22
+ la.as_doubles.should==[1.5]
23
+ end
24
+ it "should process double vector" do
25
+ a=100.times.map{|i| rand()}
26
+ la=@r.eval("c("+a.map(&:to_s).join(",")+")")
27
+ la.should be_instance_of(Rserve::REXP::Double)
28
+
29
+ la.as_doubles.map(&:to_f).each_with_index {|v,i|
30
+ v.should be_close(a[i],1e-10)
31
+ }
32
+ end
33
+ it "should process char" do
34
+ la=@r.eval("c('abc','def','ghi')")
35
+ la.should be_instance_of(Rserve::REXP::String)
36
+ la.as_strings.should==['abc','def','ghi']
37
+ end
38
+ it "should process list" do
39
+ require 'pp'
40
+ la=@r.eval("list(name='Fred', wife='Mary', no.children=3, child.ages=c(4,7,9))")
41
+ pp la
42
+ end
43
+
44
+ end
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__)+"/spec_helper.rb"
2
+
3
+ describe Rserve do
4
+ before do
5
+ @r=Rserve::Connection.new()
6
+ end
7
+ it "should receive a valid response to valid expression" do
8
+ #response=@r.send(Rserve::CMD_eval, @r.string("1:5"))
9
+ #p response
10
+ #response[:response].should==Rserve::RESP_OK
11
+ end
12
+ it "should receive error on invalid expression" do
13
+ #response=@r.send(Rserve::CMD_eval, @r.string("a|sdsds<-||#@r3"))
14
+ #p response
15
+ #response[:response].should==Rserve::RESP_ERR
16
+ end
17
+
18
+ end
@@ -0,0 +1,73 @@
1
+ require File.dirname(__FILE__)+"/spec_helper.rb"
2
+
3
+ describe Rserve::Talk do
4
+ before do
5
+ @iomock=mock('IO Mock')
6
+ @talk=Rserve::Talk.new(@iomock)
7
+ end
8
+ it "method request_string should return a valid string" do
9
+ par="x<-12".unpack("C*")
10
+ buf=[0]*13
11
+ @talk.set_hdr(Rserve::Protocol::DT_STRING,8,buf,0)
12
+ par.each_index {|i| buf[i+4]=par[i]}
13
+ @talk.request_string("x<-12").should==buf
14
+ end
15
+ it "should raise an error on incorrect type of cont" do
16
+ ty=Rserve::Protocol::CMD_shutdown
17
+ lambda {
18
+ @talk.request(:cmd=>ty, :cont=>"no")
19
+ }.should raise_exception()
20
+
21
+ end
22
+ it "should behave correctly with cmd as only argument" do
23
+ ty=Rserve::Protocol::CMD_shutdown
24
+ buf=[0]*16
25
+ @talk.set_int(ty, buf, 0)
26
+ @talk.set_int(0, buf, 4)
27
+ rep=Rserve::Protocol::RESP_OK
28
+ cont="Test content"
29
+ cl=cont.length
30
+ server_response_1=[rep,cl,0,0].pack("IIII")
31
+ server_response_2=cont
32
+
33
+ @iomock.should_receive(:write).once.with(buf.pack("C*"))
34
+ @iomock.should_receive(:recv).once.with(16).and_return(server_response_1)
35
+ @iomock.should_receive(:recv).once.with(cl).and_return(server_response_2)
36
+
37
+ ret=@talk.request(:cmd=>ty)
38
+ ret.should be_instance_of(Rserve::Packet)
39
+ ret.cmd.should==rep
40
+ ret.cont_len.should==cl
41
+ ret.cont.should==cont.unpack("C*")
42
+ end
43
+ it "should behave correctly with cmd and cont as arguments" do
44
+
45
+
46
+ ty=Rserve::Protocol::CMD_eval
47
+ buf=[0]*16
48
+
49
+ es="x<-1020"
50
+ es_proc=@talk.request_string(es).pack("C*")
51
+ es_len=es_proc.size
52
+ @talk.set_int(ty, buf, 0)
53
+ @talk.set_int(es_len, buf, 4)
54
+ rep=Rserve::Protocol::RESP_OK
55
+ cont=es+"(Response)"
56
+ cl=cont.length
57
+ server_response_1=[rep,cl,0,0].pack("IIII")
58
+ server_response_2=cont
59
+ @iomock.should_receive(:write).once.with(buf.pack("C*"))
60
+ @iomock.should_receive(:write).once.with(es_proc)
61
+
62
+ @iomock.should_receive(:recv).once.with(16).and_return(server_response_1)
63
+ @iomock.should_receive(:recv).once.with(cl).and_return(server_response_2)
64
+
65
+ ret=@talk.request(:cmd=>ty,:cont=>es)
66
+
67
+ ret.should be_instance_of(Rserve::Packet)
68
+ ret.cmd.should==rep
69
+ ret.cont_len.should==cl
70
+ ret.cont.should==cont.unpack("C*")
71
+ end
72
+
73
+ end
@@ -0,0 +1,3 @@
1
+ --color
2
+ -f s
3
+ -b
@@ -0,0 +1,4 @@
1
+ $:.unshift(File.dirname(__FILE__)+"/../lib")
2
+ require 'spec'
3
+ require 'spec/autorun'
4
+ require 'rserve'
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rserve-client
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Claudio Bustos
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain:
16
+ - |
17
+ -----BEGIN CERTIFICATE-----
18
+ MIIDMjCCAhqgAwIBAgIBADANBgkqhkiG9w0BAQUFADA/MREwDwYDVQQDDAhjbGJ1
19
+ c3RvczEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
20
+ MB4XDTEwMDMyOTIxMzg1NVoXDTExMDMyOTIxMzg1NVowPzERMA8GA1UEAwwIY2xi
21
+ dXN0b3MxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
22
+ bTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALf8JVMGqE7m5kYb+PNN
23
+ neZv2pcXV5fQCi6xkyG8bi2/SIFy/LyxuvLzEeOxBeaz1Be93bayIUquOIqw3dyw
24
+ /KXWa31FxuNuvAm6CN8fyeRYX/ou4cw3OIUUnIvB7RMNIu4wbgeM6htV/QEsNLrv
25
+ at1/mh9JpqawPrcjIOVMj4BIp67vmzJCaUf+S/H2uYtSO09F+YQE3tv85TPeRmqU
26
+ yjyXyTc/oJiw1cXskUL8UtMWZmrwNLHXuZWWIMzkjiz3UNdhJr/t5ROk8S2WPznl
27
+ 0bMy/PMIlAbqWolRn1zl2VFJ3TaXScbqImY8Wf4g62b/1ZSUlGrtnLNsCYXrWiso
28
+ UPUCAwEAAaM5MDcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFGu9
29
+ rrJ1H64qRmNNu3Jj/Qjvh0u5MA0GCSqGSIb3DQEBBQUAA4IBAQCV0Unka5isrhZk
30
+ GjqSDqY/6hF+G2pbFcbWUpjmC8NWtAxeC+7NGV3ljd0e1SLfoyBj4gnFtFmY8qX4
31
+ K02tgSZM0eDV8TpgFpWXzK6LzHvoanuahHLZEtk/+Z885lFene+nHadkem1n9iAB
32
+ cs96JO9/JfFyuXM27wFAwmfHCmJfPF09R4VvGHRAvb8MGzSVgk2i06OJTqkBTwvv
33
+ JHJdoyw3+8bw9RJ+jLaNoQ+xu+1pQdS2bb3m7xjZpufml/m8zFCtjYM/7qgkKR8z
34
+ /ZZt8lCiKfFArppRrZayE2FVsps4X6WwBdrKTMZ0CKSXTRctbEj1BAZ67eoTvBBt
35
+ rpP0jjs0
36
+ -----END CERTIFICATE-----
37
+
38
+ date: 2010-05-21 00:00:00 -04:00
39
+ default_executable:
40
+ dependencies:
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubyforge
43
+ prerelease: false
44
+ requirement: &id001 !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ segments:
49
+ - 2
50
+ - 0
51
+ - 4
52
+ version: 2.0.4
53
+ type: :development
54
+ version_requirements: *id001
55
+ - !ruby/object:Gem::Dependency
56
+ name: hoe
57
+ prerelease: false
58
+ requirement: &id002 !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ segments:
63
+ - 2
64
+ - 6
65
+ - 0
66
+ version: 2.6.0
67
+ type: :development
68
+ version_requirements: *id002
69
+ description: |-
70
+ Ruby client for Rserve, a Binary R server (http://www.rforge.net/Rserve/).
71
+
72
+ Follows closely the new Java client API, but maintains all Ruby conventions when possible.
73
+
74
+ Connection to Rserve not yet developed, but between June-July 2010 the system should be operational.
75
+ email:
76
+ - clbustos_AT_gmail.com
77
+ executables: []
78
+
79
+ extensions: []
80
+
81
+ extra_rdoc_files:
82
+ - History.txt
83
+ - Manifest.txt
84
+ - README.txt
85
+ files:
86
+ - History.txt
87
+ - Manifest.txt
88
+ - README.txt
89
+ - Rakefile
90
+ - lib/rserve.rb
91
+ - lib/rserve/connection.rb
92
+ - lib/rserve/engine.rb
93
+ - lib/rserve/packet.rb
94
+ - lib/rserve/protocol.rb
95
+ - lib/rserve/protocol/rexpfactory.rb
96
+ - lib/rserve/rexp.rb
97
+ - lib/rserve/rexp/double.rb
98
+ - lib/rserve/rexp/genericvector.rb
99
+ - lib/rserve/rexp/integer.rb
100
+ - lib/rserve/rexp/list.rb
101
+ - lib/rserve/rexp/logical.rb
102
+ - lib/rserve/rexp/string.rb
103
+ - lib/rserve/rexp/symbol.rb
104
+ - lib/rserve/rexp/vector.rb
105
+ - lib/rserve/rlist.rb
106
+ - lib/rserve/talk.rb
107
+ - spec/rserve_connection_spec.rb
108
+ - spec/rserve_double_spec.rb
109
+ - spec/rserve_integer_spec.rb
110
+ - spec/rserve_packet_spec.rb
111
+ - spec/rserve_protocol_spec.rb
112
+ - spec/rserve_rexpfactory_spec.rb
113
+ - spec/rserve_spec.rb
114
+ - spec/rserve_talk_spec.rb
115
+ - spec/spec.opts
116
+ - spec/spec_helper.rb
117
+ has_rdoc: true
118
+ homepage: http://github.com/clbustos/Rserve-Ruby-client
119
+ licenses: []
120
+
121
+ post_install_message:
122
+ rdoc_options:
123
+ - --main
124
+ - README.txt
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ segments:
132
+ - 0
133
+ version: "0"
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ segments:
139
+ - 0
140
+ version: "0"
141
+ requirements: []
142
+
143
+ rubyforge_project: ruby-statsample
144
+ rubygems_version: 1.3.6
145
+ signing_key:
146
+ specification_version: 3
147
+ summary: Ruby client for Rserve, a Binary R server (http://www.rforge.net/Rserve/)
148
+ test_files: []
149
+