Skip to content

Commit

Permalink
test symstruct
Browse files Browse the repository at this point in the history
  • Loading branch information
baggepinnen committed Feb 19, 2024
1 parent fde6b1f commit 9d8d577
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions test/struct.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Test, Symbolics
using Symbolics: StructElement, Struct, operation, arguments, symstruct
using Symbolics: StructElement, Struct, operation, arguments, symstruct, juliatype

handledtypes = [Int8,
Int16,
Expand All @@ -23,17 +23,19 @@ struct Fisk
end
a = StructElement(Int8, :a)
b = StructElement(Int, :b)
for s in [Struct(Fisk, [a, b]), symstruct(Fisk)]
sa = s.a
sb = s.b
@test operation(sa) === getfield
@test arguments(sa) == Any[s, 1]
@test arguments(sa) isa Any
@test operation(sb) === getfield
@test arguments(sb) == Any[s, 2]
@test arguments(sb) isa Any
@test juliatype(s) == Fisk
end

s = Struct(Fisk, [a, b])
sa = s.a
sb = s.b
@test operation(sa) === getfield
@test arguments(sa) == Any[s, 1]
@test arguments(sa) isa Any
@test operation(sb) === getfield
@test arguments(sb) == Any[s, 2]
@test arguments(sb) isa Any
@test juliatype(s) == Fisk
@test symstruct(Fisk) == s

sa1 = (setproperty!(s, :a, UInt8(1)))
@test operation(sa1) === setfield!
Expand All @@ -52,4 +54,4 @@ end

ss = symstruct(Jörgen)

@test getfield(ss, :v) == [StructElement(Int, :a), StructElement(Float64, :b)]
@test getfield(ss, :v) == [StructElement(Int, :a), StructElement(Float64, :b)]

0 comments on commit 9d8d577

Please sign in to comment.