From d82a11e45f3f67d7963abee318296c965d062e29 Mon Sep 17 00:00:00 2001 From: Owen Lynch Date: Fri, 13 Oct 2023 16:55:01 -0700 Subject: [PATCH] add test for GATContext -> Schema --- src/categorical_algebra/ACSetsGATsInterop.jl | 16 +++++++++------- test/categorical_algebra/ACSetsGATsInterop.jl | 11 +++++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/categorical_algebra/ACSetsGATsInterop.jl b/src/categorical_algebra/ACSetsGATsInterop.jl index 930c34b09..9f739b977 100644 --- a/src/categorical_algebra/ACSetsGATsInterop.jl +++ b/src/categorical_algebra/ACSetsGATsInterop.jl @@ -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) diff --git a/test/categorical_algebra/ACSetsGATsInterop.jl b/test/categorical_algebra/ACSetsGATsInterop.jl index a244be880..6028b00a2 100644 --- a/test/categorical_algebra/ACSetsGATsInterop.jl +++ b/test/categorical_algebra/ACSetsGATsInterop.jl @@ -1,6 +1,7 @@ module TestACSetsGATsInterop using Test +using GATlab using Catlab.CategoricalAlgebra using Catlab.Graphs: SchGraph, SchWeightedGraph @@ -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 #------------------- @@ -44,4 +54,5 @@ for schema in [SchGraph, SchWeightedGraph] @test roundtrip_json_acset_schema(schema) == schema end + end