diff --git a/Project.toml b/Project.toml index 4ee9e89f..62184636 100644 --- a/Project.toml +++ b/Project.toml @@ -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"] diff --git a/test/runtests.jl b/test/runtests.jl index 64973333..811c3e8c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 diff --git a/test/symbolics.jl b/test/symbolics.jl new file mode 100644 index 00000000..61b23ba3 --- /dev/null +++ b/test/symbolics.jl @@ -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