Skip to content

Commit 84c23c5

Browse files
committed
push test coverage
1 parent ccb9c97 commit 84c23c5

File tree

4 files changed

+34
-18
lines changed

4 files changed

+34
-18
lines changed

src/arithematics.jl

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -357,25 +357,17 @@ end
357357

358358
# AbstractTree APIs
359359
function children(t::TreeConfigEnumerator)
360-
if isdefined(t, :left)
361-
if isdefined(t, :right)
362-
return [t.left, t.right]
363-
else
364-
return [t.left]
365-
end
360+
if t.tag == ZERO || t.tag == LEAF
361+
return typeof(t)[]
366362
else
367-
if isdefined(t, :right)
368-
return [t.right]
369-
else
370-
return typeof(t)[]
371-
end
363+
return [t.left, t.right]
372364
end
373365
end
374366
function printnode(io::IO, t::TreeConfigEnumerator)
375367
if t.tag === LEAF
376368
print(io, t.data)
377369
elseif t.tag === ZERO
378-
print(io, "")
370+
print(io, "")
379371
elseif t.tag === SUM
380372
print(io, "+")
381373
else # PROD
@@ -448,11 +440,11 @@ Base.zero(::TreeConfigEnumerator{N,S,C}) where {N,S,C} = zero(TreeConfigEnumerat
448440
Base.one(::TreeConfigEnumerator{N,S,C}) where {N,S,C} = one(TreeConfigEnumerator{N,S,C})
449441
# todo, check siblings too?
450442
function Base.iszero(t::TreeConfigEnumerator)
451-
if t.TAG == SUM
443+
if t.tag == SUM
452444
iszero(t.left) && iszero(t.right)
453-
elseif t.TAG == ZERO
445+
elseif t.tag == ZERO
454446
true
455-
elseif t.TAG == LEAF
447+
elseif t.tag == LEAF
456448
false
457449
else
458450
iszero(t.left) || iszero(t.right)
@@ -497,11 +489,11 @@ onehotv(::Type{ConfigSampler{N,S,C}}, i::Integer, v) where {N,S,C} = ConfigSampl
497489
Base.transpose(c::ConfigEnumerator) = c
498490
Base.copy(c::ConfigEnumerator) = ConfigEnumerator(copy(c.data))
499491
Base.transpose(c::TreeConfigEnumerator) = c
500-
function Base.copy(c::TreeConfigEnumerator)
492+
function Base.copy(c::TreeConfigEnumerator{N,S,C}) where {N,S,C}
501493
if c.tag == LEAF
502494
TreeConfigEnumerator(c.data)
503495
elseif c.tag == ZERO
504-
TreeConfigEnumerator(c.tag)
496+
TreeConfigEnumerator{N,S,C}(c.tag)
505497
else
506498
TreeConfigEnumerator(c.tag, c.left, c.right)
507499
end

src/interfaces.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@ end
271271

272272
# raise an error if the property for problem can not be computed
273273
_solvable(::Any, ::Any) = true
274-
_solvable(::Coloring, ::GraphPolynomial) = false
275274

276275
# negate the exponents before entering the solver
277276
pre_invert_exponent(t::TruncatedPoly{K}) where K = TruncatedPoly(t.coeffs, -t.maxorder)

test/arithematics.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ end
7575
@test length(a + a) == 2
7676
@test length(a * a) == 1
7777
print((a+a) * a)
78+
b = a + a
79+
@test GraphTensorNetworks.num_nodes(b * b) == 3
7880

7981
a = ConfigSampler(StaticBitVector(rand(Bool, 10)))
8082
@test 1 * a == a
@@ -95,4 +97,20 @@ end
9597
x = ConfigSampler(bv"00111")
9698
@test x ^ 0 == one(x)
9799
@test x ^ 2.0 == x
100+
end
101+
102+
@testset "push coverage" begin
103+
@test abs(Mod{5}(2)) == Mod{5}(2)
104+
@test one(ConfigSampler(bv"11100")) == ConfigSampler(bv"00000")
105+
@test one(TreeConfigEnumerator{5,1,1}(GraphTensorNetworks.ZERO)) == TreeConfigEnumerator(bv"00000")
106+
@test iszero(copy(TreeConfigEnumerator{5,1,1}(GraphTensorNetworks.ZERO)))
107+
x = TreeConfigEnumerator(bv"00111")
108+
@test copy(x) == x
109+
@test copy(x) !== x
110+
@test !iszero(x)
111+
y = x + x
112+
@test copy(y) == y
113+
@test copy(y) !== y
114+
@test !iszero(y)
115+
println((x * x) * zero(x))
98116
end

test/graphs.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,11 @@ using GraphTensorNetworks, Test, Graphs
88
g = unit_disk_graph([(0.1, 0.2), (0.2, 0.3), (1.2, 1.4)], 1.0)
99
@test ne(g) == 1
1010
@test nv(g) == 3
11+
end
12+
13+
@testset "line graph" begin
14+
g = smallgraph(:petersen)
15+
lg = line_graph(g)
16+
@test nv(lg) == 15
17+
@test ne(lg) == 45
1118
end

0 commit comments

Comments
 (0)