Skip to content

Commit

Permalink
Basic Symbolics tests -- pass!
Browse files Browse the repository at this point in the history
  • Loading branch information
LebedevRI committed May 15, 2023
1 parent 0453339 commit e0b0814
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

[targets]
test = ["Aqua", "QuadGK", "SpecialFunctions", "Statistics", "Test", "Unitful"]
test = ["Aqua", "QuadGK", "SpecialFunctions", "Statistics", "Symbolics", "Test", "Unitful"]
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1051,3 +1051,7 @@ end
# JuliaLang/julia#30944
@test range(0±0, step=1±.1, length=10) isa StepRangeLen
end

@testset "Symbolics" begin
include("symbolics.jl")
end
37 changes: 37 additions & 0 deletions test/symbolics.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Symbolics

isapprox(x::Symbolics.Num, y::Symbolics.Num; rest...) = isequal(x, y)

@testset "measurement" begin
@variables x, x_err

@test typeof(@inferred(measurement(x))) == Measurement{Num}
@test typeof(@inferred(measurement(x, 0))) == Measurement{Num}
@test typeof(@inferred(measurement(x, 1))) == Measurement{Num}
@test typeof(@inferred(measurement(x, 0.0))) == Measurement{Num}
@test typeof(@inferred(measurement(x, 1.0))) == Measurement{Num}
@test typeof(@inferred(measurement(x, big(0)))) == Measurement{Num}
@test typeof(@inferred(measurement(x, big(1)))) == Measurement{Num}
@test typeof(@inferred(measurement(x, x_err))) == Measurement{Num}
@test typeof(@inferred(measurement(0, x_err))) == Measurement{Num}
@test typeof(@inferred(measurement(0.0, x_err))) == Measurement{Num}
@test typeof(@inferred(measurement(big(0), x_err))) == Measurement{Num}

@test iszero(@inferred(measurement(x)).err)
@test @inferred(measurement(x)).tag === UInt64(0)
@test length(@inferred(measurement(x)).der) == 0
@test !(@inferred(measurement(x, x_err)).tag === UInt64(0))
@test length(@inferred(measurement(x, 0)).der) == 0
@test length(@inferred(measurement(x, x_err)).der) == 1
end

##### Mathematical Operations
@testset "Addition" begin
@variables x_val, x_err, y_val, y_err

x = measurement(x_val, x_err)
y = measurement(y_val, y_err)

# abs2(v) === abs(x)^2, but maybe faster.
@test @inferred(x + y) measurement(x_val + y_val, sqrt(abs2(x_err) + abs2(y_err)))
end

0 comments on commit e0b0814

Please sign in to comment.