2018-06-08 10:26:52 +00:00
|
|
|
defmodule RDF.EqualityTest do
|
|
|
|
use RDF.Test.Case
|
|
|
|
|
|
|
|
alias RDF.NS.XSD
|
2018-09-16 13:07:41 +00:00
|
|
|
alias Decimal, as: D
|
2018-06-08 10:26:52 +00:00
|
|
|
|
|
|
|
describe "RDF.IRI" do
|
|
|
|
@term_equal_iris [
|
|
|
|
{RDF.iri("http://example.com/"), RDF.iri("http://example.com/")},
|
|
|
|
]
|
|
|
|
@term_unequal_iris [
|
|
|
|
{RDF.iri("http://example.com/foo"), RDF.iri("http://example.com/bar")},
|
|
|
|
]
|
|
|
|
@value_equal_iris [
|
|
|
|
{RDF.iri("http://example.com/"),
|
|
|
|
RDF.literal("http://example.com/", datatype: XSD.anyURI)},
|
|
|
|
|
|
|
|
{RDF.literal("http://example.com/", datatype: XSD.anyURI),
|
|
|
|
RDF.iri("http://example.com/")},
|
|
|
|
|
|
|
|
{RDF.literal("http://example.com/", datatype: XSD.anyURI),
|
|
|
|
RDF.literal("http://example.com/", datatype: XSD.anyURI)},
|
|
|
|
]
|
|
|
|
@value_unequal_iris [
|
|
|
|
{RDF.iri("http://example.com/foo"),
|
|
|
|
RDF.literal("http://example.com/bar", datatype: XSD.anyURI)},
|
|
|
|
]
|
|
|
|
@incomparable_iris [
|
|
|
|
{RDF.iri("http://example.com/"), RDF.string("http://example.com/")},
|
|
|
|
]
|
|
|
|
|
|
|
|
test "term equality", do: assert_term_equal @term_equal_iris
|
|
|
|
test "term inequality", do: assert_term_unequal @term_unequal_iris
|
|
|
|
test "value equality", do: assert_value_equal @value_equal_iris
|
|
|
|
test "value inequality", do: assert_value_unequal @value_unequal_iris
|
|
|
|
test "incomparability", do: assert_incomparable @incomparable_iris
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "RDF.BlankNode" do
|
|
|
|
@term_equal_bnodes [
|
|
|
|
{RDF.bnode("foo"), RDF.bnode("foo")},
|
|
|
|
]
|
|
|
|
@term_unequal_bnodes [
|
|
|
|
{RDF.bnode("foo"), RDF.bnode("bar")},
|
|
|
|
]
|
|
|
|
@value_equal_bnodes [
|
|
|
|
]
|
|
|
|
@value_unequal_bnodes [
|
|
|
|
]
|
|
|
|
@incomparable_bnodes [
|
|
|
|
{RDF.bnode("foo"), RDF.string("foo")},
|
|
|
|
{RDF.string("foo"), RDF.bnode("foo")},
|
|
|
|
]
|
|
|
|
|
|
|
|
test "term equality", do: assert_term_equal @term_equal_bnodes
|
|
|
|
test "term inequality", do: assert_term_unequal @term_unequal_bnodes
|
|
|
|
test "value equality", do: assert_value_equal @value_equal_bnodes
|
|
|
|
test "value inequality", do: assert_value_unequal @value_unequal_bnodes
|
|
|
|
test "incomparability", do: assert_incomparable @incomparable_bnodes
|
|
|
|
end
|
|
|
|
|
2018-06-08 17:45:57 +00:00
|
|
|
describe "RDF.String and RDF.LangString" do
|
|
|
|
@term_equal_strings [
|
|
|
|
{RDF.string("foo"), RDF.string("foo")},
|
|
|
|
{RDF.lang_string("foo", language: "de"), RDF.lang_string("foo", language: "de")},
|
|
|
|
]
|
|
|
|
@term_unequal_strings [
|
|
|
|
{RDF.string("foo"), RDF.string("bar")},
|
|
|
|
{RDF.lang_string("foo", language: "de"), RDF.lang_string("bar", language: "de")},
|
|
|
|
]
|
|
|
|
@value_equal_strings [
|
|
|
|
]
|
|
|
|
@value_unequal_strings [
|
|
|
|
]
|
2018-09-16 02:02:53 +00:00
|
|
|
@value_equal_strings_by_coercion [
|
|
|
|
{RDF.string("foo"), "foo"},
|
|
|
|
]
|
|
|
|
@value_unequal_strings_by_coercion [
|
|
|
|
{RDF.string("foo"), "bar"},
|
|
|
|
]
|
2018-06-08 17:45:57 +00:00
|
|
|
@incomparable_strings [
|
2018-09-16 02:02:53 +00:00
|
|
|
{RDF.string("42"), 42},
|
|
|
|
{RDF.lang_string("foo", language: "de"), "foo"},
|
2018-06-08 17:45:57 +00:00
|
|
|
{RDF.string("foo"), RDF.lang_string("foo", language: "de")},
|
|
|
|
{RDF.lang_string("foo", language: "de"), RDF.string("foo")},
|
|
|
|
{RDF.string("foo"), RDF.bnode("foo")},
|
|
|
|
]
|
|
|
|
|
2018-09-16 02:02:53 +00:00
|
|
|
test "term equality", do: assert_term_equal @term_equal_strings
|
|
|
|
test "term inequality", do: assert_term_unequal @term_unequal_strings
|
|
|
|
test "value equality", do: assert_value_equal @value_equal_strings
|
|
|
|
test "value inequality", do: assert_value_unequal @value_unequal_strings
|
|
|
|
test "coerced value equality", do: assert_value_equal @value_equal_strings_by_coercion
|
|
|
|
test "coerced value inequality", do: assert_value_unequal @value_unequal_strings_by_coercion
|
|
|
|
test "incomparability", do: assert_incomparable @incomparable_strings
|
2018-06-08 17:45:57 +00:00
|
|
|
end
|
|
|
|
|
2018-06-08 10:26:52 +00:00
|
|
|
describe "RDF.Boolean" do
|
|
|
|
@term_equal_booleans [
|
2018-09-14 19:31:16 +00:00
|
|
|
{RDF.true, RDF.true},
|
|
|
|
{RDF.false, RDF.false},
|
|
|
|
# invalid literals
|
|
|
|
{RDF.boolean("foo"), RDF.boolean("foo")},
|
2018-06-08 10:26:52 +00:00
|
|
|
]
|
|
|
|
@term_unequal_booleans [
|
2018-09-14 19:31:16 +00:00
|
|
|
{RDF.true, RDF.false},
|
|
|
|
{RDF.false, RDF.true},
|
|
|
|
# invalid literals
|
|
|
|
{RDF.boolean("foo"), RDF.boolean("bar")},
|
2018-06-08 10:26:52 +00:00
|
|
|
]
|
|
|
|
@value_equal_booleans [
|
|
|
|
{RDF.true, RDF.boolean("TRUE")},
|
|
|
|
{RDF.boolean(1), RDF.true},
|
2018-09-14 19:31:16 +00:00
|
|
|
# invalid literals
|
|
|
|
{RDF.boolean("foo"), RDF.boolean("foo")},
|
2018-06-08 10:26:52 +00:00
|
|
|
]
|
|
|
|
@value_unequal_booleans [
|
|
|
|
{RDF.true, RDF.boolean("FALSE")},
|
|
|
|
{RDF.boolean(0), RDF.true},
|
2018-09-14 19:31:16 +00:00
|
|
|
# invalid literals
|
|
|
|
{RDF.boolean("foo"), RDF.boolean("bar")},
|
2018-06-08 10:26:52 +00:00
|
|
|
]
|
2018-09-16 02:02:53 +00:00
|
|
|
@value_equal_booleans_by_coercion [
|
|
|
|
{RDF.true, true},
|
|
|
|
{RDF.false, false},
|
|
|
|
]
|
|
|
|
@value_unequal_booleans_by_coercion [
|
|
|
|
{RDF.true, false},
|
|
|
|
{RDF.false, true},
|
|
|
|
]
|
2018-06-08 10:26:52 +00:00
|
|
|
@incomparable_booleans [
|
2018-09-16 02:02:53 +00:00
|
|
|
{RDF.false, nil},
|
|
|
|
{RDF.true, 42},
|
|
|
|
{RDF.true, RDF.string("FALSE")},
|
|
|
|
{RDF.true, RDF.integer(0)},
|
2018-06-08 10:26:52 +00:00
|
|
|
]
|
|
|
|
|
2018-09-16 02:02:53 +00:00
|
|
|
test "term equality", do: assert_term_equal @term_equal_booleans
|
|
|
|
test "term inequality", do: assert_term_unequal @term_unequal_booleans
|
|
|
|
test "value equality", do: assert_value_equal @value_equal_booleans
|
|
|
|
test "value inequality", do: assert_value_unequal @value_unequal_booleans
|
|
|
|
test "coerced value equality", do: assert_value_equal @value_equal_booleans_by_coercion
|
|
|
|
test "coerced value inequality", do: assert_value_unequal @value_unequal_booleans_by_coercion
|
|
|
|
test "incomparability", do: assert_incomparable @incomparable_booleans
|
2018-06-08 10:26:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "RDF.Numeric" do
|
|
|
|
@term_equal_numerics [
|
|
|
|
{RDF.integer(42), RDF.integer(42)},
|
|
|
|
{RDF.integer("042"), RDF.integer("042")},
|
2018-09-14 19:31:16 +00:00
|
|
|
# invalid literals
|
|
|
|
{RDF.integer("foo"), RDF.integer("foo")},
|
|
|
|
{RDF.decimal("foo"), RDF.decimal("foo")},
|
|
|
|
{RDF.double("foo"), RDF.double("foo")},
|
2018-06-08 10:26:52 +00:00
|
|
|
]
|
|
|
|
@term_unequal_numerics [
|
|
|
|
{RDF.integer(1), RDF.integer(2)},
|
2018-09-14 19:31:16 +00:00
|
|
|
# invalid literals
|
|
|
|
{RDF.integer("foo"), RDF.integer("bar")},
|
|
|
|
{RDF.decimal("foo"), RDF.decimal("bar")},
|
|
|
|
{RDF.double("foo"), RDF.double("bar")},
|
2018-06-08 10:26:52 +00:00
|
|
|
]
|
|
|
|
@value_equal_numerics [
|
|
|
|
{RDF.integer("42"), RDF.integer("042")},
|
|
|
|
{RDF.integer("42"), RDF.double("42")},
|
|
|
|
{RDF.integer(42), RDF.double(42.0)},
|
2018-06-15 23:48:10 +00:00
|
|
|
{RDF.integer("42"), RDF.decimal("42")},
|
|
|
|
{RDF.integer(42), RDF.decimal(42.0)},
|
|
|
|
{RDF.double(3.14), RDF.decimal(3.14)},
|
|
|
|
{RDF.double("+0"), RDF.double("-0")},
|
|
|
|
{RDF.decimal("+0"), RDF.decimal("-0")},
|
2018-09-14 19:31:16 +00:00
|
|
|
# invalid literals
|
|
|
|
{RDF.integer("foo"), RDF.integer("foo")},
|
|
|
|
{RDF.decimal("foo"), RDF.decimal("foo")},
|
|
|
|
{RDF.double("foo"), RDF.double("foo")},
|
2018-06-08 10:26:52 +00:00
|
|
|
]
|
|
|
|
@value_unequal_numerics [
|
|
|
|
{RDF.integer("1"), RDF.double("1.1")},
|
2018-06-15 23:48:10 +00:00
|
|
|
{RDF.integer("1"), RDF.decimal("1.1")},
|
2018-09-14 19:31:16 +00:00
|
|
|
# invalid literals
|
|
|
|
{RDF.integer("foo"), RDF.integer("bar")},
|
|
|
|
{RDF.decimal("foo"), RDF.decimal("bar")},
|
|
|
|
{RDF.double("foo"), RDF.double("bar")},
|
2018-06-08 10:26:52 +00:00
|
|
|
]
|
2018-09-16 02:02:53 +00:00
|
|
|
@value_equal_numerics_by_coercion [
|
|
|
|
{RDF.integer(42), 42},
|
|
|
|
{RDF.integer(42), 42.0},
|
2018-09-16 13:07:41 +00:00
|
|
|
{RDF.integer(42), D.new(42)},
|
2018-09-16 02:02:53 +00:00
|
|
|
{RDF.decimal(42), 42},
|
|
|
|
{RDF.decimal(3.14), 3.14},
|
2018-09-16 13:07:41 +00:00
|
|
|
{RDF.decimal(3.14), D.new(3.14)},
|
2018-09-16 02:02:53 +00:00
|
|
|
{RDF.double(42), 42},
|
|
|
|
{RDF.double(3.14), 3.14},
|
2018-09-16 13:07:41 +00:00
|
|
|
{RDF.double(3.14), D.new(3.14)},
|
2018-09-16 02:02:53 +00:00
|
|
|
]
|
|
|
|
@value_unequal_numerics_by_coercion [
|
|
|
|
{RDF.integer(3), 3.14},
|
2018-09-16 13:07:41 +00:00
|
|
|
{RDF.integer(3), D.new(3.14)},
|
2018-09-16 02:02:53 +00:00
|
|
|
{RDF.double(3.14), 3},
|
|
|
|
{RDF.decimal(3.14), 3},
|
|
|
|
]
|
2018-06-08 10:26:52 +00:00
|
|
|
@incomparable_numerics [
|
2018-09-16 02:02:53 +00:00
|
|
|
{RDF.integer("42"), nil},
|
|
|
|
{RDF.integer("42"), true},
|
|
|
|
{RDF.integer("42"), "42"},
|
2018-06-08 10:26:52 +00:00
|
|
|
{RDF.integer("42"), RDF.string("42")},
|
|
|
|
]
|
|
|
|
|
2018-09-16 02:02:53 +00:00
|
|
|
test "term equality", do: assert_term_equal @term_equal_numerics
|
|
|
|
test "term inequality", do: assert_term_unequal @term_unequal_numerics
|
|
|
|
test "value equality", do: assert_value_equal @value_equal_numerics
|
|
|
|
test "value inequality", do: assert_value_unequal @value_unequal_numerics
|
|
|
|
test "coerced value equality", do: assert_value_equal @value_equal_numerics_by_coercion
|
|
|
|
test "coerced value inequality", do: assert_value_unequal @value_unequal_numerics_by_coercion
|
|
|
|
test "incomparability", do: assert_incomparable @incomparable_numerics
|
2018-06-08 10:26:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "RDF.DateTime" do
|
|
|
|
@term_equal_datetimes [
|
|
|
|
{RDF.date_time("2002-04-02T12:00:00-01:00"), RDF.date_time("2002-04-02T12:00:00-01:00")},
|
|
|
|
{RDF.date_time("2002-04-02T12:00:00"), RDF.date_time("2002-04-02T12:00:00")},
|
2018-09-14 19:31:16 +00:00
|
|
|
# invalid literals
|
|
|
|
{RDF.date_time("foo"), RDF.date_time("foo")},
|
2018-06-08 10:26:52 +00:00
|
|
|
]
|
|
|
|
@term_unequal_datetimes [
|
2018-09-16 02:02:53 +00:00
|
|
|
{RDF.date_time("2002-04-02T12:00:00"), RDF.date_time("2002-04-02T17:00:00")},
|
2018-09-14 19:31:16 +00:00
|
|
|
# invalid literals
|
|
|
|
{RDF.date_time("foo"), RDF.date_time("bar")},
|
2018-06-08 10:26:52 +00:00
|
|
|
]
|
|
|
|
@value_equal_datetimes [
|
|
|
|
{RDF.date_time("2002-04-02T12:00:00-01:00"), RDF.date_time("2002-04-02T17:00:00+04:00")},
|
|
|
|
{RDF.date_time("2002-04-02T23:00:00-04:00"), RDF.date_time("2002-04-03T02:00:00-01:00")},
|
|
|
|
{RDF.date_time("1999-12-31T24:00:00"), RDF.date_time("2000-01-01T00:00:00")},
|
2018-11-04 14:54:49 +00:00
|
|
|
|
|
|
|
{RDF.date_time("2002-04-02T23:00:00Z"), RDF.date_time("2002-04-02T23:00:00+00:00")},
|
|
|
|
{RDF.date_time("2002-04-02T23:00:00Z"), RDF.date_time("2002-04-02T23:00:00-00:00")},
|
|
|
|
{RDF.date_time("2002-04-02T23:00:00+00:00"), RDF.date_time("2002-04-02T23:00:00-00:00")},
|
|
|
|
|
2018-09-14 19:31:16 +00:00
|
|
|
# invalid literals
|
|
|
|
{RDF.date_time("foo"), RDF.date_time("foo")},
|
2018-06-08 10:26:52 +00:00
|
|
|
]
|
|
|
|
@value_unequal_datetimes [
|
2018-06-08 17:45:57 +00:00
|
|
|
{RDF.date_time("2005-04-04T24:00:00"), RDF.date_time("2005-04-04T00:00:00")},
|
2018-09-14 19:31:16 +00:00
|
|
|
# invalid literals
|
|
|
|
{RDF.date_time("foo"), RDF.date_time("bar")},
|
2018-06-08 10:26:52 +00:00
|
|
|
]
|
2018-09-16 02:02:53 +00:00
|
|
|
@value_equal_datetimes_by_coercion [
|
|
|
|
{RDF.date_time("2002-04-02T12:00:00-01:00"), elem(DateTime.from_iso8601("2002-04-02T12:00:00-01:00"), 1)},
|
|
|
|
{RDF.date_time("2002-04-02T12:00:00"), ~N"2002-04-02T12:00:00"},
|
2018-11-04 14:54:49 +00:00
|
|
|
{RDF.date_time("2002-04-02T23:00:00Z"), elem(DateTime.from_iso8601("2002-04-02T23:00:00+00:00"), 1)},
|
|
|
|
{RDF.date_time("2002-04-02T23:00:00+00:00"), elem(DateTime.from_iso8601("2002-04-02T23:00:00Z"), 1)},
|
|
|
|
{RDF.date_time("2002-04-02T23:00:00-00:00"), elem(DateTime.from_iso8601("2002-04-02T23:00:00Z"), 1)},
|
|
|
|
{RDF.date_time("2002-04-02T23:00:00-00:00"), elem(DateTime.from_iso8601("2002-04-02T23:00:00+00:00"), 1)},
|
2018-09-16 02:02:53 +00:00
|
|
|
]
|
|
|
|
@value_unequal_datetimes_by_coercion [
|
|
|
|
{RDF.date_time("2002-04-02T12:00:00-01:00"), elem(DateTime.from_iso8601("2002-04-02T12:00:00+00:00"), 1)},
|
|
|
|
]
|
2018-06-08 10:26:52 +00:00
|
|
|
@incomparable_datetimes [
|
2018-11-04 14:54:49 +00:00
|
|
|
{RDF.date_time("2002-04-02T12:00:00"), RDF.date_time("2002-04-02T12:00:00Z")},
|
|
|
|
{RDF.string("2002-04-02T12:00:00-01:00"), RDF.date_time("2002-04-02T12:00:00-01:00")},
|
|
|
|
# These are incomparable because of indeterminacy due to missing timezone
|
|
|
|
{RDF.date_time("2002-04-02T12:00:00"), RDF.date_time("2002-04-02T23:00:00+00:00")},
|
2018-06-08 10:26:52 +00:00
|
|
|
]
|
|
|
|
|
2018-09-16 02:02:53 +00:00
|
|
|
test "term equality", do: assert_term_equal @term_equal_datetimes
|
|
|
|
test "term inequality", do: assert_term_unequal @term_unequal_datetimes
|
|
|
|
test "value equality", do: assert_value_equal @value_equal_datetimes
|
|
|
|
test "value inequality", do: assert_value_unequal @value_unequal_datetimes
|
|
|
|
test "coerced value equality", do: assert_value_equal @value_equal_datetimes_by_coercion
|
|
|
|
test "coerced value inequality", do: assert_value_unequal @value_unequal_datetimes_by_coercion
|
|
|
|
test "incomparability", do: assert_incomparable @incomparable_datetimes
|
2018-06-08 10:26:52 +00:00
|
|
|
end
|
|
|
|
|
2018-09-16 02:02:53 +00:00
|
|
|
describe "RDF.Date" do
|
|
|
|
@term_equal_dates [
|
|
|
|
{RDF.date("2002-04-02-01:00"), RDF.date("2002-04-02-01:00")},
|
|
|
|
{RDF.date("2002-04-02"), RDF.date("2002-04-02")},
|
|
|
|
# invalid literals
|
|
|
|
{RDF.date("foo"), RDF.date("foo")},
|
|
|
|
]
|
|
|
|
@term_unequal_dates [
|
|
|
|
{RDF.date("2002-04-01"), RDF.date("2002-04-02")},
|
|
|
|
# invalid literals
|
|
|
|
{RDF.date("foo"), RDF.date("bar")},
|
|
|
|
]
|
|
|
|
@value_equal_dates [
|
2018-10-25 22:57:30 +00:00
|
|
|
{RDF.date("2002-04-02-00:00"), RDF.date("2002-04-02+00:00")},
|
|
|
|
{RDF.date("2002-04-02Z"), RDF.date("2002-04-02+00:00")},
|
|
|
|
{RDF.date("2002-04-02Z"), RDF.date("2002-04-02-00:00")},
|
2018-09-16 02:02:53 +00:00
|
|
|
]
|
|
|
|
@value_unequal_dates [
|
2018-11-04 14:54:49 +00:00
|
|
|
{RDF.date("2002-04-03Z"), RDF.date("2002-04-02")},
|
|
|
|
{RDF.date("2002-04-03"), RDF.date("2002-04-02Z")},
|
|
|
|
{RDF.date("2002-04-03+00:00"), RDF.date("2002-04-02")},
|
|
|
|
{RDF.date("2002-04-03-00:00"), RDF.date("2002-04-02")},
|
|
|
|
# invalid literals
|
|
|
|
{RDF.date("2002.04.02"), RDF.date("2002-04-02")},
|
2018-09-16 02:02:53 +00:00
|
|
|
]
|
|
|
|
@value_equal_dates_by_coercion [
|
2018-11-04 14:54:49 +00:00
|
|
|
{RDF.date("2002-04-02"), Date.from_iso8601!("2002-04-02")},
|
2018-09-16 02:02:53 +00:00
|
|
|
]
|
|
|
|
@value_unequal_dates_by_coercion [
|
2018-11-04 14:54:49 +00:00
|
|
|
{RDF.date("2002-04-02"), Date.from_iso8601!("2002-04-03")},
|
|
|
|
{RDF.date("2002-04-03+01:00"), Date.from_iso8601!("2002-04-02")},
|
|
|
|
{RDF.date("2002-04-03Z"), Date.from_iso8601!("2002-04-02")},
|
|
|
|
{RDF.date("2002-04-03+00:00"), Date.from_iso8601!("2002-04-02")},
|
|
|
|
{RDF.date("2002-04-03-00:00"), Date.from_iso8601!("2002-04-02")},
|
2018-09-16 02:02:53 +00:00
|
|
|
]
|
|
|
|
@incomparable_dates [
|
|
|
|
{RDF.date("2002-04-02"), RDF.string("2002-04-02")},
|
2018-11-04 14:54:49 +00:00
|
|
|
# These are incomparable because of indeterminacy due to missing timezone
|
|
|
|
{RDF.date("2002-04-02Z"), RDF.date("2002-04-02")},
|
|
|
|
{RDF.date("2002-04-02"), RDF.date("2002-04-02Z")},
|
|
|
|
{RDF.date("2002-04-02+00:00"), RDF.date("2002-04-02")},
|
|
|
|
{RDF.date("2002-04-02-00:00"), RDF.date("2002-04-02")},
|
|
|
|
{RDF.date("2002-04-02+01:00"), Date.from_iso8601!("2002-04-02")},
|
|
|
|
{RDF.date("2002-04-02Z"), Date.from_iso8601!("2002-04-02")},
|
|
|
|
{RDF.date("2002-04-02+00:00"), Date.from_iso8601!("2002-04-02")},
|
|
|
|
{RDF.date("2002-04-02-00:00"), Date.from_iso8601!("2002-04-02")},
|
2018-09-16 02:02:53 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
test "term equality", do: assert_term_equal @term_equal_dates
|
|
|
|
test "term inequality", do: assert_term_unequal @term_unequal_dates
|
|
|
|
test "value equality", do: assert_value_equal @value_equal_dates
|
|
|
|
test "value inequality", do: assert_value_unequal @value_unequal_dates
|
|
|
|
test "coerced value equality", do: assert_value_equal @value_equal_dates_by_coercion
|
|
|
|
test "coerced value inequality", do: assert_value_unequal @value_unequal_dates_by_coercion
|
|
|
|
test "incomparability", do: assert_incomparable @incomparable_dates
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "RDF.Time" do
|
|
|
|
@term_equal_times [
|
|
|
|
{RDF.time("12:00:00+01:00"), RDF.time("12:00:00+01:00")},
|
|
|
|
{RDF.time("12:00:00"), RDF.time("12:00:00")},
|
|
|
|
# invalid literals
|
|
|
|
{RDF.time("foo"), RDF.time("foo")},
|
|
|
|
]
|
|
|
|
@term_unequal_times [
|
|
|
|
{RDF.time("12:00:00"), RDF.time("13:00:00")},
|
|
|
|
# invalid literals
|
|
|
|
{RDF.time("foo"), RDF.time("bar")},
|
|
|
|
]
|
|
|
|
@value_equal_times [
|
|
|
|
]
|
|
|
|
@value_unequal_times [
|
|
|
|
]
|
|
|
|
@value_equal_times_by_coercion [
|
|
|
|
{RDF.time("12:00:00"), Time.from_iso8601!("12:00:00")},
|
|
|
|
]
|
|
|
|
@value_unequal_times_by_coercion [
|
|
|
|
{RDF.time("12:00:00"), Time.from_iso8601!("13:00:00")},
|
|
|
|
]
|
|
|
|
@incomparable_times [
|
|
|
|
{RDF.time("12:00:00"), RDF.string("12:00:00")},
|
|
|
|
]
|
|
|
|
|
|
|
|
test "term equality", do: assert_term_equal @term_equal_times
|
|
|
|
test "term inequality", do: assert_term_unequal @term_unequal_times
|
|
|
|
test "value equality", do: assert_value_equal @value_equal_times
|
|
|
|
test "value inequality", do: assert_value_unequal @value_unequal_times
|
|
|
|
test "coerced value equality", do: assert_value_equal @value_equal_times_by_coercion
|
|
|
|
test "coerced value inequality", do: assert_value_unequal @value_unequal_times_by_coercion
|
|
|
|
test "incomparability", do: assert_incomparable @incomparable_times
|
|
|
|
end
|
|
|
|
|
2018-09-14 19:30:48 +00:00
|
|
|
describe "RDF.Literals with unsupported types" do
|
|
|
|
@equal_literals [
|
|
|
|
{RDF.literal("foo", datatype: "http://example.com/datatype"),
|
|
|
|
RDF.literal("foo", datatype: "http://example.com/datatype")},
|
|
|
|
]
|
|
|
|
@unequal_literals [
|
|
|
|
{RDF.literal("foo", datatype: "http://example.com/datatype"),
|
|
|
|
RDF.literal("bar", datatype: "http://example.com/datatype")},
|
|
|
|
]
|
|
|
|
@incomparable_literals [
|
|
|
|
{RDF.literal("foo", datatype: "http://example.com/datatype1"),
|
|
|
|
RDF.literal("foo", datatype: "http://example.com/datatype2")},
|
|
|
|
]
|
|
|
|
|
|
|
|
test "term equality", do: assert_term_equal @equal_literals
|
|
|
|
test "term inequality", do: assert_value_unequal @unequal_literals
|
|
|
|
test "incomparability", do: assert_incomparable @incomparable_literals
|
|
|
|
end
|
|
|
|
|
2018-06-08 10:26:52 +00:00
|
|
|
|
|
|
|
defp assert_term_equal(examples) do
|
|
|
|
Enum.each examples, fn example -> assert_term_equality(example, true) end
|
|
|
|
Enum.each examples, fn example -> assert_value_equality(example, true) end
|
|
|
|
end
|
|
|
|
|
|
|
|
defp assert_term_unequal(examples) do
|
|
|
|
Enum.each examples, fn example -> assert_term_equality(example, false) end
|
|
|
|
Enum.each examples, fn example -> assert_value_equality(example, false) end
|
|
|
|
end
|
|
|
|
|
|
|
|
defp assert_value_equal(examples) do
|
|
|
|
Enum.each examples, fn example -> assert_value_equality(example, true) end
|
|
|
|
end
|
|
|
|
|
|
|
|
defp assert_value_unequal(examples) do
|
|
|
|
Enum.each examples, fn example -> assert_value_equality(example, false) end
|
|
|
|
end
|
|
|
|
|
|
|
|
defp assert_incomparable(examples) do
|
|
|
|
Enum.each examples, fn example -> assert_term_equality(example, false) end
|
|
|
|
Enum.each examples, fn example -> assert_value_equality(example, nil) end
|
|
|
|
end
|
|
|
|
|
|
|
|
defp assert_term_equality({left, right}, expected) do
|
|
|
|
result = RDF.Term.equal?(left, right)
|
|
|
|
assert result == expected, """
|
|
|
|
expected RDF.Term.equal?(
|
|
|
|
#{inspect left},
|
|
|
|
#{inspect right})
|
|
|
|
to be: #{inspect expected}
|
|
|
|
but got: #{inspect result}
|
|
|
|
"""
|
2018-09-16 02:02:53 +00:00
|
|
|
|
|
|
|
result = RDF.Term.equal?(right, left)
|
|
|
|
assert result == expected, """
|
|
|
|
expected RDF.Term.equal?(
|
|
|
|
#{inspect right},
|
|
|
|
#{inspect left})
|
|
|
|
to be: #{inspect expected}
|
|
|
|
but got: #{inspect result}
|
|
|
|
"""
|
2018-06-08 10:26:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
defp assert_value_equality({left, right}, expected) do
|
|
|
|
result = RDF.Term.equal_value?(left, right)
|
|
|
|
assert result == expected, """
|
|
|
|
expected RDF.Term.equal_value?(
|
|
|
|
#{inspect left},
|
|
|
|
#{inspect right})
|
|
|
|
to be: #{inspect expected}
|
|
|
|
but got: #{inspect result}
|
|
|
|
"""
|
2018-09-16 02:02:53 +00:00
|
|
|
|
|
|
|
result = RDF.Term.equal_value?(right, left)
|
|
|
|
assert result == expected, """
|
|
|
|
expected RDF.Term.equal_value?(
|
|
|
|
#{inspect right},
|
|
|
|
#{inspect left})
|
|
|
|
to be: #{inspect expected}
|
|
|
|
but got: #{inspect result}
|
|
|
|
"""
|
2018-06-08 10:26:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|