Fix bad naming in some test functions

This commit is contained in:
Marcel Otto 2021-11-16 23:05:09 +01:00
parent a367438f9d
commit b0cdb62598
5 changed files with 85 additions and 69 deletions

View file

@ -208,26 +208,31 @@ defmodule RDF.Test.Case do
end
###############################
# RDF.Star annotations
# RDF.Star
@star_statement {@statement, EX.ap(), EX.ao()}
def star_statement(), do: @star_statement
@empty_annotation Description.new(@statement)
def empty_annotation(), do: @empty_annotation
@empty_annotation_description Description.new(@statement)
def empty_annotation_description(), do: @empty_annotation_description
@annotation Description.new(@statement, init: {EX.ap(), EX.ao()})
def annotation(), do: @annotation
@annotation_description Description.new(@statement, init: {EX.ap(), EX.ao()})
def annotation_description(), do: @annotation_description
@object_annotation Description.new(EX.As, init: {EX.ap(), @statement})
def object_annotation(), do: @object_annotation
@description_with_quoted_triple_object Description.new(EX.As, init: {EX.ap(), @statement})
def description_with_quoted_triple_object(), do: @description_with_quoted_triple_object
@graph_with_annotation Graph.new(init: @annotation)
@graph_with_annotation Graph.new(init: @annotation_description)
def graph_with_annotation(), do: @graph_with_annotation
@graph_with_annotations Graph.new(init: [@annotation, @object_annotation])
def graph_with_annotations(), do: @graph_with_annotations
@graph_with_quoted_triples Graph.new(
init: [
@annotation_description,
@description_with_quoted_triple_object
]
)
def graph_with_quoted_triples(), do: @graph_with_quoted_triples
@dataset_with_annotation Dataset.new(init: @annotation)
@dataset_with_annotation Dataset.new(init: @annotation_description)
def dataset_with_annotation(), do: @dataset_with_annotation
end

View file

@ -34,8 +34,8 @@ defmodule RDF.InspectTest do
|> String.trim()) <> "\n>"
end
test "it encodes the RDF-star graphs ands descriptions in Turtle-star" do
{_, triples} = inspect_parts(annotation(), limit: 2)
test "it encodes the RDF-star graphs and descriptions in Turtle-star" do
{_, triples} = inspect_parts(annotation_description(), limit: 2)
assert triples =~ "<< <http://example.com/S> <http://example.com/P> \"Foo\" >>"
end

View file

@ -38,7 +38,7 @@ defmodule RDF.Star.Dataset.Test do
end
test "delete/3" do
assert Dataset.delete(dataset_with_annotation(), annotation()) == dataset()
assert Dataset.delete(dataset_with_annotation(), annotation_description()) == dataset()
end
test ":filter_star opt on statements/1" do

View file

@ -24,7 +24,7 @@ defmodule RDF.Star.Description.Test do
end
test "subject/1" do
assert Description.subject(empty_annotation()) == statement()
assert Description.subject(empty_annotation_description()) == statement()
end
test "change_subject/2" do
@ -35,7 +35,7 @@ defmodule RDF.Star.Description.Test do
describe "add/3" do
test "with a proper triple as a subject" do
assert empty_annotation()
assert empty_annotation_description()
|> Description.add({statement(), EX.ap(), EX.ao()})
|> description_includes_predication({EX.ap(), EX.ao()})
end
@ -47,7 +47,7 @@ defmodule RDF.Star.Description.Test do
end
test "with a proper triple as a subject and object" do
assert empty_annotation()
assert empty_annotation_description()
|> Description.add({statement(), EX.ap(), statement()})
|> description_includes_predication({EX.ap(), statement()})
end
@ -62,81 +62,87 @@ defmodule RDF.Star.Description.Test do
end
test "with a list of predicate-object tuples" do
assert empty_annotation()
assert empty_annotation_description()
|> Description.add([{EX.ap(), statement()}])
|> description_includes_predication({EX.ap(), statement()})
end
test "with a description map" do
assert empty_annotation()
assert empty_annotation_description()
|> Description.add(%{EX.ap() => statement()})
|> description_includes_predication({EX.ap(), statement()})
end
test "with coercible triples" do
assert empty_annotation()
assert empty_annotation_description()
|> Description.add({coercible_statement(), EX.ap(), coercible_statement()})
|> description_includes_predication({EX.ap(), statement()})
end
end
test "put/3" do
assert annotation()
assert annotation_description()
|> Description.put({statement(), EX.ap(), EX.ao2()})
|> description_includes_predication({EX.ap(), EX.ao2()})
assert annotation()
assert annotation_description()
|> Description.put({statement(), EX.ap(), statement()})
|> description_includes_predication({EX.ap(), statement()})
end
test "delete/3" do
assert Description.delete(annotation(), {statement(), EX.ap(), EX.ao()}) ==
empty_annotation()
assert Description.delete(annotation_description(), {statement(), EX.ap(), EX.ao()}) ==
empty_annotation_description()
assert Description.delete(object_annotation(), {EX.As, EX.ap(), statement()}) ==
assert Description.delete(
description_with_quoted_triple_object(),
{EX.As, EX.ap(), statement()}
) ==
Description.new(EX.As)
assert Description.delete(object_annotation(), {EX.ap(), statement()}) ==
assert Description.delete(description_with_quoted_triple_object(), {EX.ap(), statement()}) ==
Description.new(EX.As)
end
test "delete_predicates/2" do
assert Description.delete_predicates(annotation(), EX.ap()) ==
empty_annotation()
assert Description.delete_predicates(annotation_description(), EX.ap()) ==
empty_annotation_description()
assert Description.delete_predicates(object_annotation(), EX.ap()) ==
assert Description.delete_predicates(description_with_quoted_triple_object(), EX.ap()) ==
Description.new(EX.As)
end
test "fetch/2" do
assert Description.fetch(annotation(), EX.ap()) == {:ok, [EX.ao()]}
assert Description.fetch(object_annotation(), EX.ap()) == {:ok, [statement()]}
assert Description.fetch(annotation_description(), EX.ap()) == {:ok, [EX.ao()]}
assert Description.fetch(description_with_quoted_triple_object(), EX.ap()) ==
{:ok, [statement()]}
end
test "get/2" do
assert Description.get(annotation(), EX.ap()) == [EX.ao()]
assert Description.get(object_annotation(), EX.ap()) == [statement()]
assert Description.get(annotation_description(), EX.ap()) == [EX.ao()]
assert Description.get(description_with_quoted_triple_object(), EX.ap()) == [statement()]
end
test "first/2" do
assert Description.first(annotation(), EX.ap()) == EX.ao()
assert Description.first(object_annotation(), EX.ap()) == statement()
assert Description.first(annotation_description(), EX.ap()) == EX.ao()
assert Description.first(description_with_quoted_triple_object(), EX.ap()) == statement()
end
test "pop/2" do
assert Description.pop(annotation(), EX.ap()) == {[EX.ao()], empty_annotation()}
assert Description.pop(annotation_description(), EX.ap()) ==
{[EX.ao()], empty_annotation_description()}
assert Description.pop(object_annotation(), EX.ap()) ==
assert Description.pop(description_with_quoted_triple_object(), EX.ap()) ==
{[statement()], Description.new(EX.As)}
end
test "update/4" do
assert (description =
Description.update(empty_annotation(), EX.ap(), statement(), fn _ ->
Description.update(empty_annotation_description(), EX.ap(), statement(), fn _ ->
raise "unexpected"
end)) ==
empty_annotation()
empty_annotation_description()
|> Description.add(%{EX.ap() => statement()})
assert Description.update(description, EX.ap(), statement(), fn
@ -144,7 +150,7 @@ defmodule RDF.Star.Description.Test do
assert statement == statement()
[statement, {s, p, EX.O}]
end) ==
empty_annotation()
empty_annotation_description()
|> Description.add(%{EX.ap() => statement()})
|> Description.add(%{EX.ap() => {EX.S, EX.P, EX.O}})
end
@ -195,8 +201,8 @@ defmodule RDF.Star.Description.Test do
end
test "describes?/2" do
assert Description.describes?(annotation(), statement())
assert Description.describes?(annotation(), coercible_statement())
assert Description.describes?(annotation_description(), statement())
assert Description.describes?(annotation_description(), coercible_statement())
end
describe "without_quoted_triples/1" do

View file

@ -5,7 +5,7 @@ defmodule RDF.Star.GraphTest do
assert Graph.new(init: {statement(), EX.ap(), EX.ao()})
|> graph_includes_statement?({statement(), EX.ap(), EX.ao()})
assert Graph.new(init: annotation())
assert Graph.new(init: annotation_description())
|> graph_includes_statement?({statement(), EX.ap(), EX.ao()})
end
@ -1691,57 +1691,60 @@ defmodule RDF.Star.GraphTest do
end
test "update/3" do
assert Graph.update(graph(), statement(), annotation(), fn _ -> raise "unexpected" end) ==
assert Graph.update(graph(), statement(), annotation_description(), fn _ ->
raise "unexpected"
end) ==
graph_with_annotation()
assert graph()
|> Graph.add({statement(), EX.foo(), EX.bar()})
|> Graph.update(statement(), fn _ -> annotation() end) ==
|> Graph.update(statement(), fn _ -> annotation_description() end) ==
graph_with_annotation()
end
test "fetch/2" do
assert graph_with_annotation() |> Graph.fetch(statement()) == {:ok, annotation()}
assert graph_with_annotation() |> Graph.fetch(statement()) == {:ok, annotation_description()}
end
test "get/3" do
assert graph_with_annotation() |> Graph.get(statement()) == annotation()
assert graph_with_annotation() |> Graph.get(statement()) == annotation_description()
end
test "get_and_update/3" do
assert Graph.get_and_update(graph_with_annotation(), statement(), fn description ->
{description, object_annotation()}
{description, description_with_quoted_triple_object()}
end) ==
{annotation(), Graph.new(init: {statement(), EX.ap(), statement()})}
{annotation_description(), Graph.new(init: {statement(), EX.ap(), statement()})}
end
test "pop/2" do
assert Graph.pop(graph_with_annotation(), statement()) == {annotation(), graph()}
assert Graph.pop(graph_with_annotation(), statement()) == {annotation_description(), graph()}
end
test "subject_count/1" do
assert Graph.subject_count(graph_with_annotations()) == 2
assert Graph.subject_count(graph_with_quoted_triples()) == 2
end
test "subjects/1" do
assert Graph.subjects(graph_with_annotations()) == MapSet.new([statement(), RDF.iri(EX.As)])
assert Graph.subjects(graph_with_quoted_triples()) ==
MapSet.new([statement(), RDF.iri(EX.As)])
end
test "objects/1" do
assert Graph.objects(graph_with_annotations()) == MapSet.new([statement(), EX.ao()])
assert Graph.objects(graph_with_quoted_triples()) == MapSet.new([statement(), EX.ao()])
end
describe "statements/1" do
test "without the filter_star flag" do
assert Graph.statements(graph_with_annotations()) == [
assert Graph.statements(graph_with_quoted_triples()) == [
star_statement(),
{RDF.iri(EX.As), EX.ap(), statement()}
]
end
test "with the filter_star flag" do
assert Graph.statements(graph_with_annotations(), filter_star: true) == []
assert Graph.statements(graph_with_annotations(), filter_star: true) == []
assert Graph.statements(graph_with_quoted_triples(), filter_star: true) == []
assert Graph.statements(graph_with_quoted_triples(), filter_star: true) == []
assert Graph.new(
init: [
@ -1785,11 +1788,13 @@ defmodule RDF.Star.GraphTest do
end
test "quoted triples on object position" do
assert Graph.without_annotations(graph_with_annotations()) == RDF.graph(object_annotation())
assert Graph.without_annotations(graph_with_quoted_triples()) ==
RDF.graph(description_with_quoted_triple_object())
assert graph_with_annotations()
assert graph_with_quoted_triples()
|> Graph.add(statement())
|> Graph.without_annotations() == RDF.graph([statement(), object_annotation()])
|> Graph.without_annotations() ==
RDF.graph([statement(), description_with_quoted_triple_object()])
end
end
@ -1808,29 +1813,29 @@ defmodule RDF.Star.GraphTest do
end
test "quoted triples on object position" do
assert Graph.without_quoted_triples(graph_with_annotations()) == RDF.graph()
assert Graph.without_quoted_triples(graph_with_quoted_triples()) == RDF.graph()
assert graph_with_annotations()
assert graph_with_quoted_triples()
|> Graph.add(statement())
|> Graph.without_quoted_triples() == RDF.graph(statement())
end
end
test "include?/3" do
assert Graph.include?(graph_with_annotations(), star_statement())
assert Graph.include?(graph_with_annotations(), {EX.As, EX.ap(), statement()})
assert Graph.include?(graph_with_quoted_triples(), star_statement())
assert Graph.include?(graph_with_quoted_triples(), {EX.As, EX.ap(), statement()})
end
test "describes?/2" do
assert Graph.describes?(graph_with_annotations(), statement())
assert Graph.describes?(graph_with_quoted_triples(), statement())
end
test "values/2" do
assert graph_with_annotations() |> Graph.values() == %{}
assert graph_with_quoted_triples() |> Graph.values() == %{}
assert Graph.new(
init: [
annotation(),
annotation_description(),
{EX.s(), EX.p(), ~L"Foo"},
{EX.s(), EX.ap(), statement()}
]
@ -1848,13 +1853,13 @@ defmodule RDF.Star.GraphTest do
RDF.Term.value(term)
end
assert graph_with_annotations() |> Graph.map(mapping) == %{}
assert graph_with_quoted_triples() |> Graph.map(mapping) == %{}
assert Graph.new([
annotation(),
annotation_description(),
{EX.s1(), EX.p(), EX.o1()},
{EX.s2(), EX.p(), EX.o2()},
object_annotation()
description_with_quoted_triple_object()
])
|> Graph.map(mapping) ==
%{