You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

tc_basic_query.rb 1.6 kB

19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. require 'test/unit'
  2. require 'igraph'
  3. class TestGraph < Test::Unit::TestCase
  4. def test_graph_size
  5. assert_equal 4, IGraph.new([1,2,3,4],true).vcount
  6. assert_equal 2, IGraph.new([1,2,3,4],true).ecount
  7. end
  8. def test_eid_get_edge
  9. assert_nothing_raised do
  10. IGraph.new(['A','B','C','D'],true).get_eid('A','B')
  11. end
  12. graph = IGraph.new(['A','B','C','D'],true)
  13. eid1 = graph.get_eid('A','B')
  14. eid2 = graph.get_eid('C','D')
  15. assert_equal ['A','B'], graph.edge(eid1)
  16. assert_equal ['C','D'], graph.edge(eid2);
  17. assert_not_equal eid1,eid2
  18. end
  19. def test_neighbours
  20. assert_nothing_raised do
  21. IGraph.new(['A','B','C','D'],true).neighbors('A',IGraph::ALL)
  22. end
  23. graph = IGraph.new(['A','B','C','D'],true)
  24. assert_equal ['B'], graph.neighbors('A',IGraph::ALL)
  25. assert_equal ['D'], graph.neighbors('C',IGraph::ALL)
  26. end
  27. def test_adjacent
  28. assert_nothing_raised do
  29. IGraph.new(['A','B','C','D'],true).adjacent('A',IGraph::ALL)
  30. end
  31. graph = IGraph.new(['A','B','C','D'],true)
  32. eid1 = graph.get_eid('A','B')
  33. eid2 = graph.adjacent('A',IGraph::ALL)[0]
  34. assert_equal eid1, eid2
  35. end
  36. def test_directed
  37. assert IGraph.new(['A','B','C','D'],true).is_directed?
  38. assert !(IGraph.new(['A','B','C','D'],false).is_directed?)
  39. end
  40. def test_degree
  41. graph = IGraph.new(['A','B','C','D'],true)
  42. assert_equal [1], graph.degree(['A'], IGraph::ALL,true)
  43. assert_equal [1,1],graph.degree(['A','B'],IGraph::ALL,true)
  44. assert_raises IGraphError do
  45. graph.degree('A',IGraph::ALL,true)
  46. end
  47. end
  48. end

Ruby binding for the igraph library.