Skip to content

Commit

Permalink
additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ranocha committed Mar 6, 2019
1 parent 1811d63 commit c2cb3c9
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 24 deletions.
16 changes: 11 additions & 5 deletions src/RootedTrees.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ one with lexicographically biggest level sequence.
function canonical_representation!(t::RootedTree)
subtr = subtrees(t)
for i in eachindex(subtr)
subtr[i] = canonical_representation(subtr[i])
canonical_representation!(subtr[i])
end
sort!(subtr, rev=true)

Expand Down Expand Up @@ -321,13 +321,16 @@ end
The number of monotonic labellings of `t` not equivalent under the symmetry group.
If `is_canonical`, it is assumed that `t` is given using the canonical
representation.
Reference: Section 302 of
Butcher, John Charles.
Numerical methods for ordinary differential equations.
John Wiley & Sons, 2008.
"""
function α(t::RootedTree)
div(factorial(order(t)), σ(t)*γ(t))
function α(t::RootedTree, is_canonical=false)
div(factorial(order(t)), σ(t, is_canonical)*γ(t))
end


Expand All @@ -336,13 +339,16 @@ end
The total number of labellings of `t` not equivalent under the symmetry group.
If `is_canonical`, it is assumed that `t` is given using the canonical
representation.
Reference: Section 302 of
Butcher, John Charles.
Numerical methods for ordinary differential equations.
John Wiley & Sons, 2008.
"""
function β(t::RootedTree)
div(factorial(order(t)), σ(t))
function β(t::RootedTree, is_canonical=false)
div(factorial(order(t)), σ(t, is_canonical))
end


Expand Down
80 changes: 61 additions & 19 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,83 @@ using Test
using StaticArrays
using RootedTrees

t1 = RootedTree([1,2,3])
t2 = RootedTree([1,2,3])
t3 = RootedTree([1,2,2])
t4 = RootedTree([1,2,3,3])

@test t1 == t1
@test t1 == t2
@test !(t1 == t3)
@test !(t1 == t4)

@test t3 < t2 && t2 > t3
@test !(t2 < t3) && !(t3 > t2)
@test t1 < t4 && t4 > t1
@test !(t4 < t1) && !(t1 > t4)
@test t1 <= t2 && t2 >= t1
@test t2 <= t2 && t2 >= t2
trees_array = (RootedTree([1,2,3]),
RootedTree([1,2,3]),
RootedTree([1,2,2]),
RootedTree([1,2,3,3]))

trees_marray = (RootedTree(@MArray [1,2,3]),
RootedTree(@MArray [1,2,3]),
RootedTree(@MArray [1,2,2]),
RootedTree(@MArray [1,2,3,3]))

for (t1,t2,t3,t4) in (trees_array, trees_marray)
@test t1 == t1
@test t1 == t2
@test !(t1 == t3)
@test !(t1 == t4)

@test t3 < t2 && t2 > t3
@test !(t2 < t3) && !(t3 > t2)
@test t1 < t4 && t4 > t1
@test !(t4 < t1) && !(t1 > t4)
@test t1 <= t2 && t2 >= t1
@test t2 <= t2 && t2 >= t2

println(devnull, t1)
println(devnull, t2)
println(devnull, t3)
println(devnull, t4)
end


t = RootedTree([1])
@test order(t) == 1
@test σ(t) == 1
@test γ(t) == 1
@test α(t) == 1
@test β(t) == α(t)*γ(t)

t = RootedTree([1, 2])
@test order(t) == 2
@test σ(t) == 1
@test γ(t) == 2
@test α(t) == 1
@test β(t) == α(t)*γ(t)

t = RootedTree([1, 2, 2])
@test order(t) == 3
@test σ(t) == 2
@test γ(t) == 3
@test α(t) == 1
@test β(t) == α(t)*γ(t)

t = RootedTree([1, 2, 3])
@test order(t) == 3
@test σ(t) == 1
@test γ(t) == 6
@test α(t) == 1
@test β(t) == α(t)*γ(t)

t = RootedTree([1, 2, 2, 2])
@test order(t) == 4
@test σ(t) == 6
@test γ(t) == 4
@test α(t) == 1
@test β(t) == α(t)*γ(t)

t = RootedTree([1, 2, 2, 3])
@test order(t) == 4
@test σ(t) == 1
@test γ(t) == 8
@test α(t) == 3
@test β(t) == α(t)*γ(t)

t = RootedTree([1, 2, 3, 3])
@test order(t) == 4
@test order(t) == 4
@test σ(t) == 2
@test γ(t) == 12
@test γ(t) == 12
@test β(t) == α(t)*γ(t)

t = RootedTree([1, 2, 3, 4])
@test order(t) == 4
Expand All @@ -71,12 +91,14 @@ t = RootedTree([1, 2, 2, 2, 2])
@test σ(t) == 24
@test γ(t) == 5
@test α(t) == 1
@test β(t) == α(t)*γ(t)

t = RootedTree([1, 2, 2, 2, 3])
@test order(t) == 5
@test σ(t) == 2
@test γ(t) == 10
@test α(t) == 6
@test β(t) == α(t)*γ(t)

t = RootedTree([1, 2, 2, 3, 3])
@test order(t) == 5
Expand All @@ -89,36 +111,42 @@ t = RootedTree([1, 2, 2, 3, 4])
@test σ(t) == 1
@test γ(t) == 30
@test α(t) == 4
@test β(t) == α(t)*γ(t)

t = RootedTree([1, 2, 3, 2, 3])
@test order(t) == 5
@test σ(t) == 2
@test γ(t) == 20
@test α(t) == 3
@test β(t) == α(t)*γ(t)

t = RootedTree([1, 2, 3, 3, 3])
@test order(t) == 5
@test σ(t) == 6
@test γ(t) == 20
@test α(t) == 1
@test β(t) == α(t)*γ(t)

t = RootedTree([1, 2, 3, 3, 4])
@test order(t) == 5
@test σ(t) == 1
@test γ(t) == 40
@test α(t) == 3
@test β(t) == α(t)*γ(t)

t = RootedTree([1, 2, 3, 4, 4])
@test order(t) == 5
@test σ(t) == 2
@test γ(t) == 60
@test α(t) == 1
@test β(t) == α(t)*γ(t)

t = RootedTree([1, 2, 3, 4, 5])
@test order(t) == 5
@test σ(t) == 1
@test γ(t) == 120
@test α(t) == 1
@test β(t) == α(t)*γ(t)

# see butcher2008numerical, Table 302(I)
number_of_rooted_trees = [1, 1, 2, 4, 9, 20, 48, 115, 286, 719]
Expand All @@ -130,7 +158,7 @@ for order in 1:10
@test num == number_of_rooted_trees[order] == count_trees(order)
end

# Runge-Kutta method SSPRK33
# Runge-Kutta method SSPRK33 of order 3
A = [0 0 0; 1 0 0; 1/4 1/4 0]
b = [1/6, 1/6, 2/3]
c = A * fill(1, length(b))
Expand All @@ -139,6 +167,13 @@ for order in 1:3
@test residual_order_condition(t, A, b, c) 0 atol=eps()
end
end
let order=4
res = 0.
for t in RootedTreeIterator(order)
res += abs(residual_order_condition(t, A, b, c, true))
end
@test res > 10*eps()
end

A = @SArray [0 0 0; 1 0 0; 1/4 1/4 0]
b = @SArray [1/6, 1/6, 2/3]
Expand All @@ -148,3 +183,10 @@ for order in 1:3
@test residual_order_condition(t, A, b, c) 0 atol=eps()
end
end
let order=4
res = 0.
for t in RootedTreeIterator(order)
res += abs(residual_order_condition(t, A, b, c, true))
end
@test res > 10*eps()
end

0 comments on commit c2cb3c9

Please sign in to comment.