Skip to content

Commit 82c4eb8

Browse files
committed
Add histogram spec
1 parent 7c6ebdf commit 82c4eb8

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

spec/integration/histtest_spec.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
describe "Histogram Plot Example" do
2+
let(:file_path) { 'spec/tmp/histogram_plot.eps' }
3+
let(:fixture_path) { 'spec/fixtures/plots/histogram_plot.eps' }
4+
5+
let(:file_content) do
6+
File.read(file_path).gsub(/CreationDate.*/, "")
7+
end
8+
9+
let(:fixture_content) do
10+
File.read(fixture_path).gsub(/CreationDate.*/, "")
11+
end
12+
13+
before do
14+
path = file_path
15+
collection = (0..500).collect do |_v|
16+
(rand()-0.5)**3
17+
end
18+
19+
Gnuplot.open do |gp|
20+
gp << "bin(x, s) = s*int(x/s)\n"
21+
22+
Gnuplot::Plot.new( gp ) do |plot|
23+
plot.title "Histogram"
24+
plot.xlabel "x"
25+
plot.ylabel "frequency"
26+
27+
plot.data << Gnuplot::DataSet.new( [collection] ) do |ds|
28+
ds.title = "smooth frequency"
29+
ds.using = "(bin($1,.01)):(1.)"
30+
ds.smooth = "freq"
31+
ds.with = "boxes"
32+
end
33+
34+
plot.term "postscript eps"
35+
plot.output path
36+
end
37+
end
38+
39+
end
40+
41+
after do
42+
File.delete(file_path)
43+
end
44+
45+
it "plots expected file" do
46+
expect(file_content).to eq(fixture_content)
47+
end
48+
end

0 commit comments

Comments
 (0)