octave-ruby 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/LICENSE.txt +674 -0
- data/Manifest.txt +36 -0
- data/README.txt +58 -0
- data/Rakefile +18 -0
- data/ext/octave_api/MANIFEST +4 -0
- data/ext/octave_api/Makefile +149 -0
- data/ext/octave_api/extconf.rb +24 -0
- data/ext/octave_api/octave-includes.h +11 -0
- data/ext/octave_api/octave-ruby.cpp +62 -0
- data/ext/octave_api/octave-ruby.h +18 -0
- data/ext/octave_api/octave_api.c +22 -0
- data/ext/octave_api/octave_api.h +13 -0
- data/ext/octave_api/or-array.cpp +56 -0
- data/ext/octave_api/or-array.h +20 -0
- data/ext/octave_api/or-cell_matrix.cpp +68 -0
- data/ext/octave_api/or-cell_matrix.h +22 -0
- data/ext/octave_api/or-hash.cpp +23 -0
- data/ext/octave_api/or-hash.h +19 -0
- data/ext/octave_api/or-matrix.cpp +89 -0
- data/ext/octave_api/or-matrix.h +22 -0
- data/ext/octave_api/or-string.cpp +13 -0
- data/ext/octave_api/or-string.h +22 -0
- data/ext/octave_api/or-struct_matrix.cpp +83 -0
- data/ext/octave_api/or-struct_matrix.h +22 -0
- data/ext/octave_api/or-variable.cpp +55 -0
- data/ext/octave_api/or-variable.h +22 -0
- data/lib/octave.rb +5 -0
- data/lib/octave/driver/native/driver.rb +26 -0
- data/lib/octave/engine.rb +67 -0
- data/lib/octave/matrix.rb +84 -0
- data/lib/octave/version.rb +14 -0
- data/setup.rb +1333 -0
- data/test/driver/native/test_conversions.rb +158 -0
- data/test/driver/native/test_driver.rb +32 -0
- data/test/test_engine.rb +50 -0
- metadata +104 -0
@@ -0,0 +1,158 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__) + "/../../../lib"
|
2
|
+
require 'test/unit'
|
3
|
+
require 'octave'
|
4
|
+
require 'octave/driver/native/driver'
|
5
|
+
require 'rubygems'
|
6
|
+
require 'mocha'
|
7
|
+
|
8
|
+
class ConversionsTest < Test::Unit::TestCase
|
9
|
+
def setup
|
10
|
+
@driver = Octave::Driver::Native::Driver.new
|
11
|
+
@driver.feval "eval", "function r = to_octave(val); r = val; endfunction"
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_octave_to_ruby(value)
|
15
|
+
@driver.feval "to_octave", value
|
16
|
+
end
|
17
|
+
|
18
|
+
def assert_octave_and_ruby_equal(value)
|
19
|
+
result = to_octave_to_ruby(value)
|
20
|
+
assert_equal value, result
|
21
|
+
assert_equal value.class, result.class
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_should_convert_string
|
25
|
+
assert_octave_and_ruby_equal "foo"
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_should_convert_true
|
29
|
+
assert_octave_and_ruby_equal true
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_should_convert_false
|
33
|
+
assert_octave_and_ruby_equal false
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_should_convert_nil
|
37
|
+
assert_octave_and_ruby_equal nil
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_should_convert_float
|
41
|
+
assert_octave_and_ruby_equal 12.345
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_should_convert_fixnum
|
45
|
+
# Fixnums are sent to and returned from Octave as Float
|
46
|
+
result = to_octave_to_ruby(12345)
|
47
|
+
assert_equal 12345.0, result
|
48
|
+
assert_instance_of Float, result
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_should_convert_array
|
52
|
+
assert_octave_and_ruby_equal [1, nil, 3.0]
|
53
|
+
assert_octave_and_ruby_equal [1, "2", false, ["foo", "bar", "baz"]]
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_should_convert_hash
|
57
|
+
assert_octave_and_ruby_equal "foo" => "bar"
|
58
|
+
assert_octave_and_ruby_equal "foo" => [1,2,3]
|
59
|
+
assert_octave_and_ruby_equal "foo" => { "bar" => [1,2,3, [4,5,6]] }
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_should_convert_octave_matrix
|
63
|
+
matrix = Octave::Matrix.new(3, 3)
|
64
|
+
3.times { |m| 3.times { |n| matrix[m, n] = rand } }
|
65
|
+
matrix[1, 1] = nil
|
66
|
+
|
67
|
+
assert_octave_and_ruby_equal matrix
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_should_convert_a_1xn_octave_matrix_to_an_array
|
71
|
+
matrix = Octave::Matrix.new(1, 3)
|
72
|
+
matrix[0, 0] = 1
|
73
|
+
matrix[0, 1] = 2
|
74
|
+
matrix[0, 2] = 3
|
75
|
+
|
76
|
+
expected_array = [1,2,3]
|
77
|
+
result = to_octave_to_ruby(matrix)
|
78
|
+
|
79
|
+
assert_equal expected_array, result
|
80
|
+
assert_instance_of Array, result
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_should_convert_an_nx1_octave_matrix_to_an_array
|
84
|
+
matrix = Octave::Matrix.new(3, 1)
|
85
|
+
matrix[0, 0] = 1
|
86
|
+
matrix[1, 0] = 2
|
87
|
+
matrix[2, 0] = 3
|
88
|
+
|
89
|
+
expected_array = [1,2,3]
|
90
|
+
result = to_octave_to_ruby(matrix)
|
91
|
+
|
92
|
+
assert_equal expected_array, result
|
93
|
+
assert_instance_of Array, result
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_should_convert_octave_struct_matrix
|
97
|
+
cats = Octave::StructMatrix.new(17, 1, "name")
|
98
|
+
17.times { |m| 1.times { |n| cats[m, n]["name"] = "Kitty #{m}.#{n}" } }
|
99
|
+
|
100
|
+
struct_matrix = Octave::StructMatrix.new(17, 1, "name", "age", "married", "cats", "car")
|
101
|
+
17.times do |m|
|
102
|
+
1.times do |n|
|
103
|
+
struct_matrix[m, n]["name"] = "Bob #{m}.#{n}"
|
104
|
+
struct_matrix[m, n]["age"] = (rand * 100).to_i
|
105
|
+
struct_matrix[m, n]["married"] = (rand > 0.5)
|
106
|
+
struct_matrix[m, n]["cats"] = cats
|
107
|
+
struct_matrix[m, n]["car"] = nil
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
assert_octave_and_ruby_equal struct_matrix
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_should_convert_a_1x1_struct_matrix_to_a_hash
|
115
|
+
struct_matrix = Octave::StructMatrix.new(1, 1, "foo")
|
116
|
+
struct_matrix[0,0]["foo"] = { "bar" => [1,2,3] }
|
117
|
+
|
118
|
+
expected_hash = { "foo" => { "bar" => [1,2,3] } }
|
119
|
+
result = to_octave_to_ruby(struct_matrix)
|
120
|
+
|
121
|
+
assert_equal expected_hash, result
|
122
|
+
assert_instance_of Hash, result
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_should_convert_octave_cell_matrix
|
126
|
+
cell_matrix = Octave::CellMatrix.new(3, 3)
|
127
|
+
cell_matrix[0, 0] = 1
|
128
|
+
cell_matrix[1, 0] = "2"
|
129
|
+
cell_matrix[2, 0] = false
|
130
|
+
|
131
|
+
assert_octave_and_ruby_equal cell_matrix
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_should_convert_a_1x1_cell_matrix_to_value
|
135
|
+
cell_matrix = Octave::CellMatrix.new(1, 1)
|
136
|
+
cell_matrix[0,0] = [1, 2, 3]
|
137
|
+
|
138
|
+
assert_equal [1, 2, 3], to_octave_to_ruby(cell_matrix)
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_should_convert_a_1xn_cell_matrix_to_an_array
|
142
|
+
cell_matrix = Octave::CellMatrix.new(1, 3)
|
143
|
+
cell_matrix[0,0] = "foo"
|
144
|
+
cell_matrix[0,1] = "bar"
|
145
|
+
cell_matrix[0,2] = "baz"
|
146
|
+
|
147
|
+
assert_equal %w(foo bar baz), to_octave_to_ruby(cell_matrix)
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_should_convert_a_nx1_cell_matrix_to_an_array
|
151
|
+
cell_matrix = Octave::CellMatrix.new(3, 1)
|
152
|
+
cell_matrix[0,0] = "foo"
|
153
|
+
cell_matrix[1,0] = "bar"
|
154
|
+
cell_matrix[2,0] = "baz"
|
155
|
+
|
156
|
+
assert_equal %w(foo bar baz), to_octave_to_ruby(cell_matrix)
|
157
|
+
end
|
158
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
$:.unshift "../../../lib"
|
2
|
+
require 'test/unit'
|
3
|
+
require 'octave'
|
4
|
+
require 'octave/driver/native/driver'
|
5
|
+
require 'rubygems'
|
6
|
+
require 'mocha'
|
7
|
+
|
8
|
+
class DriverTest < Test::Unit::TestCase
|
9
|
+
include Octave::Driver::Native
|
10
|
+
|
11
|
+
def setup
|
12
|
+
@driver = Driver.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_feval
|
16
|
+
API.expects(:feval).with("some_function_name", ["argument 1", "argument 2"])
|
17
|
+
@driver.feval("some_function_name", "argument 1", "argument 2")
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_put_and_get_variable
|
21
|
+
assert_equal "some_value", @driver.put_variable("some_variable_name", "some_value")
|
22
|
+
assert_equal "some_value", @driver.get_variable("some_variable_name")
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_putting_variable_with_same_name_multiple_times
|
26
|
+
assert_equal "foo", @driver.put_variable("some_variable_name", "foo")
|
27
|
+
assert_equal "bar", @driver.put_variable("some_variable_name", "bar")
|
28
|
+
assert_equal "baz", @driver.put_variable("some_variable_name", "baz")
|
29
|
+
|
30
|
+
assert_equal "baz", @driver.get_variable("some_variable_name")
|
31
|
+
end
|
32
|
+
end
|
data/test/test_engine.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'octave'
|
3
|
+
require 'octave/engine'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'mocha'
|
6
|
+
|
7
|
+
class Driver
|
8
|
+
end
|
9
|
+
|
10
|
+
class EngineTest_Init < Test::Unit::TestCase
|
11
|
+
def test_new
|
12
|
+
driver = mock()
|
13
|
+
Driver.expects(:new).returns(driver)
|
14
|
+
|
15
|
+
engine = Octave::Engine.new(:driver => Driver)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_new_with_invalid_driver
|
19
|
+
exception = assert_raise(LoadError) do
|
20
|
+
engine = Octave::Engine.new(:driver => "foo")
|
21
|
+
end
|
22
|
+
assert_equal "no such file to load -- octave/driver/foo/driver", exception.message
|
23
|
+
|
24
|
+
exception = assert_raise(LoadError) do
|
25
|
+
engine = Octave::Engine.new(:driver => :bar)
|
26
|
+
end
|
27
|
+
assert_equal "no such file to load -- octave/driver/bar/driver", exception.message
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_new_with_native_driver
|
31
|
+
assert_nothing_raised do
|
32
|
+
engine = Octave::Engine.new
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class EngineTest < Test::Unit::TestCase
|
38
|
+
def setup
|
39
|
+
@driver = mock()
|
40
|
+
@handle = mock()
|
41
|
+
Driver.expects(:new).returns(@driver)
|
42
|
+
|
43
|
+
@engine = Octave::Engine.new(:driver => Driver)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_method_missing
|
47
|
+
@driver.expects(:feval).with("some_method_name", "argument 1", "argument 2")
|
48
|
+
@engine.some_method_name("argument 1", "argument 2")
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: octave-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonathan Younger
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-01-07 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.4.0
|
23
|
+
version:
|
24
|
+
description: "== USAGE: require 'octave' engine = Octave::Engine.new engine.eval \"123.456 * 789.101112\" engine.rand(10) matrix = Octave::Matrix.new(20, 400) 20.times { |m| 400.times { |n| matrix[m, n] = rand } } engine.put_variable(\"m\", matrix) engine.save \"/tmp/20_x_400_matrix\" == REQUIREMENTS: * Octave * GCC or some other compiler to build the included extension * Mocha (For testing only)"
|
25
|
+
email:
|
26
|
+
- jonathan.younger@lipomics.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions:
|
30
|
+
- ext/octave_api/extconf.rb
|
31
|
+
extra_rdoc_files:
|
32
|
+
- History.txt
|
33
|
+
- LICENSE.txt
|
34
|
+
- Manifest.txt
|
35
|
+
- README.txt
|
36
|
+
files:
|
37
|
+
- History.txt
|
38
|
+
- LICENSE.txt
|
39
|
+
- Manifest.txt
|
40
|
+
- README.txt
|
41
|
+
- Rakefile
|
42
|
+
- ext/octave_api/MANIFEST
|
43
|
+
- ext/octave_api/Makefile
|
44
|
+
- ext/octave_api/extconf.rb
|
45
|
+
- ext/octave_api/octave-includes.h
|
46
|
+
- ext/octave_api/octave-ruby.cpp
|
47
|
+
- ext/octave_api/octave-ruby.h
|
48
|
+
- ext/octave_api/octave_api.c
|
49
|
+
- ext/octave_api/octave_api.h
|
50
|
+
- ext/octave_api/or-array.cpp
|
51
|
+
- ext/octave_api/or-array.h
|
52
|
+
- ext/octave_api/or-cell_matrix.cpp
|
53
|
+
- ext/octave_api/or-cell_matrix.h
|
54
|
+
- ext/octave_api/or-hash.cpp
|
55
|
+
- ext/octave_api/or-hash.h
|
56
|
+
- ext/octave_api/or-matrix.cpp
|
57
|
+
- ext/octave_api/or-matrix.h
|
58
|
+
- ext/octave_api/or-string.cpp
|
59
|
+
- ext/octave_api/or-string.h
|
60
|
+
- ext/octave_api/or-struct_matrix.cpp
|
61
|
+
- ext/octave_api/or-struct_matrix.h
|
62
|
+
- ext/octave_api/or-variable.cpp
|
63
|
+
- ext/octave_api/or-variable.h
|
64
|
+
- lib/octave.rb
|
65
|
+
- lib/octave/driver/native/driver.rb
|
66
|
+
- lib/octave/engine.rb
|
67
|
+
- lib/octave/matrix.rb
|
68
|
+
- lib/octave/version.rb
|
69
|
+
- setup.rb
|
70
|
+
- test/driver/native/test_conversions.rb
|
71
|
+
- test/driver/native/test_driver.rb
|
72
|
+
- test/test_engine.rb
|
73
|
+
has_rdoc: true
|
74
|
+
homepage: http://octave-ruby.rubyforge.org/
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options:
|
77
|
+
- --main
|
78
|
+
- README.txt
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
- ext
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: "0"
|
87
|
+
version:
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: "0"
|
93
|
+
version:
|
94
|
+
requirements: []
|
95
|
+
|
96
|
+
rubyforge_project: octave-ruby
|
97
|
+
rubygems_version: 1.0.1
|
98
|
+
signing_key:
|
99
|
+
specification_version: 2
|
100
|
+
summary: A Ruby interface to the Octave interpreted language.
|
101
|
+
test_files:
|
102
|
+
- test/driver/native/test_conversions.rb
|
103
|
+
- test/driver/native/test_driver.rb
|
104
|
+
- test/test_engine.rb
|