Skip to content

Commit ad45beb

Browse files
committed
add specs for Multiplot destructive update
1 parent 58abe53 commit ad45beb

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

spec/multiplot_spec.rb

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
end
5656
end
5757

58-
context 'handling plots as container' do
58+
context 'safe plot array update' do
5959
before :each do
6060
@sinx = Plot.new('sin(x)')
6161
@plot3d = Splot.new('sin(x)*cos(y)')
@@ -122,4 +122,50 @@
122122
expect(mp[0..-1]).to be_eql(mp.plots)
123123
end
124124
end
125+
126+
context 'destructive plot array update' do
127+
before :each do
128+
plots = [
129+
Plot.new('sin(x)'),
130+
Splot.new('sin(x)*cos(y)'),
131+
Plot.new('exp(x)')
132+
]
133+
@mp = Multiplot.new(*plots, layout: [1, 3])
134+
end
135+
136+
it 'should update plots in the existing Plot' do
137+
@mp.update!(0) do |plot|
138+
plot.options!(title: 'Updated plot')
139+
plot.replace_dataset!('exp(x)')
140+
plot[0].lw!(3)
141+
end
142+
expect(@mp[0].title).to eql('Updated plot')
143+
expect(@mp[0][0].data).to eql('exp(x)')
144+
expect(@mp[0][0].lw).to eql(3)
145+
end
146+
147+
it 'should replace plot in the existing Multiplot' do
148+
plot = Plot.new('cos(x)', title: 'Second plot')
149+
expect(@mp.replace!(1, plot)).to equal(@mp)
150+
expect(@mp[1].title).to eql('Second plot')
151+
@mp[0] = Plot.new('cos(x)', title: 'First plot')
152+
expect(@mp[0].title).to eql('First plot')
153+
end
154+
155+
it 'should add plots to the existing Multiplot' do
156+
plot = Plot.new('cos(x)', title: 'First plot')
157+
expect(@mp.add!(plot)).to equal(@mp)
158+
expect(@mp[0].title).to eql('First plot')
159+
expect(@mp.plots.size).to eql(4)
160+
end
161+
162+
it 'should remove plot from the existing Multiplot' do
163+
plot = Plot.new('cos(x)', title: 'Last plot')
164+
expect(@mp.add!(-1, plot)).to equal(@mp)
165+
expect(@mp.plots.size).to eql(4)
166+
expect(@mp.remove!).to equal(@mp)
167+
expect(@mp.plots.size).to eql(3)
168+
expect(@mp.plots.last.title).to eql('Last plot')
169+
end
170+
end
125171
end

0 commit comments

Comments
 (0)