Add graph:make-from-vertices

* src/graph.xsl (graph:make-from-vertices): Added
* test/graph-test.xsl (foo:graph-with-dupes): Added duplicate edges
* test/graph.xspec: Added tests
master
Mike Gerwitz 2016-07-05 16:14:57 -04:00
parent 641147cd8f
commit e5da6f8ce1
3 changed files with 61 additions and 1 deletions

View File

@ -29,6 +29,7 @@
<import href="../hoxsl/src/apply.xsl" />
<!--
@node Dependency Graph
@section Dependency Graph
@ -51,6 +52,29 @@
use the node QNames for type checks.}
-->
<!--
Create a graph from the given vertex set @var{$vertices}.
The resulting graph will be normalized with duplicate vertices and
edges removed,
making it suitable for ad hoc graph generation.@c
@footnote{This is done by calling @ref{graph:union}.}
-->
<function name="graph:make-from-vertices"
as="element( preproc:sym-deps )">
<param name="vertices" as="element( preproc:sym-dep )*" />
<variable name="graph" as="element( preproc:sym-deps )">
<preproc:sym-deps>
<sequence select="$vertices" />
</preproc:sym-deps>
</variable>
<!-- dedupe/normalize -->
<sequence select="graph:union( $graph )" />
</function>
<!--
Produce a new graph that is the transpose of
@var{$graph}@mdash{}that is,

View File

@ -146,9 +146,9 @@
<variable name="foo:graph-vtwo-vthree" as="element( preproc:sym-deps )">
<preproc:sym-deps>
<preproc:sym-dep name="a">
<preproc:sym-ref name="a" attr1="foo" />
<preproc:sym-ref name="b" attr1="foo" attr2="bar" />
<preproc:sym-ref name="c" />
<preproc:sym-ref name="a" attr1="foo" />
</preproc:sym-dep>
<preproc:sym-dep name="b">

View File

@ -29,6 +29,42 @@
stylesheet="graph-test.xsl">
<scenario label="graph:make-from-vertices">
<scenario label="with no vertices">
<call function="graph:make-from-vertices">
<param name="vertices"
select="()" />
</call>
<expect label="produces an empty graph">
<preproc:sym-deps />
</expect>
</scenario>
<scenario label="with vertices">
<call function="graph:make-from-vertices">
<param name="vertices"
select="$foo:graph-vtwo/preproc:sym-dep" />
</call>
<expect label="produces a graph containing those vertices"
select="$foo:graph-vtwo" />
</scenario>
<scenario label="with duplicate vertices">
<call function="graph:make-from-vertices">
<param name="vertices"
select="$foo:graph-with-dupes/preproc:sym-dep" />
</call>
<expect label="removes duplicate vertices and edges"
select="$foo:graph-deduped" />
</scenario>
</scenario>
<scenario label="graph:reverse on a disconnected DAG">
<call function="graph:reverse">
<param name="graph"