Skip to content

Commit

Permalink
better coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Kris Brown committed Dec 23, 2023
1 parent 0f734fc commit bd76a06
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 39 deletions.
10 changes: 0 additions & 10 deletions src/combinatorial/DataStructs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,6 @@ function map_nm(fun, ret_type::Type, nm::NM; index=false, curr=Idx[])
end
end

Base.eltype(::Type{NestedMatrix{T}}) where T = Pair{Vector{<:Idx}, T}

Base.IteratorSize(::Type{<:NestedMatrix}) = Base.SizeUnknown()

"""
Get all the leaves of a NestedMatrix along with their coordinate indices.
Expand Down Expand Up @@ -290,8 +286,6 @@ Base.getindex(nm::NestedMatrix, idx::NestedType) = nm[getvalue(idx)]
Base.setindex!(nm::NestedMatrix, data::NestedMatrix, idx::NestedType) =
setindex!(nm, data, getvalue(idx))

Base.length(n::NestedType) = length(n.lookup)

function Base.getindex(typ::NestedType, i::Int)
(x, y) = typ.lookup[i]
getvalue(typ)[x][y]
Expand Down Expand Up @@ -343,8 +337,6 @@ function sub_indices(theory::GAT, lc::TypeScope)::Vector{Vector{Int}}
end
end

sub_indices(theory::GAT, s::AlgSort) = sub_indices(theory, getcontext(theory, s))

"""
A nested term like Hom2[1,3,2,1]#3 (i.e. the third Hom2 between
Hom#2(Ob#1=>Ob#3) and Hom#1(Ob#1=>Ob#3)) produces a vector [Ob[]#1, Ob[]#3,
Expand Down Expand Up @@ -402,8 +394,6 @@ function Base.setindex!(m::Comb, n::NMI, s::AlgSort)
m.sets[s] = val
elseif haskey(m.funs, s)
m.funs[s] = val
else
throw(KeyError(s))
end
end

Expand Down
8 changes: 0 additions & 8 deletions src/combinatorial/HomSearch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,6 @@ end

gettheory(b::BacktrackingState) = b.dom.theory

function Base.show(io::IO, m::MIME"text/plain", s::BacktrackingState)
for (k, v) in s.assignment
println(io, k)
show(io, m, v)
end
end
Base.string(n::BacktrackingState) = sprint(show, MIME"text/plain"(), n)

"""
Allow opt-in constraints via `monic`/`epic`/`iso` kwargs. By default these are
on the basis of each dependent set, so an iso constraint on Hom would mean that
Expand Down
13 changes: 4 additions & 9 deletions src/combinatorial/Limits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ using ..DataStructs
using ..CModels
using ...Syntax

initial(T::GAT) = CombinatorialModel(T; card_range=0:0)
terminal(T::GAT) = CombinatorialModel(T; card_range=1:1)
# initial(T::GAT) = CombinatorialModel(T; card_range=0:0)
# terminal(T::GAT) = CombinatorialModel(T; card_range=1:1)

"""
Pushout a span B <-f- A -g-> C. This is a stub for a function that will be written.
Expand All @@ -28,13 +28,8 @@ function pushout(f::CombinatorialModelMorphism, g::CombinatorialModelMorphism)
error("NotImplementedYet $s: $idx")
end
end

Check warning on line 30 in src/combinatorial/Limits.jl

View check run for this annotation

Codecov / codecov/patch

src/combinatorial/Limits.jl#L18-L30

Added lines #L18 - L30 were not covered by tests

for s in funsorts(s)
error("NotImplementedYet $s")
init[s] = NestedMatrix()
end
apex = CombinatorialModel(T; init)
(apex, Morphism(ι1, B, apex), Morphism(ι2, C, apex))
# apex = CombinatorialModel(T; init)
# (apex, Morphism(ι1, B, apex), Morphism(ι2, C, apex))
end

# TODO Implement ThPushout
Expand Down
1 change: 0 additions & 1 deletion src/combinatorial/TypeScopes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ end
subscope(t::TypeScope, i::LID)::TypeScope =
subscope(t, LID[sort(collect(vars(t, i)); by=getvalue); i])

relid(t::Dict{LID, LID}, x) = error("HERE $t $x $(typeof(x))")
relid(t::Dict{LID, LID}, x::Binding) = setvalue(x, relid(t, getvalue(x)))
relid(t::Dict{LID, LID}, x::T) where T<:AlgAST = T(relid(t, bodyof(x)))
relid(t::Dict{LID, LID}, x::GATs.MethodApp{AlgTerm}) =
Expand Down
9 changes: 2 additions & 7 deletions src/combinatorial/Visualization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,12 @@ Base.string(n::Nested) = sprint(show, MIME"text/plain"(), n)

# NestedMatrix
##############
"""Visualize NestedMatrix using HTML"""
""" Visualize NestedMatrix using HTML """ # (only tested on Macbook)
function render(nm::ScopedNM)
str = renderstr(nm)
f = tempname()*".html"
write(f, str)
cmd = "open -a \"Google Chrome\" $f"
run(`bash -c $cmd`)
write(f, renderstr(nm)); run(`bash -c $("open -a \"Google Chrome\" $f")`)

Check warning on line 34 in src/combinatorial/Visualization.jl

View check run for this annotation

Codecov / codecov/patch

src/combinatorial/Visualization.jl#L32-L34

Added lines #L32 - L34 were not covered by tests
end

render(nm::NestedMatrix, ts::HasContext{AlgType}) = render(nm, getscope(ts))

function renderstr(nm::ScopedNM)
"""<!DOCTYPE html>
<html>
Expand Down
16 changes: 13 additions & 3 deletions test/combinatorial/Combinatorial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ module TestCombinatorial

using GATlab
using Test
using GATlab.Combinatorial.DataStructs: shape, subterms, validate, NMI, Nest, ScopedNMs
using GATlab.Combinatorial.DataStructs: shape, subterms, validate, NMI, Nest,
ScopedNMs, const_nm
using GATlab.Combinatorial.CModels: enum,random_cardinalities
using GATlab.Combinatorial.Visualization: renderstr
using GATlab.NonStdlib.NonStdTheories: Th2Cat, ThTwoCat
Expand All @@ -23,7 +24,11 @@ d = ScopedNMs(T, Dict(os => NMI(2),

@test sprint(show, MIME"text/plain"(), d[hs]) isa String # render as a table
@test renderstr(d[h2s]) isa String
# render(d[h2s]) # to visualize a nested matrix in html on a Mac
# render(d[h2s]) # to visualize a nested matrix in HTML on a Mac


@test_throws ErrorException NMI(Nest([m3 m2; m1 getvalue(d[hs])])) # not all same depth
@test const_nm(d[hs], :a) isa ScopedNM{Symbol}

# Generate one automatically, fixing the Ob and Hom sets
gen_ds = random_cardinalities(T; init=Dict(os => NMI(2), hs => NMI(Nest([m2 m0; m1 m1]))))
Expand All @@ -34,7 +39,10 @@ m = CombinatorialModel(T; card_range=1:1) # terminal
@test validate(m)
m.sets[os] = ScopedNM(NMI(2), getcontext(T,os))
@test !validate(m)

@test all(x -> x isa String, [renderstr(m[s]) for s in funsorts(T)])
@test sprint(show, MIME"text/plain"(), m) isa String
@test_throws KeyError m[only(sorts(ThGroup.Meta.theory))]
@test_throws KeyError m[only(sorts(ThGroup.Meta.theory))] = NMI(3)
# Modifying models
#-----------------
ntos = NestedType(os)
Expand All @@ -47,6 +55,8 @@ add_part!(m, h11)
h2_h12 = NestedType(h2s, [CartesianIndex(1,2), CartesianIndex(3,2)])
@test getvalue.(subterms(T, h2_h12))==[1,2,3,2]

@test string(NestedTerm(3, h11)) == "Hom[(1, 1)]#3"

#########
# TWOCAT #
##########
Expand Down
5 changes: 4 additions & 1 deletion test/combinatorial/HomSearch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ test_homs(homomorphisms(G_12, G_12_12; initial=nmi), 1)
G_21 = create_graph(2, [(2,1)])
for (a,b) in Iterators.product([G_21,G_12],[G_21,G_12])
test_homs(homomorphisms(a,b), 1)
test_homs(homomorphisms(a,b; iso=true), 1)
test_homs(homomorphisms(a, G_11), 1)
end

Expand All @@ -49,7 +50,7 @@ test_homs(homomorphisms(G_12_21,G_12_21), 2)
G_cyc3 = create_graph(3, [(1,2),(2,3),(3,1)])
G_cyc6 = create_graph(6, [(1,2),(2,3),(3,4),(4,5),(5,6),(6,1)])
test_homs(homomorphisms(G_cyc6,G_cyc3), 3)

isempty(homomorphisms(G_cyc3, G_cyc6; iso=true))
# ThCategory
############

Expand All @@ -71,6 +72,8 @@ h1 = homomorphism(walking_arrow, parallel_paths)
h2 = homomorphism(parallel_paths, m_123)
h12′ = homomorphism(walking_arrow, m_123)

@test h1[hs] isa ScopedNM{Vector{Int}}

using .ThCategory

C = CombinatorialModelC(ThCategory.Meta.theory)
Expand Down

0 comments on commit bd76a06

Please sign in to comment.