Skip to content

Commit

Permalink
add test for GATContext -> Schema
Browse files Browse the repository at this point in the history
  • Loading branch information
olynch committed Oct 13, 2023
1 parent f464919 commit d82a11e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/categorical_algebra/ACSetsGATsInterop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ end
function Schema(c::GATContext)
obs, attrtypes = Symbol[], Symbol[]
homs, attrs = Tuple{Symbol, Symbol, Symbol}[], Tuple{Symbol, Symbol, Symbol}[]
for binding in p.scope
type = getvalue(binding)
@match (nameof(type.body.head), type.body.args...) begin
(:Ob,) => push!(obs, nameof(binding))
(:Hom, x, y) => push!(homs, nameof.((binding, x.body, y.body)))
(:AttrType,) => push!(attrtypes, nameof(binding))
(:Attr, x, y) => push!(attrs, nameof.((binding, x.body, y.body)))
for scope in allscopes(gettypecontext(c))
for binding in scope
type = getvalue(binding)
@match (nameof(type.body.head), type.body.args...) begin
(:Ob,) => push!(obs, nameof(binding))
(:Hom, x, y) => push!(homs, nameof.((binding, x.body, y.body)))
(:AttrType,) => push!(attrtypes, nameof(binding))
(:Attr, x, y) => push!(attrs, nameof.((binding, x.body, y.body)))
end
end
end
BasicSchema(obs,homs,attrtypes,attrs)
Expand Down
11 changes: 11 additions & 0 deletions test/categorical_algebra/ACSetsGATsInterop.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module TestACSetsGATsInterop
using Test

using GATlab
using Catlab.CategoricalAlgebra
using Catlab.Graphs: SchGraph, SchWeightedGraph

Expand Down Expand Up @@ -29,6 +30,15 @@ X, parent, height = SchDendrogram[[:X, :parent, :height]]
@test subpart(d, id(X)) == 1:5
@test subpart(d, compose(parent, height)) == [10,10,10,20,20]

@gatcontext SchDendrogram′(ThSchema) begin
X::Ob
R::AttrType
parent::Hom(X,X)
height::Attr(X,R)
end

@test Schema(SchDendrogram′) == Schema(SchDendrogram)

# JSON serialization
#-------------------

Expand All @@ -44,4 +54,5 @@ for schema in [SchGraph, SchWeightedGraph]
@test roundtrip_json_acset_schema(schema) == schema
end


end

0 comments on commit d82a11e

Please sign in to comment.