[BioRuby-cvs] bioruby/test/unit/bio test_tree.rb,1.3,1.4

Naohisa Goto ngoto at dev.open-bio.org
Fri Jan 12 16:12:07 UTC 2007


Update of /home/repository/bioruby/bioruby/test/unit/bio
In directory dev.open-bio.org:/tmp/cvs-serv30875/test/unit/bio

Modified Files:
	test_tree.rb 
Log Message:
Large test methods are splitted into small methods.
More tests are added.


Index: test_tree.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/test/unit/bio/test_tree.rb,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** test_tree.rb	13 Dec 2006 16:29:37 -0000	1.3
--- test_tree.rb	12 Jan 2007 16:12:05 -0000	1.4
***************
*** 262,265 ****
--- 262,268 ----
        assert_equal([ @rodents, @primates ].sort(&@by_id),
                     @tree.adjacent_nodes(@mammals).sort(&@by_id))
+     end
+ 
+     def test_adjacent_nodes_nonexistent
        # test for not existed nodes
        assert_equal([], @tree.adjacent_nodes(Bio::Tree::Node.new))
***************
*** 275,279 ****
--- 278,284 ----
        assert_equal([[ @chimpanzee, @primates, @edge_primates_chimpanzee ]],
                     @tree.out_edges(@chimpanzee))
+     end
  
+     def test_out_edges_rodents
        adjacents = [ @mouse, @rat, @mammals ]
        edges = [ @edge_rodents_mouse, @edge_rodents_rat, @edge_mammals_rodents ]
***************
*** 287,291 ****
--- 292,298 ----
        assert_equal(true, adjacents.empty?)
        assert_equal(true, edges.empty?)
+     end
  
+     def test_out_edges_primates
        adjacents = [ @human, @chimpanzee, @mammals ]
        edges = [ @edge_primates_human, @edge_primates_chimpanzee,
***************
*** 300,304 ****
--- 307,313 ----
        assert_equal(true, adjacents.empty?)
        assert_equal(true, edges.empty?)
+     end
  
+     def test_out_edges_mammals
        adjacents = [ @rodents, @primates ]
        edges = [ @edge_mammals_rodents, @edge_mammals_primates ]
***************
*** 312,316 ****
--- 321,327 ----
        assert_equal(true, adjacents.empty?)
        assert_equal(true, edges.empty?)
+     end
  
+     def test_out_edges_nonexistent
        # test for not existed nodes
        assert_equal([], @tree.out_edges(Bio::Tree::Node.new))
***************
*** 327,331 ****
--- 338,344 ----
        assert_equal(@tree, r)
        assert_equal(true, flag)
+     end
  
+     def test_each_out_edge_rat
        flag = nil
        r =  @tree.each_out_edge(@rat) do |src, tgt, edge|
***************
*** 337,341 ****
--- 350,356 ----
        assert_equal(@tree, r)
        assert_equal(true, flag)
+     end
  
+     def test_each_out_edge_human
        flag = nil
        r = @tree.each_out_edge(@human) do |src, tgt, edge|
***************
*** 347,351 ****
--- 362,368 ----
        assert_equal(@tree, r)
        assert_equal(true, flag)
+     end
  
+     def test_each_out_edge_chimpanzee
        flag = nil
        r = @tree.each_out_edge(@chimpanzee) do |src, tgt, edge|
***************
*** 357,361 ****
--- 374,380 ----
        assert_equal(@tree, r)
        assert_equal(true, flag)
+     end
  
+     def test_each_out_edge_rodents
        adjacents = [ @mouse, @rat, @mammals ]
        edges = [ @edge_rodents_mouse, @edge_rodents_rat, @edge_mammals_rodents ]
***************
*** 369,373 ****
--- 388,394 ----
        assert_equal(true, adjacents.empty?)
        assert_equal(true, edges.empty?)
+     end
  
+     def test_each_out_edge_primates
        adjacents = [ @human, @chimpanzee, @mammals ]
        edges = [ @edge_primates_human, @edge_primates_chimpanzee,
***************
*** 382,386 ****
--- 403,409 ----
        assert_equal(true, adjacents.empty?)
        assert_equal(true, edges.empty?)
+     end
  
+     def test_each_out_edge_mammals
        adjacents = [ @rodents, @primates ]
        edges = [ @edge_mammals_rodents, @edge_mammals_primates ]
***************
*** 394,398 ****
--- 417,423 ----
        assert_equal(true, adjacents.empty?)
        assert_equal(true, edges.empty?)
+     end
  
+     def test_each_out_edge_nonexistent
        # test for not existed nodes
        flag = nil
***************
*** 405,408 ****
--- 430,591 ----
      end
  
+     def test_out_degree
+       assert_equal(1, @tree.out_degree(@mouse))
+       assert_equal(1, @tree.out_degree(@rat))
+       assert_equal(3, @tree.out_degree(@rodents))
+       assert_equal(1, @tree.out_degree(@human))
+       assert_equal(1, @tree.out_degree(@chimpanzee))
+       assert_equal(3, @tree.out_degree(@primates))
+       assert_equal(2, @tree.out_degree(@mammals))
+     end
+ 
+     def test_out_degree_nonexistent
+       assert_equal(0, @tree.out_degree(Bio::Tree::Node.new))
+     end
+ 
+     def test_get_edge
+       assert_not_nil(@tree.get_edge(@rodents, @mouse))
+       assert_not_nil(@tree.get_edge(@mouse, @rodents))
+       assert_equal(@edge_rodents_mouse, @tree.get_edge(@rodents, @mouse))
+       assert_equal(@edge_rodents_mouse, @tree.get_edge(@mouse, @rodents))
+ 
+       assert_not_nil(@tree.get_edge(@rodents, @rat))
+       assert_not_nil(@tree.get_edge(@rat, @rodents))
+       assert_equal(@edge_rodents_rat, @tree.get_edge(@rodents, @rat))
+       assert_equal(@edge_rodents_rat, @tree.get_edge(@rat, @rodents))
+ 
+       assert_not_nil(@tree.get_edge(@mammals, @rodents))
+       assert_not_nil(@tree.get_edge(@rodents, @mammals))
+       assert_equal(@edge_mammals_rodents, @tree.get_edge(@mammals, @rodents))
+       assert_equal(@edge_mammals_rodents, @tree.get_edge(@rodents, @mammals))
+ 
+       assert_not_nil(@tree.get_edge(@primates, @human))
+       assert_not_nil(@tree.get_edge(@human, @primates))
+       assert_equal(@edge_primates_human, @tree.get_edge(@primates, @human))
+       assert_equal(@edge_primates_human, @tree.get_edge(@human, @primates))
+ 
+       assert_not_nil(@tree.get_edge(@primates, @chimpanzee))
+       assert_not_nil(@tree.get_edge(@chimpanzee, @primates))
+       assert_equal(@edge_primates_chimpanzee, @tree.get_edge(@primates, @chimpanzee))
+       assert_equal(@edge_primates_chimpanzee, @tree.get_edge(@chimpanzee, @primates))
+ 
+       assert_not_nil(@tree.get_edge(@mammals, @primates))
+       assert_not_nil(@tree.get_edge(@primates, @mammals))
+       assert_equal(@edge_mammals_primates, @tree.get_edge(@mammals, @primates))
+       assert_equal(@edge_mammals_primates, @tree.get_edge(@primates, @mammals))
+     end
+ 
+     def test_get_edge_indirect
+       assert_nil(@tree.get_edge(@mouse, @rat))
+       assert_nil(@tree.get_edge(@human, @chimpanzee))
+     end
+ 
+     def test_get_edge_nonexistent
+       assert_nil(@tree.get_edge(@mouse, Bio::Tree::Node.new))
+     end
+ 
+     def test_get_node_by_name
+       assert_not_nil(@tree.get_node_by_name('mouse'))
+       assert_not_nil(@tree.get_node_by_name('rat'))
+       assert_not_nil(@tree.get_node_by_name('human'))
+       assert_not_nil(@tree.get_node_by_name('chimpanzee'))
+       assert_equal(@mouse, @tree.get_node_by_name('mouse'))
+       assert_equal(@rat, @tree.get_node_by_name('rat'))
+       assert_equal(@human, @tree.get_node_by_name('human'))
+       assert_equal(@chimpanzee, @tree.get_node_by_name('chimpanzee'))
+     end
+ 
+     def test_get_node_by_name_noexistent
+       assert_nil(@tree.get_node_by_name('frog'))
+     end
+ 
+     def test_add_edge
+       amphibian = Bio::Tree::Node.new('amphibian')
+       edge = Bio::Tree::Edge.new(0.3123)
+       assert_equal(edge, @tree.add_edge(@mammals, amphibian, edge))
+ 
+       frog = Bio::Tree::Node.new('frog')
+       newt = Bio::Tree::Node.new('newt')
+       assert_instance_of(Bio::Tree::Edge, @tree.add_edge(frog, newt))
+     end
+ 
+     def test_add_node
+       frog = Bio::Tree::Node.new('frog')
+       # the node does not exist
+       assert_nil(@tree.get_node_by_name('frog'))
+       assert_equal(false, @tree.include?(frog))
+       # add node
+       assert_equal(@tree, @tree.add_node(frog))
+       # the node exists
+       assert_equal(frog, @tree.get_node_by_name('frog'))
+       assert_equal(true, @tree.include?(frog))
+     end
+ 
+     def test_include?
+       assert_equal(true, @tree.include?(@mouse))
+       assert_equal(true, @tree.include?(@rat))
+       assert_equal(true, @tree.include?(@rodents))
+       assert_equal(true, @tree.include?(@human))
+       assert_equal(true, @tree.include?(@chimpanzee))
+       assert_equal(true, @tree.include?(@primates))
+       assert_equal(true, @tree.include?(@mammals))
+     end
+       
+     def test_include_nonexistent
+       assert_equal(false, @tree.include?(Bio::Tree::Node.new))
+     end
+ 
+     def test_clear_node
+       assert_equal(2, @tree.out_degree(@mammals))
+       # clear node
+       assert_equal(@tree, @tree.clear_node(@mammals))
+       # checks
+       assert_equal(true, @tree.include?(@mammals))
+       assert_equal(0, @tree.out_degree(@mammals))
+       assert_equal(2, @tree.out_degree(@rodents))
+       assert_equal(2, @tree.out_degree(@primates))
+     end
+ 
+     def test_clear_node_nonexistent
+       assert_raise(IndexError) { @tree.clear_node(Bio::Tree::Node.new) }
+     end
+ 
+     def test_remove_node
+       assert_equal(2, @tree.out_degree(@mammals))
+       # remove node
+       assert_equal(@tree, @tree.remove_node(@mammals))
+       # checks
+       assert_equal(false, @tree.include?(@mammals))
+       assert_equal(0, @tree.out_degree(@mammals))
+       assert_equal(2, @tree.out_degree(@rodents))
+       assert_equal(2, @tree.out_degree(@primates))
+     end
+ 
+     def test_remove_node_nonexistent
+       assert_raise(IndexError) { @tree.remove_node(Bio::Tree::Node.new) }
+     end
+ 
+     def test_remove_node_if
+       assert_equal(@tree, @tree.remove_node_if { |node| node == @mouse })
+       assert_equal(false, @tree.include?(@mouse))
+     end
+ 
+     def test_remove_node_if_false
+       ary = []
+       assert_equal(@tree, @tree.remove_node_if { |node| ary << node; false })
+       nodes = @nodes.sort(&@by_id)
+       assert_equal(nodes, ary.sort(&@by_id))
+       assert_equal(nodes, @tree.nodes.sort(&@by_id))
+     end
+ 
+     def test_remove_edge
+       assert_not_nil(@tree.get_edge(@mouse, @rodents))
+       assert_equal(@tree, @tree.remove_edge(@mouse, @rodents))
+       assert_nil(@tree.get_edge(@mouse, @rodents))
+     end
+ 
+     def test_remove_edge_nonexistent
+       assert_raise(IndexError) { @tree.remove_edge(@mouse, @rat) }
+     end
    end #class TestTree2
  




More information about the bioruby-cvs mailing list