Skip to content

Latest commit

 

History

History
106 lines (73 loc) · 3.43 KB

File metadata and controls

106 lines (73 loc) · 3.43 KB

generators.graph

GitHub Actions badge cljdoc badge Clojars Project Codecov badge

generators.graph is a Clojure(Script) library of test.check generators for graph data.

Install

tools.deps

com.theinternate/generators.graph {:mvn/version "0.0-45"}

Leiningen/Boot

[com.theinternate/generators.graph "0.0-45"]

Maven

<dependency>
  <groupId>com.theinternate</groupId>
  <artifactId>generators.graph</artifactId>
  <version>0.0-45</version>
</dependency>

Usage

Fire up a REPL and try it out!

(require '[clojure.test.check.generators :as gen])
(require '[com.theinternate.generators.graph :as gen.graph])

Generate a random DAG from a set of nodes:

(gen/generate (gen.graph/gen-directed-acyclic-graph #{:a :b :c :d}))

Generate a random directed graph (which may contain cycles):

(gen/generate (gen.graph/gen-directed-graph #{:a :b :c :d}))

Generate a random undirected graph:

(gen/generate (gen.graph/gen-undirected-graph #{:a :b :c :d}))

Generate a random topological ordering of a DAG:

(gen/generate (gen.graph/gen-topological-ordering {:a #{}
                                                   :b #{}
                                                   :c #{:b :d}
                                                   :d #{:a}}))

Generate a weighted graph by decorating an existing graph's edges with non-negative integer weights. Composes with any of the graph generators above:

(gen/generate
 (gen/bind (gen.graph/gen-directed-acyclic-graph #{:a :b :c :d})
           gen.graph/gen-weighted))

Generate an ancestor-closed subgraph of a DAG — a subset whose vertices are closed under the ancestor relation:

(gen/generate (gen.graph/gen-ancestor-closed-subgraph {:a #{}
                                                       :b #{:a}
                                                       :c #{:b :d :a}
                                                       :d #{:b :a}
                                                       :e #{:c :b :a}}))

API reference

API reference documentation is hosted by cljdoc.

Maintainer

Nate Smith

License

Copyright © 2019 Nathaniel Smith

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.