Skip to content

Commit 91664cc

Browse files
committed
add tests for destructive methods in Dataset and Datablock
1 parent 5ed7d9d commit 91664cc

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

spec/dataset_spec.rb

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
require 'spec_helper.rb'
22

33
describe Dataset do
4+
before(:all) do
5+
@tmp_dir = File.join('spec', 'tmp')
6+
Dir.mkdir(@tmp_dir)
7+
@datafile_path = File.join('spec', 'points.data')
8+
end
9+
10+
after(:all) do
11+
FileUtils.rm_r(@tmp_dir)
12+
end
13+
414
context 'creation' do
515
before do
616
x = (0..10).to_a
@@ -165,4 +175,54 @@
165175
expect(size_after_update).to be > size_before_update
166176
end
167177
end
178+
179+
context 'destructive update' do
180+
before :each do
181+
x = (0..10).to_a
182+
y = x.map { |xx| Math.exp(-xx) }
183+
@data = [x, y]
184+
@ds = Dataset.new(@data)
185+
@ds_file = Dataset.new(@data, file: true)
186+
end
187+
188+
it 'should update an option of existing object' do
189+
@ds.lw!(3)
190+
expect(@ds.lw).to eql(3)
191+
@ds.pt = 8
192+
expect(@ds.pt).to eql(8)
193+
end
194+
195+
it 'should update several options of existing object at once via #options!' do
196+
@ds.options!(lw: 3, pt: 8)
197+
expect(@ds.lw).to eql(3)
198+
expect(@ds.pt).to eql(8)
199+
end
200+
201+
it 'should update several options of existing object at once via #update!' do
202+
@ds.update!(lw: 3, pt: 8)
203+
expect(@ds.lw).to eql(3)
204+
expect(@ds.pt).to eql(8)
205+
end
206+
207+
it 'should update data of existing in-memory datablock at once' do
208+
paths = (0..1).map { |i| File.join(@tmp_dir, "#{i}plot.png") }
209+
options0 = { term: ['png', size: [300, 300]], output: paths[0] }
210+
options1 = { term: ['png', size: [300, 300]], output: paths[1] }
211+
x1 = (11..15).to_a
212+
y1 = x1.map { |xx| Math.exp(-xx) }
213+
@ds.plot(options0)
214+
@ds.update!([x1, y1])
215+
@ds.plot(options1)
216+
expect(same_images?(*paths)).to be_falsey
217+
end
218+
219+
it 'should update data of existing in-file datablock at once' do
220+
x1 = (11..15).to_a
221+
y1 = x1.map { |xx| Math.exp(-xx) }
222+
size_before = File.size(@ds_file.data.to_s[1..-2])
223+
@ds_file.update!([x1, y1])
224+
size_after = File.size(@ds_file.data.to_s[1..-2])
225+
expect(size_after).to be > size_before
226+
end
227+
end
168228
end

0 commit comments

Comments
 (0)