Module: RDF::Graph::Tests
- Defined in:
- lib/rdf/graph/tests.rb
Instance Method Summary collapse
-
#query_executer_test_case ⇒ Object
execute ==##.
- #test_add_should_insert_spo ⇒ Object
-
#test_add_should_insert_triple ⇒ Object
add ==##.
- #test_add_should_raise_error_for_unassociated_blank_node_object ⇒ Object
- #test_add_should_raise_error_for_unassociated_blank_node_subject ⇒ Object
- #test_delete_should_remove_spo ⇒ Object
-
#test_delete_should_remove_triple ⇒ Object
delete ==##.
-
#test_each_should_iterate_all_nodes ⇒ Object
each ==##.
-
#test_empty_should_be_true_for_empty_graph ⇒ Object
empty? ==##.
- #test_empty_should_not_be_true_for_non_empty_graph ⇒ Object
- #test_execute_should_assign_variable ⇒ Object
- #test_execute_should_return_result ⇒ Object
- #test_execute_should_succeed ⇒ Object
-
#test_include_should_accept_spo ⇒ Object
include? ==##.
- #test_merge_should_associate_blank_nodes_with_new_graph ⇒ Object
-
#test_merge_should_copy_triples ⇒ Object
merge ==##.
-
#test_new_blank_node_should_be_a_blank_node ⇒ Object
new_blank_node ==##.
- #test_new_blank_node_should_set_graph ⇒ Object
- #test_new_blank_node_should_set_name ⇒ Object
- #test_size_should_be_number_of_triples ⇒ Object
-
#test_size_should_be_zero_for_empty_graph ⇒ Object
size ==##.
Instance Method Details
#query_executer_test_case ⇒ Object
execute ==##
114 115 116 117 118 119 120 121 122 |
# File 'lib/rdf/graph/tests.rb', line 114 def query_executer_test_case @graph.add(EX::a, EX::b, EX::c) @graph.add(EX::c, EX::e, EX::f) q = RDF::Query.new q.where(EX::a, EX::b, :a) q.where(:a, EX::e, EX::f) @graph.execute(q) end |
#test_add_should_insert_spo ⇒ Object
11 12 13 14 15 |
# File 'lib/rdf/graph/tests.rb', line 11 def test_add_should_insert_spo @graph.add(EX::a, EX::b, EX::c) assert @graph.include?(RDF::Triple.new(EX::a, EX::b, EX::c)), "Add should accept three nodes as parameters" end |
#test_add_should_insert_triple ⇒ Object
add ==##
5 6 7 8 9 |
# File 'lib/rdf/graph/tests.rb', line 5 def test_add_should_insert_triple @graph.add(RDF::Triple.new(EX::a, EX::b, EX::c)) assert @graph.include?(RDF::Triple.new(EX::a, EX::b, EX::c)), "Add should accept an RDF::Triple as a parameter" end |
#test_add_should_raise_error_for_unassociated_blank_node_object ⇒ Object
23 24 25 26 27 |
# File 'lib/rdf/graph/tests.rb', line 23 def test_add_should_raise_error_for_unassociated_blank_node_object assert_raise(RDF::UnassociatedBlankNodeError) { @graph.add(EX::a, EX::b, RDF::Graph::Memory.new.new_blank_node('x')) } end |
#test_add_should_raise_error_for_unassociated_blank_node_subject ⇒ Object
17 18 19 20 21 |
# File 'lib/rdf/graph/tests.rb', line 17 def test_add_should_raise_error_for_unassociated_blank_node_subject assert_raise(RDF::UnassociatedBlankNodeError) { @graph.add(RDF::Graph::Memory.new.new_blank_node('x'), EX::b, EX::c) } end |
#test_delete_should_remove_spo ⇒ Object
42 43 44 45 46 |
# File 'lib/rdf/graph/tests.rb', line 42 def test_delete_should_remove_spo @graph.add(RDF::Triple.new(EX::a, EX::b, EX::c)) @graph.delete(EX::a, EX::b, EX::c) assert !@graph.include?(RDF::Triple.new(EX::a, EX::b, EX::c)) end |
#test_delete_should_remove_triple ⇒ Object
delete ==##
36 37 38 39 40 |
# File 'lib/rdf/graph/tests.rb', line 36 def test_delete_should_remove_triple @graph.add(RDF::Triple.new(EX::a, EX::b, EX::c)) @graph.delete(RDF::Triple.new(EX::a, EX::b, EX::c)) assert !@graph.include?(RDF::Triple.new(EX::a, EX::b, EX::c)) end |
#test_each_should_iterate_all_nodes ⇒ Object
each ==##
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/rdf/graph/tests.rb', line 72 def test_each_should_iterate_all_nodes triples = [RDF::Triple.new(EX::a, EX::b, EX::c), RDF::Triple.new(EX::d, EX::e, EX::f), RDF::Triple.new(EX::g, EX::h, EX::i)] @graph.add(triples[0]) @graph.add(triples[1]) @graph.add(triples[2]) @graph.each do |t| assert triples.delete(t) end assert_equal [], triples end |
#test_empty_should_be_true_for_empty_graph ⇒ Object
empty? ==##
49 50 51 |
# File 'lib/rdf/graph/tests.rb', line 49 def test_empty_should_be_true_for_empty_graph assert @graph.empty? end |
#test_empty_should_not_be_true_for_non_empty_graph ⇒ Object
53 54 55 56 |
# File 'lib/rdf/graph/tests.rb', line 53 def test_empty_should_not_be_true_for_non_empty_graph @graph.add(RDF::Triple.new(EX::a, EX::b, EX::c)) assert !@graph.empty? end |
#test_execute_should_assign_variable ⇒ Object
132 133 134 |
# File 'lib/rdf/graph/tests.rb', line 132 def test_execute_should_assign_variable assert_equal EX::c, query_executer_test_case.bindings.to_a.first[:a] end |
#test_execute_should_return_result ⇒ Object
124 125 126 |
# File 'lib/rdf/graph/tests.rb', line 124 def test_execute_should_return_result assert query_executer_test_case.is_a?(RDF::Query::Result) end |
#test_execute_should_succeed ⇒ Object
128 129 130 |
# File 'lib/rdf/graph/tests.rb', line 128 def test_execute_should_succeed assert query_executer_test_case.success? end |
#test_include_should_accept_spo ⇒ Object
include? ==##
30 31 32 33 |
# File 'lib/rdf/graph/tests.rb', line 30 def test_include_should_accept_spo @graph.add(RDF::Triple.new(EX::a, EX::b, EX::c)) assert @graph.include?(EX::a, EX::b, EX::c) end |
#test_merge_should_associate_blank_nodes_with_new_graph ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/rdf/graph/tests.rb', line 105 def test_merge_should_associate_blank_nodes_with_new_graph new_graph = RDF::Graph::Memory.new x = new_graph.new_blank_node('x') new_graph.add(EX::a, EX::b, x) @graph.merge(new_graph) assert_equal @graph, @graph.execute(RDF::Query.new.where(EX::a, EX::b, :a)).bindings.to_a.first[:a].graph end |
#test_merge_should_copy_triples ⇒ Object
merge ==##
98 99 100 101 102 103 |
# File 'lib/rdf/graph/tests.rb', line 98 def test_merge_should_copy_triples new_graph = RDF::Graph::Memory.new new_graph.add(EX::a, EX::b, new_graph.new_blank_node('x')) @graph.merge(new_graph) assert @graph.execute(RDF::Query.new.where(EX::a, EX::b, :a)).success? end |
#test_new_blank_node_should_be_a_blank_node ⇒ Object
new_blank_node ==##
59 60 61 |
# File 'lib/rdf/graph/tests.rb', line 59 def test_new_blank_node_should_be_a_blank_node assert RDF::BlankNode?(@graph.new_blank_node('test')) end |
#test_new_blank_node_should_set_graph ⇒ Object
63 64 65 |
# File 'lib/rdf/graph/tests.rb', line 63 def test_new_blank_node_should_set_graph assert_equal @graph, @graph.new_blank_node('test').graph end |
#test_new_blank_node_should_set_name ⇒ Object
67 68 69 |
# File 'lib/rdf/graph/tests.rb', line 67 def test_new_blank_node_should_set_name assert_equal 'test', @graph.new_blank_node('test').name end |
#test_size_should_be_number_of_triples ⇒ Object
91 92 93 94 95 |
# File 'lib/rdf/graph/tests.rb', line 91 def test_size_should_be_number_of_triples @graph.add(EX::a, EX::b, EX::c) @graph.add(EX::d, EX::e, EX::f) assert 2, @graph.size end |
#test_size_should_be_zero_for_empty_graph ⇒ Object
size ==##
87 88 89 |
# File 'lib/rdf/graph/tests.rb', line 87 def test_size_should_be_zero_for_empty_graph assert_equal 0, @graph.size end |