2016-10-15 16:26:56 +00:00
defmodule RDF.GraphTest do
2017-02-13 00:21:32 +00:00
use RDF.Test.Case
2016-11-02 02:19:19 +00:00
2016-10-15 16:26:56 +00:00
doctest RDF.Graph
2017-03-31 14:27:34 +00:00
describe " new " do
2016-10-15 16:26:56 +00:00
test " creating an empty unnamed graph " do
2017-02-12 14:42:27 +00:00
assert unnamed_graph? ( unnamed_graph ( ) )
2016-10-15 16:26:56 +00:00
end
test " creating an empty graph with a proper graph name " do
2017-02-12 14:42:27 +00:00
refute unnamed_graph? ( named_graph ( ) )
assert named_graph? ( named_graph ( ) )
2016-10-15 16:26:56 +00:00
end
2017-04-11 00:05:57 +00:00
test " creating an empty graph with a blank node as graph name " do
assert named_graph ( bnode ( " graph_name " ) )
|> named_graph? ( bnode ( " graph_name " ) )
end
2016-10-15 16:26:56 +00:00
test " creating an empty graph with a convertible graph name " do
assert named_graph ( " http://example.com/graph/GraphName " )
|> named_graph? ( uri ( " http://example.com/graph/GraphName " ) )
assert named_graph ( EX.Foo ) |> named_graph? ( uri ( EX.Foo ) )
end
test " creating an unnamed graph with an initial triple " do
g = Graph . new ( { EX.Subject , EX . predicate , EX.Object } )
assert unnamed_graph? ( g )
assert graph_includes_statement? ( g , { EX.Subject , EX . predicate , EX.Object } )
2016-11-25 00:17:07 +00:00
g = Graph . new ( EX.Subject , EX . predicate , EX.Object )
assert unnamed_graph? ( g )
assert graph_includes_statement? ( g , { EX.Subject , EX . predicate , EX.Object } )
2016-10-15 16:26:56 +00:00
end
test " creating a named graph with an initial triple " do
g = Graph . new ( EX.GraphName , { EX.Subject , EX . predicate , EX.Object } )
assert named_graph? ( g , uri ( EX.GraphName ) )
assert graph_includes_statement? ( g , { EX.Subject , EX . predicate , EX.Object } )
2016-11-25 00:17:07 +00:00
g = Graph . new ( EX.GraphName , EX.Subject , EX . predicate , EX.Object )
assert named_graph? ( g , uri ( EX.GraphName ) )
assert graph_includes_statement? ( g , { EX.Subject , EX . predicate , EX.Object } )
2016-10-15 16:26:56 +00:00
end
test " creating an unnamed graph with a list of initial triples " do
g = Graph . new ( [ { EX.Subject1 , EX . predicate1 , EX.Object1 } ,
{ EX.Subject2 , EX . predicate2 , EX.Object2 } ] )
assert unnamed_graph? ( g )
assert graph_includes_statement? ( g , { EX.Subject1 , EX . predicate1 , EX.Object1 } )
assert graph_includes_statement? ( g , { EX.Subject2 , EX . predicate2 , EX.Object2 } )
2016-11-25 00:17:07 +00:00
g = Graph . new ( EX.Subject , EX . predicate , [ EX.Object1 , EX.Object2 ] )
assert unnamed_graph? ( g )
assert graph_includes_statement? ( g , { EX.Subject , EX . predicate , EX.Object1 } )
assert graph_includes_statement? ( g , { EX.Subject , EX . predicate , EX.Object2 } )
2016-10-15 16:26:56 +00:00
end
test " creating a named graph with a list of initial triples " do
g = Graph . new ( EX.GraphName , [ { EX.Subject , EX . predicate1 , EX.Object1 } ,
{ EX.Subject , EX . predicate2 , EX.Object2 } ] )
assert named_graph? ( g , uri ( EX.GraphName ) )
assert graph_includes_statement? ( g , { EX.Subject , EX . predicate1 , EX.Object1 } )
assert graph_includes_statement? ( g , { EX.Subject , EX . predicate2 , EX.Object2 } )
2016-11-25 00:17:07 +00:00
g = Graph . new ( EX.GraphName , EX.Subject , EX . predicate , [ EX.Object1 , EX.Object2 ] )
assert named_graph? ( g , uri ( EX.GraphName ) )
assert graph_includes_statement? ( g , { EX.Subject , EX . predicate , EX.Object1 } )
assert graph_includes_statement? ( g , { EX.Subject , EX . predicate , EX.Object2 } )
2016-10-15 16:26:56 +00:00
end
2016-12-09 13:52:21 +00:00
test " creating a named graph with an initial description " do
g = Graph . new ( EX.GraphName , Description . new ( { EX.Subject , EX . predicate , EX.Object } ) )
assert named_graph? ( g , uri ( EX.GraphName ) )
assert graph_includes_statement? ( g , { EX.Subject , EX . predicate , EX.Object } )
end
test " creating an unnamed graph with an initial description " do
g = Graph . new ( Description . new ( { EX.Subject , EX . predicate , EX.Object } ) )
assert unnamed_graph? ( g )
assert graph_includes_statement? ( g , { EX.Subject , EX . predicate , EX.Object } )
end
2017-03-31 14:04:39 +00:00
test " creating a named graph from another graph " do
g = Graph . new ( EX.GraphName , Graph . new ( { EX.Subject , EX . predicate , EX.Object } ) )
assert named_graph? ( g , uri ( EX.GraphName ) )
assert graph_includes_statement? ( g , { EX.Subject , EX . predicate , EX.Object } )
g = Graph . new ( EX.GraphName , Graph . new ( EX.OtherGraphName , { EX.Subject , EX . predicate , EX.Object } ) )
assert named_graph? ( g , uri ( EX.GraphName ) )
assert graph_includes_statement? ( g , { EX.Subject , EX . predicate , EX.Object } )
end
test " creating an unnamed graph from another graph " do
g = Graph . new ( Graph . new ( { EX.Subject , EX . predicate , EX.Object } ) )
assert unnamed_graph? ( g )
assert graph_includes_statement? ( g , { EX.Subject , EX . predicate , EX.Object } )
g = Graph . new ( Graph . new ( EX.OtherGraphName , { EX.Subject , EX . predicate , EX.Object } ) )
assert unnamed_graph? ( g )
assert graph_includes_statement? ( g , { EX.Subject , EX . predicate , EX.Object } )
end
2016-10-15 16:26:56 +00:00
end
2017-03-31 14:27:34 +00:00
describe " add " do
2016-10-15 16:26:56 +00:00
test " a proper triple " do
2017-02-12 14:42:27 +00:00
assert Graph . add ( graph ( ) , uri ( EX.Subject ) , EX . predicate , uri ( EX.Object ) )
2016-11-25 00:17:07 +00:00
|> graph_includes_statement? ( { EX.Subject , EX . predicate , EX.Object } )
2017-02-12 14:42:27 +00:00
assert Graph . add ( graph ( ) , { uri ( EX.Subject ) , EX . predicate , uri ( EX.Object ) } )
2016-10-15 16:26:56 +00:00
|> graph_includes_statement? ( { EX.Subject , EX . predicate , EX.Object } )
end
2016-11-25 00:17:07 +00:00
test " a convertible triple " do
2017-02-12 14:42:27 +00:00
assert Graph . add ( graph ( ) ,
2017-02-13 00:21:32 +00:00
" http://example.com/Subject " , EX . predicate , EX.Object )
2016-11-25 00:17:07 +00:00
|> graph_includes_statement? ( { EX.Subject , EX . predicate , EX.Object } )
2017-02-12 14:42:27 +00:00
assert Graph . add ( graph ( ) ,
2017-02-13 00:21:32 +00:00
{ " http://example.com/Subject " , EX . predicate , EX.Object } )
2016-10-15 16:26:56 +00:00
|> graph_includes_statement? ( { EX.Subject , EX . predicate , EX.Object } )
end
2016-11-25 00:17:07 +00:00
test " a triple with multiple objects " do
2017-02-12 14:42:27 +00:00
g = Graph . add ( graph ( ) , EX.Subject1 , EX . predicate1 , [ EX.Object1 , EX.Object2 ] )
2016-11-25 00:17:07 +00:00
assert graph_includes_statement? ( g , { EX.Subject1 , EX . predicate1 , EX.Object1 } )
assert graph_includes_statement? ( g , { EX.Subject1 , EX . predicate1 , EX.Object2 } )
end
2016-10-15 16:26:56 +00:00
test " a list of triples " do
2017-02-12 14:42:27 +00:00
g = Graph . add ( graph ( ) , [
2016-10-15 16:26:56 +00:00
{ EX.Subject1 , EX . predicate1 , EX.Object1 } ,
{ EX.Subject1 , EX . predicate2 , EX.Object2 } ,
{ EX.Subject3 , EX . predicate3 , EX.Object3 }
] )
assert graph_includes_statement? ( g , { EX.Subject1 , EX . predicate1 , EX.Object1 } )
assert graph_includes_statement? ( g , { EX.Subject1 , EX . predicate2 , EX.Object2 } )
assert graph_includes_statement? ( g , { EX.Subject3 , EX . predicate3 , EX.Object3 } )
end
2016-12-09 13:52:21 +00:00
test " a Description " do
2017-02-12 14:42:27 +00:00
g = Graph . add ( graph ( ) , Description . new ( EX.Subject1 , [
2016-12-09 13:52:21 +00:00
{ EX . predicate1 , EX.Object1 } ,
{ EX . predicate2 , EX.Object2 } ,
] ) )
assert graph_includes_statement? ( g , { EX.Subject1 , EX . predicate1 , EX.Object1 } )
assert graph_includes_statement? ( g , { EX.Subject1 , EX . predicate2 , EX.Object2 } )
g = Graph . add ( g , Description . new ( { EX.Subject1 , EX . predicate3 , EX.Object3 } ) )
assert graph_includes_statement? ( g , { EX.Subject1 , EX . predicate1 , EX.Object1 } )
assert graph_includes_statement? ( g , { EX.Subject1 , EX . predicate2 , EX.Object2 } )
assert graph_includes_statement? ( g , { EX.Subject1 , EX . predicate3 , EX.Object3 } )
end
test " a list of Descriptions " do
2017-02-12 14:42:27 +00:00
g = Graph . add ( graph ( ) , [
2016-12-09 13:52:21 +00:00
Description . new ( { EX.Subject1 , EX . predicate1 , EX.Object1 } ) ,
Description . new ( { EX.Subject2 , EX . predicate2 , EX.Object2 } ) ,
Description . new ( { EX.Subject1 , EX . predicate3 , EX.Object3 } )
] )
assert graph_includes_statement? ( g , { EX.Subject1 , EX . predicate1 , EX.Object1 } )
assert graph_includes_statement? ( g , { EX.Subject2 , EX . predicate2 , EX.Object2 } )
assert graph_includes_statement? ( g , { EX.Subject1 , EX . predicate3 , EX.Object3 } )
end
2016-10-15 16:26:56 +00:00
test " duplicates are ignored " do
2017-02-12 14:42:27 +00:00
g = Graph . add ( graph ( ) , { EX.Subject , EX . predicate , EX.Object } )
2016-10-15 16:26:56 +00:00
assert Graph . add ( g , { EX.Subject , EX . predicate , EX.Object } ) == g
end
2017-03-31 13:55:56 +00:00
test " a Graph " do
g = Graph . add ( graph ( ) , Graph . new ( [
{ EX.Subject1 , EX . predicate1 , EX.Object1 } ,
{ EX.Subject2 , EX . predicate2 , EX.Object2 } ,
{ EX.Subject3 , EX . predicate3 , EX.Object3 }
] ) )
assert graph_includes_statement? ( g , { EX.Subject1 , EX . predicate1 , EX.Object1 } )
assert graph_includes_statement? ( g , { EX.Subject2 , EX . predicate2 , EX.Object2 } )
assert graph_includes_statement? ( g , { EX.Subject3 , EX . predicate3 , EX.Object3 } )
g = Graph . add ( g , Graph . new ( [
{ EX.Subject1 , EX . predicate1 , EX.Object2 } ,
{ EX.Subject2 , EX . predicate4 , EX.Object4 } ,
] ) )
assert graph_includes_statement? ( g , { EX.Subject1 , EX . predicate1 , EX.Object1 } )
assert graph_includes_statement? ( g , { EX.Subject1 , EX . predicate1 , EX.Object2 } )
assert graph_includes_statement? ( g , { EX.Subject2 , EX . predicate2 , EX.Object2 } )
assert graph_includes_statement? ( g , { EX.Subject2 , EX . predicate4 , EX.Object4 } )
assert graph_includes_statement? ( g , { EX.Subject3 , EX . predicate3 , EX.Object3 } )
end
2016-10-15 16:26:56 +00:00
test " non-convertible Triple elements are causing an error " do
assert_raise RDF.InvalidURIError , fn ->
2017-02-12 14:42:27 +00:00
Graph . add ( graph ( ) , { " not a URI " , EX . predicate , uri ( EX.Object ) } )
2016-10-15 16:26:56 +00:00
end
2016-11-04 21:13:06 +00:00
assert_raise RDF.InvalidLiteralError , fn ->
2017-02-12 14:42:27 +00:00
Graph . add ( graph ( ) , { EX.Subject , EX . prop , self ( ) } )
2016-10-15 16:26:56 +00:00
end
end
end
2017-06-02 14:24:15 +00:00
2017-03-31 14:27:34 +00:00
describe " put " do
2016-12-09 13:52:21 +00:00
test " a list of triples " do
g = Graph . new ( [ { EX.S1 , EX.P1 , EX.O1 } , { EX.S2 , EX.P2 , EX.O2 } ] )
|> RDF.Graph . put ( [ { EX.S1 , EX.P2 , EX.O3 } , { EX.S1 , EX.P2 , bnode ( :foo ) } ,
{ EX.S2 , EX.P2 , EX.O3 } , { EX.S2 , EX.P2 , EX.O4 } ] )
assert Graph . triple_count ( g ) == 5
assert graph_includes_statement? ( g , { EX.S1 , EX.P1 , EX.O1 } )
assert graph_includes_statement? ( g , { EX.S1 , EX.P2 , EX.O3 } )
assert graph_includes_statement? ( g , { EX.S1 , EX.P2 , bnode ( :foo ) } )
assert graph_includes_statement? ( g , { EX.S2 , EX.P2 , EX.O3 } )
assert graph_includes_statement? ( g , { EX.S2 , EX.P2 , EX.O4 } )
end
test " a Description " do
g = Graph . new ( [ { EX.S1 , EX.P1 , EX.O1 } , { EX.S2 , EX.P2 , EX.O2 } , { EX.S1 , EX.P3 , EX.O3 } ] )
|> RDF.Graph . put ( Description . new ( EX.S1 , [ { EX.P3 , EX.O4 } , { EX.P2 , bnode ( :foo ) } ] ) )
2016-11-26 22:45:41 +00:00
2016-12-09 13:52:21 +00:00
assert Graph . triple_count ( g ) == 4
2016-11-26 22:45:41 +00:00
assert graph_includes_statement? ( g , { EX.S1 , EX.P1 , EX.O1 } )
2016-12-09 13:52:21 +00:00
assert graph_includes_statement? ( g , { EX.S1 , EX.P3 , EX.O4 } )
2016-11-26 22:45:41 +00:00
assert graph_includes_statement? ( g , { EX.S1 , EX.P2 , bnode ( :foo ) } )
2016-12-09 13:52:21 +00:00
assert graph_includes_statement? ( g , { EX.S2 , EX.P2 , EX.O2 } )
end
@tag skip : " TODO: Requires Graph.put with a list to differentiate a list of statements and a list of Descriptions. Do we want to support mixed lists also? "
test " a list of Descriptions " do
g = Graph . new ( [ { EX.S1 , EX.P1 , EX.O1 } , { EX.S2 , EX.P2 , EX.O2 } ] )
|> RDF.Graph . put ( [
Description . new ( EX.S1 , [ { EX.P2 , EX.O3 } , { EX.P2 , bnode ( :foo ) } ] ) ,
Description . new ( EX.S2 , [ { EX.P2 , EX.O3 } , { EX.P2 , EX.O4 } ] )
] )
assert Graph . triple_count ( g ) == 5
assert graph_includes_statement? ( g , { EX.S1 , EX.P1 , EX.O1 } )
assert graph_includes_statement? ( g , { EX.S1 , EX.P2 , EX.O3 } )
assert graph_includes_statement? ( g , { EX.S1 , EX.P2 , bnode ( :foo ) } )
assert graph_includes_statement? ( g , { EX.S2 , EX.P2 , EX.O3 } )
assert graph_includes_statement? ( g , { EX.S2 , EX.P2 , EX.O4 } )
end
2017-03-31 14:22:16 +00:00
test " a Graph " do
g =
Graph . new ( [
{ EX.S1 , EX.P1 , EX.O1 } ,
{ EX.S1 , EX.P3 , EX.O3 } ,
{ EX.S2 , EX.P2 , EX.O2 } ,
] )
|> RDF.Graph . put ( Graph . new ( [
{ EX.S1 , EX.P3 , EX.O4 } ,
{ EX.S2 , EX.P2 , bnode ( :foo ) } ,
{ EX.S3 , EX.P3 , EX.O3 }
] ) )
assert Graph . triple_count ( g ) == 4
assert graph_includes_statement? ( g , { EX.S1 , EX.P1 , EX.O1 } )
assert graph_includes_statement? ( g , { EX.S1 , EX.P3 , EX.O4 } )
assert graph_includes_statement? ( g , { EX.S2 , EX.P2 , bnode ( :foo ) } )
assert graph_includes_statement? ( g , { EX.S3 , EX.P3 , EX.O3 } )
end
2016-11-26 22:45:41 +00:00
end
2017-06-02 14:24:15 +00:00
describe " delete " do
setup do
{ :ok ,
graph1 : Graph . new ( { EX.S , EX . p , EX.O } ) ,
graph2 : Graph . new ( EX.Graph , { EX.S , EX . p , [ EX.O1 , EX.O2 ] } ) ,
graph3 : Graph . new ( [
{ EX.S1 , EX . p1 , [ EX.O1 , EX.O2 ] } ,
{ EX.S2 , EX . p2 , EX.O3 } ,
{ EX.S3 , EX . p3 , [ ~B< foo > , ~L" bar " ] } ,
] )
}
end
test " a single statement as a triple " ,
%{ graph1 : graph1 , graph2 : graph2 } do
assert Graph . delete ( Graph . new , { EX.S , EX . p , EX.O } ) == Graph . new
assert Graph . delete ( graph1 , { EX.S , EX . p , EX.O } ) == Graph . new
assert Graph . delete ( graph2 , { EX.S , EX . p , EX.O1 } ) ==
Graph . new ( EX.Graph , { EX.S , EX . p , EX.O2 } )
assert Graph . delete ( graph2 , { EX.S , EX . p , EX.O1 } ) ==
Graph . new ( EX.Graph , { EX.S , EX . p , EX.O2 } )
end
test " multiple statements with a triple with multiple objects " ,
%{ graph1 : graph1 , graph2 : graph2 } do
assert Graph . delete ( Graph . new , { EX.S , EX . p , [ EX.O1 , EX.O2 ] } ) == Graph . new
assert Graph . delete ( graph1 , { EX.S , EX . p , [ EX.O , EX.O2 ] } ) == Graph . new
assert Graph . delete ( graph2 , { EX.S , EX . p , [ EX.O1 , EX.O2 ] } ) == Graph . new ( EX.Graph )
end
test " multiple statements with a list of triples " ,
%{ graph1 : graph1 , graph2 : graph2 , graph3 : graph3 } do
assert Graph . delete ( graph1 , [ { EX.S , EX . p , EX.O } ,
{ EX.S , EX . p , EX.O2 } ] ) == Graph . new
assert Graph . delete ( graph2 , [ { EX.S , EX . p , EX.O1 } ,
{ EX.S , EX . p , EX.O2 } ] ) == Graph . new ( EX.Graph )
assert Graph . delete ( graph3 , [
{ EX.S1 , EX . p1 , [ EX.O1 , EX.O2 ] } ,
{ EX.S2 , EX . p2 , EX.O3 } ,
{ EX.S3 , EX . p3 , ~B< foo > } ] ) == Graph . new ( { EX.S3 , EX . p3 , ~L" bar " } )
end
test " multiple statements with a Description " ,
%{ graph1 : graph1 , graph2 : graph2 , graph3 : graph3 } do
assert Graph . delete ( graph1 , Description . new ( EX.S ,
[ { EX . p , EX.O } , { EX . p2 , EX.O2 } ] ) ) == Graph . new
assert Graph . delete ( graph2 , Description . new ( EX.S , EX . p , [ EX.O1 , EX.O2 ] ) ) ==
Graph . new ( EX.Graph )
assert Graph . delete ( graph3 , Description . new ( EX.S3 , EX . p3 , ~B< foo > ) ) ==
Graph . new ( [
{ EX.S1 , EX . p1 , [ EX.O1 , EX.O2 ] } ,
{ EX.S2 , EX . p2 , EX.O3 } ,
{ EX.S3 , EX . p3 , [ ~L" bar " ] } ,
] )
end
test " multiple statements with a Graph " ,
%{ graph1 : graph1 , graph2 : graph2 , graph3 : graph3 } do
assert Graph . delete ( graph1 , graph2 ) == graph1
assert Graph . delete ( graph1 , graph1 ) == Graph . new
assert Graph . delete ( graph2 , Graph . new ( EX.Graph , { EX.S , EX . p , [ EX.O1 , EX.O3 ] } ) ) ==
Graph . new ( EX.Graph , { EX.S , EX . p , EX.O2 } )
assert Graph . delete ( graph3 , Graph . new ( [
{ EX.S1 , EX . p1 , [ EX.O1 , EX.O2 ] } ,
{ EX.S2 , EX . p2 , EX.O3 } ,
{ EX.S3 , EX . p3 , ~B< foo > } ,
] ) ) == Graph . new ( { EX.S3 , EX . p3 , ~L" bar " } )
end
end
2017-03-31 14:27:34 +00:00
test " pop " do
2016-10-15 16:26:56 +00:00
assert Graph . pop ( Graph . new ) == { nil , Graph . new }
{ triple , graph } = Graph . new ( { EX.S , EX . p , EX.O } ) |> Graph . pop
assert { uri ( EX.S ) , uri ( EX . p ) , uri ( EX.O ) } == triple
assert Enum . count ( graph . descriptions ) == 0
{ { subject , predicate , _ } , graph } =
Graph . new ( [ { EX.S , EX . p , EX.O1 } , { EX.S , EX . p , EX.O2 } ] )
|> Graph . pop
assert { subject , predicate } == { uri ( EX.S ) , uri ( EX . p ) }
assert Enum . count ( graph . descriptions ) == 1
{ { subject , _ , _ } , graph } =
Graph . new ( [ { EX.S , EX . p1 , EX.O1 } , { EX.S , EX . p2 , EX.O2 } ] )
|> Graph . pop
assert subject == uri ( EX.S )
assert Enum . count ( graph . descriptions ) == 1
end
2016-11-25 00:17:07 +00:00
describe " Enumerable protocol " do
2016-10-15 16:26:56 +00:00
test " Enum.count " do
assert Enum . count ( Graph . new EX . foo ) == 0
assert Enum . count ( Graph . new { EX.S , EX . p , EX.O } ) == 1
assert Enum . count ( Graph . new [ { EX.S , EX . p , EX.O1 } , { EX.S , EX . p , EX.O2 } ] ) == 2
2017-02-12 14:42:27 +00:00
g = Graph . add ( graph ( ) , [
2016-10-15 16:26:56 +00:00
{ EX.Subject1 , EX . predicate1 , EX.Object1 } ,
{ EX.Subject1 , EX . predicate2 , EX.Object2 } ,
{ EX.Subject3 , EX . predicate3 , EX.Object3 }
] )
assert Enum . count ( g ) == 3
end
test " Enum.member? " do
refute Enum . member? ( Graph . new , { uri ( EX.S ) , EX . p , uri ( EX.O ) } )
assert Enum . member? ( Graph . new ( { EX.S , EX . p , EX.O } ) , { EX.S , EX . p , EX.O } )
2017-02-12 14:42:27 +00:00
g = Graph . add ( graph ( ) , [
2016-10-15 16:26:56 +00:00
{ EX.Subject1 , EX . predicate1 , EX.Object1 } ,
{ EX.Subject1 , EX . predicate2 , EX.Object2 } ,
{ EX.Subject3 , EX . predicate3 , EX.Object3 }
] )
assert Enum . member? ( g , { EX.Subject1 , EX . predicate1 , EX.Object1 } )
assert Enum . member? ( g , { EX.Subject1 , EX . predicate2 , EX.Object2 } )
assert Enum . member? ( g , { EX.Subject3 , EX . predicate3 , EX.Object3 } )
end
test " Enum.reduce " do
2017-02-12 14:42:27 +00:00
g = Graph . add ( graph ( ) , [
2016-10-15 16:26:56 +00:00
{ EX.Subject1 , EX . predicate1 , EX.Object1 } ,
{ EX.Subject1 , EX . predicate2 , EX.Object2 } ,
{ EX.Subject3 , EX . predicate3 , EX.Object3 }
] )
2017-02-12 14:42:27 +00:00
assert g == Enum . reduce ( g , graph ( ) ,
2016-10-15 16:26:56 +00:00
fn ( triple , acc ) -> acc |> Graph . add ( triple ) end )
end
end
2016-11-27 12:49:42 +00:00
describe " Access behaviour " do
test " access with the [] operator " do
assert Graph . new [ EX.Subject ] == nil
assert Graph . new ( { EX.S , EX . p , EX.O } ) [ EX.S ] ==
Description . new ( { EX.S , EX . p , EX.O } )
end
end
2016-10-15 16:26:56 +00:00
end