aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpukkamustard <pukkamustard@posteo.net>2021-06-28 13:17:07 +0200
committerpukkamustard <pukkamustard@posteo.net>2021-06-28 13:17:07 +0200
commita82f31e6c66ed56d53aad07c4d1d587d1280bf39 (patch)
tree7d7ee9dddc33c81f1663267d08d04c56d9830618
parente1d5560be2af20245caa876c856c1c7cf56fbd13 (diff)
Rdf.Graph: add `equal` function
-rw-r--r--lib/core/graph.ml2
-rw-r--r--lib/core/rdf.mli4
-rw-r--r--test/core/main.ml68
3 files changed, 72 insertions, 2 deletions
diff --git a/lib/core/graph.ml b/lib/core/graph.ml
index b5ad5fc..f1c0640 100644
--- a/lib/core/graph.ml
+++ b/lib/core/graph.ml
@@ -9,6 +9,8 @@ module TermSet = Set.Make(Term)
type t = (TermSet.t TermMap.t) TermMap.t
+let equal = TermMap.equal (TermMap.equal TermSet.equal)
+
let empty = TermMap.empty
let singleton (triple:Triple.t) =
diff --git a/lib/core/rdf.mli b/lib/core/rdf.mli
index 4ec8f21..97eebd0 100644
--- a/lib/core/rdf.mli
+++ b/lib/core/rdf.mli
@@ -224,6 +224,10 @@ module Graph : sig
type t
(** An RDF graph *)
+ val equal : t -> t -> bool
+ (** [equal a b] tests wheter graphs [a] and [b] are equal. Note that this does
+ not check for graph isomorphism (i.e. relabeling of blank nodes).*)
+
val empty : t
(** [empty] is the empty graph. *)
diff --git a/test/core/main.ml b/test/core/main.ml
index 0b98968..5bf6987 100644
--- a/test/core/main.ml
+++ b/test/core/main.ml
@@ -5,5 +5,69 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*)
-(* TODO *)
-print_endline "crickets..."
+
+let ex = Rdf.Namespace.make_namespace "http://example.com/"
+let ex2 = Rdf.Namespace.make_namespace "http://example2.com/"
+
+module GraphTest = struct
+
+ let equal_unit_test =
+ let open Alcotest in
+ test_case "equality unit tests"
+ `Quick
+ (fun () ->
+ check bool
+ "empty graphs are equal"
+ true
+ Rdf.Graph.(equal empty empty);
+
+
+ check bool
+ "graph with one element added is not equal to empty graph"
+ false
+ Rdf.Graph.(equal empty @@
+ add empty Rdf.Triple.(
+ make
+ (Subject.of_iri @@ ex "foo")
+ (Predicate.of_iri @@ ex "prop")
+ (Object.of_iri @@ ex "bar")));
+
+ check bool
+ "graph with one element is equal"
+ true
+ Rdf.Graph.(equal
+ (add empty
+ Rdf.Triple.(make
+ (Subject.of_iri @@ ex "foo")
+ (Predicate.of_iri @@ ex "prop")
+ (Object.of_iri @@ ex "bar")))
+ (add empty
+ Rdf.Triple.(make
+ (Subject.of_iri @@ ex "foo")
+ (Predicate.of_iri @@ ex "prop")
+ (Object.of_iri @@ ex "bar"))));
+
+ check bool
+ "graph with two different elements is not equal"
+ false
+ Rdf.Graph.(equal
+ (add empty
+ Rdf.Triple.(make
+ (Subject.of_iri @@ ex "foo")
+ (Predicate.of_iri @@ ex "prop")
+ (Object.of_iri @@ ex "bar")))
+ (add empty
+ Rdf.Triple.(make
+ (Subject.of_iri @@ ex2 "foo")
+ (Predicate.of_iri @@ ex "prop")
+ (Object.of_iri @@ ex "bar"))));
+
+ )
+
+ let testcases = [equal_unit_test]
+end
+
+let () =
+ Alcotest.run "rdf" [
+ "Rdf.Graph", GraphTest.testcases
+ ]