spec/io_spec.rb in nmatrix-0.0.9 vs spec/io_spec.rb in nmatrix-0.1.0.rc1
- old
+ new
@@ -6,12 +6,12 @@
# NMatrix was originally inspired by and derived from NArray, by
# Masahiro Tanaka: http://narray.rubyforge.org
#
# == Copyright Information
#
-# SciRuby is Copyright (c) 2010 - 2012, Ruby Science Foundation
-# NMatrix is Copyright (c) 2012, Ruby Science Foundation
+# SciRuby is Copyright (c) 2010 - 2014, Ruby Science Foundation
+# NMatrix is Copyright (c) 2012 - 2014, John Woods and the Ruby Science Foundation
#
# Please see LICENSE.txt for additional copyright notices.
#
# == Contributing
#
@@ -22,13 +22,25 @@
#
# == io_spec.rb
#
# Basic tests for NMatrix::IO.
#
+require "tmpdir" # Used to avoid cluttering the repository.
+
require "./lib/nmatrix"
describe NMatrix::IO do
+ before :each do
+ @tmp_dir = Dir.mktmpdir
+ @test_out = File.join(@tmp_dir, "test-out")
+ end
+
+ after :each do
+ File.delete(@test_out) if File.file?(@test_out)
+ Dir.rmdir(@tmp_dir)
+ end
+
it "repacks a string" do
NMatrix::IO::Matlab.repack("hello", :miUINT8, :byte).should == "hello"
end
it "creates yale from internal byte-string function" do
@@ -81,59 +93,57 @@
expect{ NMatrix.read(fn) }.to raise_error(Errno::ENOENT)
end
it "reads and writes NMatrix dense" do
n = NMatrix.new(:dense, [4,3], [0,1,2,3,4,5,6,7,8,9,10,11], :int32)
- n.write("test-out")
+ n.write(@test_out)
- m = NMatrix.read("test-out")
+ m = NMatrix.read(@test_out)
n.should == m
end
it "reads and writes NMatrix dense as symmetric" do
n = NMatrix.new(:dense, 3, [0,1,2,1,3,4,2,4,5], :int16)
- n.write("test-out", :symmetric)
+ n.write(@test_out, :symmetric)
- m = NMatrix.read("test-out")
+ m = NMatrix.read(@test_out)
n.should == m
end
it "reads and writes NMatrix dense as skew" do
n = NMatrix.new(:dense, 3, [0,1,2,-1,3,4,-2,-4,5], :float64)
- n.write("test-out", :skew)
+ n.write(@test_out, :skew)
- m = NMatrix.read("test-out")
+ m = NMatrix.read(@test_out)
n.should == m
end
it "reads and writes NMatrix dense as hermitian" do
n = NMatrix.new(:dense, 3, [0,1,2,1,3,4,2,4,5], :complex64)
- n.write("test-out", :hermitian)
+ n.write(@test_out, :hermitian)
- m = NMatrix.read("test-out")
+ m = NMatrix.read(@test_out)
n.should == m
end
it "reads and writes NMatrix dense as upper" do
n = NMatrix.new(:dense, 3, [-1,1,2,3,4,5,6,7,8], :int32)
- n.write("test-out", :upper)
+ n.write(@test_out, :upper)
m = NMatrix.new(:dense, 3, [-1,1,2,0,4,5,0,0,8], :int32) # lower version of the same
- o = NMatrix.read("test-out")
+ o = NMatrix.read(@test_out)
o.should == m
o.should_not == n
end
it "reads and writes NMatrix dense as lower" do
n = NMatrix.new(:dense, 3, [-1,1,2,3,4,5,6,7,8], :int32)
- n.write("test-out", :lower)
+ n.write(@test_out, :lower)
m = NMatrix.new(:dense, 3, [-1,0,0,3,4,0,6,7,8], :int32) # lower version of the same
- o = NMatrix.read("test-out")
+ o = NMatrix.read(@test_out)
o.should == m
o.should_not == n
end
-
-
-end
\ No newline at end of file
+end