Skip to content

Commit

Permalink
Many more tests
Browse files Browse the repository at this point in the history
These tests attempt to cover all of the basic functionality of ThDEC. It also points out some strange or desired behavior.
  • Loading branch information
GeorgeR227 committed Oct 4, 2024
1 parent 85572a4 commit df41b18
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 26 deletions.
4 changes: 3 additions & 1 deletion src/deca/ThDEC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ function Base.nameof(f::Form; with_dim_parameter=false)
end

# show methods
# TODO: Remove me? Not being used anywhere
show_duality::Form) = isdual(ω) ? "dual" : "primal"

Check warning on line 272 in src/deca/ThDEC.jl

View check run for this annotation

Codecov / codecov/patch

src/deca/ThDEC.jl#L272

Added line #L272 was not covered by tests

function Base.show(io::IO, ω::Form)
Expand All @@ -286,7 +287,7 @@ const SUBSCRIPT_DIGIT_0 = '₀'

as_sub(n::Int) = join(map(d -> SUBSCRIPT_DIGIT_0 + d, digits(n)))


# TODO: Do we want both nameof's for wedges? This one belows expects different args
function Base.nameof(::typeof(), s1::B1, s2::B2) where {S1,S2,B1<:BasicSymbolic{S1}, B2<:BasicSymbolic{S2}}
Symbol("$(sub_dim(symtype(s1)))$(sub_dim(symtype(s2)))")

Check warning on line 292 in src/deca/ThDEC.jl

View check run for this annotation

Codecov / codecov/patch

src/deca/ThDEC.jl#L291-L292

Added lines #L291 - L292 were not covered by tests
end
Expand All @@ -297,6 +298,7 @@ end

Base.nameof(::typeof(∂ₜ), s) = Symbol("∂ₜ($(nameof(s)))")

#TODO: Add an option to output d for dual forms, typically d₀ -> dual_d₀
Base.nameof(::typeof(d), s) = Symbol("d$(sub_dim(s))")

# Base.nameof(::typeof(Δ), s) = Symbol("Δ$(sub_dim(s))")
Expand Down
121 changes: 96 additions & 25 deletions test/decasymbolic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ h, = @syms h::PrimalForm{2, :X, 2}
u2, = @syms u2::PrimalForm{0, :Y, 2}
u3, = @syms u3::PrimalForm{0, :X, 3}

@testset "Term Construction" begin
@testset "Symtypes" begin

@test symtype(ϐ) == InferredType
@test symtype(ℓ) == Literal
Expand All @@ -47,32 +47,73 @@ u3, = @syms u3::PrimalForm{0, :X, 3}

# @test_throws ThDEC.SortError ThDEC.♯(u)
@test symtype(Δ(u) + Δ(u)) == PrimalForm{0, :X, 2}
end

# test unary operator conversion to decaexpr
@test Term(1) == Lit(Symbol("1"))
@test Term(a) == Var(:a)
@test Term(c) == Var(:c)
@test Term(t) == Var(:t)
@test Term(∂ₜ(u)) == Tan(Var(:u))
@test_broken Term(∂ₜ(u)) == Term(DerivOp(u))

@test Term((ω)) == App1(:★₁, Var())
@test Term((η)) == App1(:★₀⁻¹, Var())

# test binary operator conversion to decaexpr
@test Term(a + b) == Plus(Term[Var(:a), Var(:b)])
# TODO: Currently parses as addition
@test_broken Term(a - b) == App2(:-, Var(:a), Var(:b))
@test Term(a * b) == Mult(Term[Var(:a), Var(:b)])
@test Term du) == App2(:₁₁, Var(), Var(:du))

@test Term+ du + d(u)) == Plus(Term[App1(:d₀, Var(:u)), Var(:du), Var()])

let
@syms f(x, y, z)
@test_throws "was unable to convert" Term(f(a, b, u))
end
@testset "Type Information" begin

@test dim(symtype(η)) == 2

@test isdual(symtype(η))
@test !isdual(symtype(u))

@test space(symtype(η)) == :X
@test spacedim(symtype(η)) == 2

@test isForm0(u)
@test !isForm0(du)
@test !isForm0(a)

@test isForm1(ω)
@test !isForm1(u)
@test !isForm1(a)

@test isForm2(η)
@test !isForm2(u)
@test !isForm2(a)

@test isDualForm(η)
@test !isDualForm(u)
@test !isDualForm(a)
end

@testset "Nameof" begin
@test nameof(symtype(c)) == :Constant
@test nameof(symtype(t)) == :Parameter
@test nameof(symtype(a)) == :Scalar
@test nameof(symtype(ℓ)) == :Literal

@test nameof(symtype(u)) == :Form0
@test nameof(symtype(ω)) == :Form1
@test nameof(symtype(η)) == :DualForm2

# TODO: Do we want this style of typed subtraction?
@test nameof(-, symtype(u), symtype(u)) == Symbol("₀-₀")
# TODO: This breaks since this expects the types to have a `dim` function
@test_broken nameof(-, symtype(a), symtype(b)) == Symbol("-")

@test nameof(, symtype(u), symtype(u)) == Symbol("∧₀₀")
@test nameof(, symtype(u), symtype(ω)) == Symbol("∧₀₁")
@test nameof(, symtype(ω), symtype(u)) == Symbol("∧₁₀")

# TODO: Do we need a special designation for wedges with duals in them?
@test nameof(, symtype(ω), symtype(η)) == Symbol("∧₁₂")

# TODO: Why is this being named as such?
@test nameof(∂ₜ, symtype(u)) == Symbol("∂ₜ(Form0)")
@test nameof(∂ₜ, symtype(d(u))) == Symbol("∂ₜ(Form1)")

@test nameof(d, symtype(u)) == Symbol("d₀")
@test_broken nameof(d, symtype(η)) == Symbol("dual_d₂")

@test_broken nameof(Δ, symtype(u)) == Symbol("Δ₀")
@test_broken nameof(Δ, symtype(ω)) == Symbol("Δ₁")

@test nameof(★, symtype(u)) == Symbol("★₀")
@test nameof(★, symtype(ω)) == Symbol("★₁")
@test nameof(★, symtype(η)) == Symbol("★₀⁻¹")
end

@testset "Symtype Promotion" begin
# test promoting types
@test promote_symtype(d, u) == PrimalForm{1, :X, 2}
@test promote_symtype(+, a, b) == Scalar
Expand All @@ -83,9 +124,39 @@ u3, = @syms u3::PrimalForm{0, :X, 3}

# test composition
@test promote_symtype(d d, u) == PrimalForm{2, :X, 2}
end

@testset "Term Construction" begin

# test unary operator conversion to decaexpr
@test Term(1) == Lit(Symbol("1"))
@test Term(a) == Var(:a)
@test Term(c) == Var(:c)
@test Term(t) == Var(:t)
@test Term(∂ₜ(u)) == Tan(Var(:u))
@test_broken Term(∂ₜ(u)) == Term(DerivOp(u))

@test Term((ω)) == App1(:★₁, Var())
@test Term((η)) == App1(:★₀⁻¹, Var())

# test binary operator conversion to decaexpr
@test Term(a + b) == Plus(Term[Var(:a), Var(:b)])

# TODO: Currently parses as addition
@test_broken Term(a - b) == App2(:-, Var(:a), Var(:b))
@test Term(a * b) == Mult(Term[Var(:a), Var(:b)])
@test Term du) == App2(:₁₁, Var(), Var(:du))

@test Term+ du + d(u)) == Plus(Term[App1(:d₀, Var(:u)), Var(:du), Var()])

let
@syms f(x, y, z)
@test_throws "was unable to convert" Term(f(a, b, u))
end

end


# this is not nabla but "bizarro Δ"
del_expand_0, del_expand_1 = @operator (S)::DECQuantity begin
@match S begin
Expand Down

0 comments on commit df41b18

Please sign in to comment.