spec/tree_spec.rb in SgfParser-1.0.0 vs spec/tree_spec.rb in SgfParser-2.0.0

- old
+ new

@@ -1,29 +1,36 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper') -describe "SgfParser::Tree" do +describe "SGF::Tree" do + before :each do + @tree = get_tree_from 'spec/data/ff4_ex.sgf' + end - it "should load a file properly" do - tree = SGF::Parser.new('spec/data/ff4_ex.sgf').parse - tree.class.should == SGF::Tree - tree.root.children.size.should == 2 - tree.root.children[0].children.size.should == 5 + it "should have two gametrees" do + @tree.games.size.should == 2 end - it "should save a simple tree properly" do - tree = SGF::Parser.new('spec/data/simple.sgf').parse - new_file = 'spec/data/simple_saved.sgf' - tree.save :filename => new_file - tree2 = SGF::Parser.new(new_file).parse - tree.should == tree2 + it "should have a decent inspect" do + inspect = @tree.inspect + inspect.should match /SGF::Tree/ + inspect.should match /#{@tree.object_id}/ + inspect.should match /2 Games/ + inspect.should match /62 Nodes/ end - it "should save the sample SGF properly" do - tree = SGF::Parser.new('spec/data/ff4_ex.sgf').parse - new_file = 'spec/data/ff4_ex_saved.sgf' - tree.save :filename => new_file - tree2 = SGF::Parser.new(new_file).parse - tree2.should == tree + it "should use preorder traversal for each" do + @tree = get_tree_from 'spec/data/example1.sgf' + array = [] + @tree.each {|node| array << node} + array[0].c.should == "root" + array[1].c.should == "a" + array[2].c.should == "b" + end + + it "should load a file properly" do + @tree.class.should == SGF::Tree + @tree.root.children.size.should == 2 + @tree.root.children[0].children.size.should == 5 end end