From 3e4619604ad6513805852645d4b514021c07ff6f Mon Sep 17 00:00:00 2001 From: Carlos Agarie Date: Thu, 19 Dec 2013 02:07:29 -0200 Subject: [PATCH] Test figure creation Simply creates a tree, trains it and produces a PNG figure, testing to confirm that no exception was raised and that the image is really there. --- spec/id3_spec.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/spec/id3_spec.rb b/spec/id3_spec.rb index 8c1eed6..a875904 100644 --- a/spec/id3_spec.rb +++ b/spec/id3_spec.rb @@ -103,4 +103,23 @@ describe describe DecisionTree::ID3Tree do lambda { tree.predict([1, 1]) }.should_not raise_error } end + + describe "create a figure" do + after(:all) do + File.delete("just_a_spec.png") if File.file?("just_a_spec.png") + end + + Given(:labels) { ["sun", "rain"]} + Given(:data) do + [ + [1,0,1], + [0,1,0] + ] + end + Given(:tree) { DecisionTree::ID3Tree.new(labels, data, 1, :discrete) } + When { tree.train } + When(:result) { tree.graph("just_a_spec") } + Then { expect(result).to_not have_failed } + And { File.file?("just_a_spec.png") } + end end