test/driver/native/test_conversions.rb in octave-ruby-1.0.2 vs test/driver/native/test_conversions.rb in octave-ruby-1.0.3
- old
+ new
@@ -2,10 +2,11 @@
require 'test/unit'
require 'octave'
require 'octave/driver/native/driver'
require 'rubygems'
require 'mocha'
+require 'yaml'
class ConversionsTest < Test::Unit::TestCase
def setup
@driver = Octave::Driver::Native::Driver.new
@driver.feval "eval", "function r = to_octave(val); r = val; endfunction"
@@ -55,11 +56,11 @@
def test_should_convert_hash
assert_octave_and_ruby_equal "foo" => "bar"
assert_octave_and_ruby_equal "foo" => [1,2,3]
assert_octave_and_ruby_equal "foo" => { "bar" => [1,2,3, [4,5,6]] }
- assert_octave_and_ruby_equal "foo" => { "bar" => [1,2,3, [4,5,6]], "baz" => "buz" }
+ assert_octave_and_ruby_equal "foo" => { "bar" => [1,2,3, [4,5,6]], "baz" => "buz", "bob" => [7,8,9] }
end
def test_should_convert_octave_matrix
matrix = Octave::Matrix.new(3, 3)
3.times { |m| 3.times { |n| matrix[m, n] = rand } }
@@ -151,6 +152,30 @@
cell_matrix[1,0] = "bar"
cell_matrix[2,0] = "baz"
assert_equal %w(foo bar baz), to_octave_to_ruby(cell_matrix)
end
-end
\ No newline at end of file
+
+ def test_hmm
+ struct_matrix = Octave::StructMatrix.new(17, 2, "name", "age", "married", "cats", "car")
+ 17.times do |m|
+ 2.times do |n|
+ struct_matrix[m, n]["name"] = "Bob #{m}.#{n}"
+ struct_matrix[m, n]["age"] = (rand * 100).to_i
+ struct_matrix[m, n]["married"] = (rand > 0.5)
+ struct_matrix[m, n]["cats"] = { "name" => "Kitty #{m}.#{n}" }
+ struct_matrix[m, n]["car"] = nil
+ end
+ end
+
+ data = {
+ "foo" => struct_matrix,
+ "bar" => [1,2,3,4],
+ "baz" => struct_matrix
+ }
+
+ @driver.put_variable "data", data
+ @driver.feval "save", "-V7", "/tmp/hmm.mat", "data"
+ # assert_octave_and_ruby_equal data
+
+ end
+end